Skip to content

Rule names can collide with Tatsu internals and raise SemanticError #141

@EGrunzke

Description

@EGrunzke

Summary

The generated ModelBuilderSemantics class raises a tatsu.exceptions.SemanticError: Could not call constructor for Sequence: 'closure' object is not callable

Context

Some cases work:

  • tatsu.compile(grammar).parse("(test)")
  • BugParser().parse("(test)")

But BugParser().parse("(test)", semantics=BugModelBuilderSemantics()) fails

The grammar

# bug.peg
@@grammar :: Bug

start = sequence $ ;

sequence::Sequence = children:{term [',']}+ ;

term = parens | word ;

parens = '(' ~ @:sequence ')' ;

word::Word = val:/\w+/ ;

Reproduction

Reproduction

  1. Generate the parser and model:
    python -m tatsu bug.peg -o bug_parser.py -G bug_model.py

  2. Run

parser = BugParser()
semantics = BugModelBuilderSemantics()
parser.parse("(test)", semantics=semantics)

GitHub repo with full code

Full reproduction code is available:
https://github.com/EGrunzke/tatsu-sematic-error-closure-not-callable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions