Brendan McGloin
Brendan McGloin

Reputation: 1

Tatsu grammar parser and codegen producing two very different results

I'm working with TatSu, and the results I get from the codegen parser is very different from the one I get from when the parser is build directly. Consider the fairly simple grammar for dice notation:

start = expression $;

int = /-?\d+/ ;

dice = number_of_dice:factor /d|D/ sides:factor;

expression = addition ;

addition
    =
    | left:addition op:('+' | '-') ~ right:addition
    | dice_expr
    ;

dice_expr
    =
    | dice
    | factor
    ;

factor
    =
    | '(' ~ @:expression ')'
    | int
    ;

Then if I feed 1d3 to the parser generated via tatsu.compile I get the result I'd expect:

{'number_of_dice': '1', 'sides': '3'}

However, when I use the parser generated vita the TatSu command line tool, I get:

{'left': None, 'op': None, 'right': None}

I've tried separating out the rules, combining the rules, etc. The only way I can get it to work is by breaking statements like (1+2)d3 break. Is there something I'm missing?

Upvotes: 0

Views: 113

Answers (1)

Apalala
Apalala

Reputation: 9244

This issue is solved in the latest version of TatSu: https://pypi.org/project/tatsu/

Upvotes: 1

Related Questions