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
0
votes
1 answer

Is there a Python parsing library that can parse a TOML-like format that specifies nested fields with [ParentHeader_ChildSection]?

I want to parse an externally defined (and undocumented) file format in Python. It looks somewhat similar to TOML, but with different text styles, and no quoting. For example: [Schedule_Step122] m_nMaxCurrent=0 m_szAddIn=Relay OFF m_szLabel=06 - End…
markfickett
  • 552
  • 3
  • 11
0
votes
1 answer

Python lark dedent to non-0 column

guys, this should be an easy one, but I can't figure it out. I have a text that I need to parse that dedents to non-0 column, like this: text = """ firstline indentline partialdedent """ When I try to run grammar like this: start :…
thevoiddancer
  • 385
  • 2
  • 9
0
votes
1 answer

Parsing formulas using Lark / EBNF

I am working on parsing formulas written in an internal syntax. I am working with Lark. Its the first time im doing this, please bear with me. The formulas look something like…
VicVic
  • 23
  • 5
0
votes
1 answer

Python3-Lark: Convenient way to handle a rule with optional terminals?

In a grammar rule like the following one: top_rule: header? body footer? ?header: "DAY" DAY | "SECT" SECT ?body: BODY ?footer: "ENDING" | "TERMINATING" DAY: /\[^s]+/ SECT: /\d+/ BODY: /\[^s]+/ What is the most convenient way for…
ex1led
  • 427
  • 5
  • 21
0
votes
0 answers

Can I combine rules with the LALR parser without intermediate rule?

I have something equivalent to the following code: STRING_LITERAL: /"[^"]*"/ NUMERIC_LITERAL: /[0-9]+/ stmt: foo | bar | baz foo: "FOO " any_expression bar: "BAR " string_expression baz: "BAZ " numeric_expression ?any_expression: function |…
FrederikVds
  • 551
  • 4
  • 11
0
votes
1 answer

How do you parse sections of text with Lark in Python

I'm trying to figure out how to use the Lark Python Module to parse a document that looks like this: ---> TITLE Introduction ---> CONTENT The quick Brown fox ---> TEST Jumps over ---> CONTENT The lazy dog Each ---> marks the start of a…
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
0
votes
1 answer

define statement only works if followed by an assignment in Lark grammar

I am creating a parser with Lark. The parser works fine for most of the tests I ran, but failed with the define keyword. It only works if it is followed by an assignement. define a = 10 works just fine, but define b is not treated as a define…
Mstrdav
  • 91
  • 1
  • 5
0
votes
1 answer

How can I fix my DSL grammar to parse a problem statement?

I've been tasked with creating a grammar for a legacy DSL that's been in use for over 20 years. The original parser was written using a mess of regular expressions, so I've been told. The syntax is generally of the "if this variable is n then set…
MerseyViking
  • 389
  • 3
  • 19
0
votes
1 answer

Lark: How to ignore whitespace after parsing?

I am creating a REPL for Linux commands. Since my grammar for command is call: WS? (redirection WS)* argument (WS atom)* WS?, once the parsing is done, I always find whitespace is included as one of the nodes in the parse tree. I understand…
plzfday
  • 23
  • 1
  • 5
0
votes
2 answers

How do I write the lark grammar for First Order Logic with Equality?

According to AIMA (Russell & Norvig, 2010) this is the BNF grammar for FOL with Equality: How do I convert this to a lark grammar? Specifically, how do I represent n-ary predicates using lark grammar?
Vivek Joshy
  • 974
  • 14
  • 37
0
votes
1 answer

Parser or postlex causing an error in Lark

everyone. So, I'm parsing a shell output (mocked here) and I'm running into an error where I really don't expect. Minimum reproducible, working example is below: from rich import print as rprint import typing as tp from lark import Lark,…
thevoiddancer
  • 385
  • 2
  • 9
0
votes
0 answers

python: Lark-parser

I use the Lark library to parse boolean expressions like (A=(value1) OR B>(value2)) AND C<=(value3) and I also use it to parse keyless expressions like (A OR B) AND C the parser works correctly until I try to parse a keyless expression containing…
Zhihar
  • 1,306
  • 1
  • 22
  • 45
0
votes
1 answer

DSL for generating sequences

trying to create DSL to generate sequences ... here is what i did so far : ?start : expr token : WORD repeat_token : token ":" INT tokens : (token | repeat_token)+ repeat : ":" INT expr :…
sten
  • 7,028
  • 9
  • 41
  • 63
0
votes
0 answers

Lark simple sql grammar

I'm trying to parse a simple sql via this grammar: grammar = ``` program : stmnt* stmnt : select_stmnt | drop_stmnt select_stmnt : select_clause from_clause? group_by_clause? having_clause?…
Spart
  • 113
  • 1
  • 2
  • 8
0
votes
1 answer

Confusion around priority of tokens in lark grammar

Following up from an earlier question, I'm a bit confused about the precedence of the /.+/ regex line; I would expect the below test to produce line line x chunk abc instead I get: line line x line abc def…
RoyM
  • 1,118
  • 1
  • 9
  • 28