lark: GrammarError: Collision when using `lalr`

I have a language using the following grammar:

    action          : STRING ACTION_OPERATOR (ESCAPED_STRING | STRING)
    attr            : (action | MACRO | conditional)
    attrs           : (attr ";")*  attr ";"?  // Colon is only used as separator, and thus optional for final attr
    operator        : OPERATOR
    conditional     : STRING "?" STRING ":"
    
    expr            : MACRO OPERATOR attrs
    line            : expr COMMENT?
    file            : line+
    
    comment         : COMMENT

    MACRO           : STRING
    COMMENT         : /#.*$/m
    
    STRING          : /[a-zA-Z0-9_.-]+/
    
    OPERATOR        : ":" | "+:"
    ACTION_OPERATOR : "===" | "==" | "+=" | "-=" | "="
    
    %import common.WS
    %import common.NEWLINE
    %import common.ESCAPED_STRING
    %ignore WS
    %ignore COMMENT
    %ignore NEWLINE

Parsing my files works fine with earley, however, it is quite slow: 18 seconds versus 1.5 seconds for my implementation in pyparsing, although the latter may still be incomplete. Parsing with lalr gives

GrammarError: Collision in MACRO: [('reduce', <attrs : attr __SEMICOLON>), ('reduce', <__anon_star_0 : attr __SEMICOLON>)]

Could you explain what the reason is for this?


Possibly related issue #10

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 22 (11 by maintainers)

Most upvoted comments

I indeed forgot to denote it as a raw string. The earley parser is slightly faster now. Hopefully I find more time to work on the lalr solution. Thanks for your help!