inveniosoftware-attic / jsonalchemy

JSONAlchemy
GNU General Public License v2.0
0 stars 10 forks source link

parser: improper Syntax Error for 3 @connect decorators #7

Open MSusik opened 9 years ago

MSusik commented 9 years ago

When trying to use 3 @connect operators, I receive Syntax Error. For example, given this field configuration:

author_note:
    """Contains public note."""
    derived:
        @parse_first('_public_note', '_private_note', '_curators_note')
        @connect('_public_note', sync_notes)
        @connect('_private_note', sync_notes)
        @connect('_curators_note', sync_notes)
        @only_if('_public_note' in self or '_private_note' in self
                 or '_curators_note' in self)
        sum_notes(self, '_public_note', '_private_note', '_curators_note')

Note that:

This is the pyparsing grammar definition for derived fields.

der_calc_body = (Optional(field_decorators).setResultsName('decorators') +
                     PYTHON_ALLOWED_EXPR)
    derived = (
        Keyword('derived:').suppress() +
        indentedBlock(der_calc_body, indent_stack)
    ).setParseAction(lambda toks: {
        'source_format': 'derived',
        'source_tags': None,
        'function': compile(toks[-1].strip(), '', 'eval'),
        'type': 'derived',
        'decorators': toks.decorators.asDict()}).setResultsName('derived_def')
    calculated = (
        Keyword('calculated:').suppress() +
        indentedBlock(der_calc_body, indent_stack)
    ).setParseAction(lambda toks: {
        'source_format': 'calculated',
        'source_tags': None,
        'function': compile(toks[-1].strip(), '', 'eval'),
        'type': 'calculated',
        'decorators': toks.decorators.asDict()
    }).setResultsName('calculated_def')

Which looks fine. No idea where does the error come from.

MSusik commented 9 years ago

Continues https://github.com/inveniosoftware/invenio/issues/2705