Skip to content

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

@MSusik

Description

@MSusik

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:

  • Changing the order of the decorators doesn't help
  • Changing only_if call to one line doesn't help
  • Removing any of the @connects helps

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions