question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GrammarError: Collision when using `lalr`

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
FRidhcommented, Nov 21, 2017

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!

0reactions
FRidhcommented, Dec 12, 2017

Oh nevermind, just as I posted it I saw the issue:

file: line? (newline line?)*

will solve it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unambiguous gramar for let e1 in e2
I think the problem is start : expr expr : ... | exprcont exprcont : ... | expr. This loop means that your...
Read more >
lark-parser/Lobby - Gitter
I am using lalr @erezsh ... But I have a GrammarError: Collision in Terminal ... @PavelICS It's the right idea, but for LALR...
Read more >
Grammar Reference - Lark documentation - Read the Docs
Grammars in Lark are based on EBNF syntax, with several enhancements. ... When using LALR, the highest priority rules are used to resolve...
Read more >
Symbols instead of strings - gitmirror - Gitea: Git with a cup of tea
from .parser_frontends import LALR. from .parsers.lalr_parser import UnexpectedToken. from .common import is_terminal, GrammarError, LexerConf, ParserConf, ...
Read more >
Deadly collision under investigation on Two Notch Rd, ...
8, a Nissan Armada collided with a pedestrian on Two Notch Rd at the intersection of ... Notice a spelling or grammar error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found