Questions tagged [lark-parser]

Questions about the Lark parser project

Use this tag when asking questions about the Lark parser project (https://github.com/lark-parser/lark)

97 questions
15
votes
1 answer

How do you add folding to QsciLexerCustom subclass?

Consider this snippet: import sys import textwrap import re from PyQt5.Qt import * # noqa from PyQt5.Qsci import QsciScintilla from PyQt5.Qsci import QsciLexerCustom from lark import Lark, inline_args, Transformer class…
BPL
  • 9,632
  • 9
  • 59
  • 117
9
votes
2 answers

How to setup a grammar that can handle ambiguity

I'm trying to create a grammar to parse some Excel-like formulas I have devised, where a special character in the beginning of a string signifies a different source. For example, $ can signify a string, so "$This is text" would be treated as a…
Dima1982
  • 189
  • 3
  • 18
6
votes
1 answer

lark grammar: How does the escaped string regex work?

The lark parser predefines some common terminals, including a string. It is defined as follows: _STRING_INNER: /.*?/ _STRING_ESC_INNER: _STRING_INNER /(?
flowit
  • 1,382
  • 1
  • 10
  • 36
5
votes
2 answers

lark-parser indented DSL and multiline documentation strings

I'm trying to implement a record definition DSL using lark. It is based on indentation, which makes things a bit more complex. Lark is a great tool, but I'm facing some dificulteis. Here is a snippet of the DSL I'm implementing: record Order : …
Branquif
  • 53
  • 6
5
votes
2 answers

Priority in grammar using Lark

I have a priority problem in my grammar, and I don't have any more idea to fix it. I'm using Lark Here is the thing (I have simplified the problem as much as I can): from lark import Lark parser = Lark(r""" start: set | set_mul set_mul:…
Kypaz
  • 411
  • 3
  • 11
4
votes
1 answer

Lark how to describe a series of optional tokens

I am parsing a file with a format that can include: INT32 price min 10 max 100 alertIfSold ; The min, max and alertIfSold tokens are all optional and can appear in any order. That is INT32 price max 100 alertIfSold ; INT32 price …
Eli
  • 6,353
  • 9
  • 30
  • 25
4
votes
1 answer

How to balance rules and terminals in python lark parser?

I'm using lark, an excellent python parsing library. It provides an Earley and LALR(1) parser and is defined through a custom EBNF format. (EBNF stands for Extended Backus–Naur form). Lowercase definitions are rules, uppercase definitions are…
achedeuzot
  • 4,164
  • 4
  • 41
  • 56
3
votes
1 answer

Why do we need to specify the standard Lark lexer to be able to catch comment terminals?

I'm working on a Lark-based project where I need to be able to "catch" comments in the code being parsed. However it doesn't work when using the standard lexer without explicitly specifying the standard lexer. I have taken the second example from…
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
3
votes
1 answer

How to prevent lark from recognizing parts of an identifier as a keyword?

I've been experimenting with lark and I came across a little problem. Suppose I have the following grammar. parser = Lark(''' ?start: value | start "or" value -> or ?value: DIGIT -> digit | ID -> id DIGIT:…
Ushyme
  • 140
  • 1
  • 8
3
votes
1 answer

Lark parsing based on tree location

I am trying to write a Lark grammar and parser to write a DSL on top of numpy. However the Transformer needs to output Python code, not eval that code. So, for example, I'd like to have: my_parser("max(mat1/mat2, 20) / lag(mat1, 5)") and this would…
Jonathan
  • 1,287
  • 14
  • 17
2
votes
1 answer

How do I add operator precedence to a lark grammar for FOL with Equality?

How do I modify this grammar so it matches parenthesis that are further away? ?wff: compound_wff ?compound_wff: biconditional_wff ?biconditional_wff: conditional_wff (SPACE? BICONDITIONAL_SYMBOL SPACE? biconditional_wff)* ?conditional_wff:…
Vivek Joshy
  • 974
  • 14
  • 37
2
votes
0 answers

Error in defining closing parenthesis in grammar for C

I am trying to define a simple grammar for C which I am using in Lark. The problem is, I defined the closing parenthesis ("}" or ")") as a terminal in the grammar but it is throwing an error as "No terminal matches ')' in the current parser…
2
votes
1 answer

How can I make this grammar unambiguous?

I'm trying to write a parser for a simple language: parser = Lark(""" ?start: arithmetic_expr | boolean_expr // relational operation ?rel_op : arithmetic_expr ("<" | ">" | "==" | "!=") arithmetic_expr // boolean expression …
Ushyme
  • 140
  • 1
  • 8
2
votes
3 answers

How to parse C++ comments with lark?

How can I write a rule to parse C++ comments either on a line alone or after other code? I've tried lots of combinations, the latest one being: ?comment: "//" /[^\n]*/ NEWLINE
João M. S. Silva
  • 1,078
  • 2
  • 11
  • 24
2
votes
2 answers

Boolean expression parser in lark fails to parse 'a OR b OR c'

This Lark parser is based on this question and this website, but it fails when parsing a OR b OR c. The website…
rrauenza
  • 6,285
  • 4
  • 32
  • 57
1
2 3 4 5 6 7