we-like-parsers / pegen_experiments

Experiments for the official PEG parser generator for Python
https://github.com/python/cpython/tree/master/Tools/peg_generator
Other
273 stars 30 forks source link

Properly aggregate the result of looped nonterminals #255

Closed PeterNerlich closed 3 years ago

PeterNerlich commented 3 years ago

While experimenting and torturing the code from story7 in several ways to try and hack together my own language without properly looking up on the theory, I noticed getting back strange representations for rules like fulltext: WORD fulltext*: A string like a b c d e f would successfully parse, but only yield:

Node(start, [
  Node(expr, [
    Node(term, [
      Node(atom, [
        Node(fulltext, [
          'a',
          [True]
        ])
      ])
    ]),
    []
  ]),
  ''
])

instead of:

Node(start, [
  Node(expr, [
    Node(term, [
      Node(atom, [
        Node(fulltext, [
          'a',
          [
            Node(fulltext, [
              'b',
              [
                Node(fulltext, [
                  'c',

...and so on.

I managed to trace it back to the condition for while in loop() of parser.py (present in story6 and story7), where the walrus operator is not parenthesis, thus first checking whether func(*args) is not None and assigning that boolean to node instead of the other way around.

gvanrossum commented 3 years ago

Hm, not sure what’s up with the tests. I’m merging anyway.