lark: Generate parser for ignored tokens

Is there an easy and failure-proof way to generate a parser (in fact, a lexer) from the ignored tokens of a ‘.lark’ declaration? Let us say we have a grammar.lark file with the following contents:

...
%import .x (A, B, C)
%ignore A
%ignore B
%ignore C

Is there a way to get a parser for the grammar start: (A|B|C)+ without having to write such a grammar explicitly?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (12 by maintainers)

Most upvoted comments

>>> p = Lark(...)
>>> r'start: (%s)+' % '|'.join(p.ignore_tokens)
'start: (A|B|C)+'