Questions tagged [grako]

Grako (for grammar compiler) is a tool that takes grammars in a variation of EBNF as input, and outputs memoizing (Packrat) PEG parsers in Python.

Grako (for grammar compiler) is a tool that takes grammars in a variation of EBNF as input, and outputs memoizing (Packrat) PEG parsers in Python.

Features:

  • Generated parsers use Python's exception-handling system to backtrack.

  • Positive and negative lookaheads, and the cut element allow for hand-crafted optimizations at the grammar level.

  • Delegation to Python's re module for lexemes allows for Perl-like lexical analysis.

  • Python's context managers reduce the size of the generated parsers.

  • Include files, rule inheritance, and rule inclusion provide expressive power

  • Support for direct and indirect left recursion allows more intuitive grammars.

See also

35 questions
0
votes
2 answers

PEG parsing match at least one preserving order

Given the PEG rule: rule = element1:'abc' element2:'def' element3:'ghi' ; How do I rewrite this such that it matches at least one of the elements but possibly all while enforcing their order? I.e. I would like to match all of the following…
ARF
  • 6,320
  • 5
  • 34
  • 62
0
votes
1 answer

Grako - How to do error handling?

How do I do error handling with Grako? EBNF (MyGrammar.ebnf): pattern = { tag | function }* ; tag = tag:( "%" name:id "%" ); function = function:("$" name:id "()" ); id = ?/([^\\%$,()=])+/? ; I'm generating the parser with python -m…
Sebastian
  • 3
  • 2
0
votes
1 answer

Grako end closure when rule is matched

I have this grammar: name = /[_a-zA-Z][a-zA-Z0-9]*/; expression = name '+' name; def_body = 'def' name:name args:{name} body:expression; But when i try to parse, it always consume first name of expression as an part of arguments. Is there way to…
tino415
  • 97
  • 1
  • 8
0
votes
1 answer

generated code is not indent

I am modifying the oil file using python script. I have written EBNF grammar to convert oil file to AST using Grako. And generate oil file back from AST using codegen but the Oil file is not indent (generate in one line). Sample Oil file: CPU dummy…
0
votes
0 answers

Floats in lists halt the parser with 'no available options' error

Given this grammar: (* integers *) DEC = /([1-9][0-9]*|0+)/; int = /(0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)/ | DEC; (* floats *) pointfloat = /([0-9]*\.[0-9]+|[0-9]+\.)/; expfloat = /([0-9]+\.?|[0-9]*\.)[eE][+-]?[0-9]+/; float = pointfloat |…
Aerdan
  • 43
  • 7
1 2
3