114 questions
0
votes
0
answers
38
views
Context-sensitive rules in lark LARL parser
I'm building a LALR grammar for a language where ">" can be either
a) the greater-than operator
b) the closing bracket of a "<" ... ">" construct (tuple literal)
...
1
vote
1
answer
76
views
optional Newline at end of file messes up lark grammar parsing
I have a file contents. if the final line has a NL at the end, i get 2 token trees as expected, but of the file doesn't have a final NL, i end up with 3 trees which is unwanted.
How do i get lark to ...
2
votes
1
answer
79
views
Why does this grammar work using the Earley parser but not LALR(1)
I wrote this grammar to describe a simple patch procedure we use at work, operating on source code files. Engineers check in files of the form:
{ignored space}
//find_start {possible comment or ...
0
votes
1
answer
60
views
Python package Lark does not build the grammar correctly
I would need to build a Tree that would retrieve something like this using Lark package:
start
expr
or_expr
and_expr
comp_expr
identifier Name
comparator ...
0
votes
0
answers
30
views
no matches for a rule in lark grammar
I'd like to catch some word in text (say, "var"). So the rules
rules = r"""
start: expr+
expr: var | anything
var.2: VAR
anything: ANYTHING
ANYTHING: /[\...
0
votes
0
answers
49
views
Multiple Aliases for a Terminal or Rule
Can one assign multiple aliases for a terminal or rule in Lark ?
Consider the following grammar
coordinate : "(" X "," Y ")"
%import common.SIGNED_NUMBER -> X
%import ...
0
votes
1
answer
91
views
Handling the presence or absence of a token in EBNF / Lark
I'm making early steps with the Lark library in Python and am really looking forward to replacing a lot of awful if statements with an EBNF parser..!
The task here is interpreting the times written in ...
2
votes
2
answers
140
views
LALR Grammar for transforming text to csv
I have a processor trace output that has the following format:
Time Cycle PC Instr Decoded instruction Register and memory contents
905ns 86 00000e36 00a005b3 c.add ...
1
vote
0
answers
58
views
How to extract a string according to rule of python lark ebnf?
I would like to parse the following PlantUML which likes flow-charts, by using python lark package.
The syntax of each action is based on verilog-hdl.
PlantUML
@startuml
:[7:0] a;
:write(reg01, 8'h01, ...
0
votes
1
answer
127
views
Unclear reason for terminal collision
I am new to lexers and parsers in general and to working with Lark in particular. I am using the versions lark 1.1.9 and interegular 0.3.3.
I started writing a grammar which produces a warning when ...
1
vote
0
answers
40
views
Avoid doubling every rule for NEWLINE vs DOUBLE_NEWLINE
I want blank new lines to be syntactically significant (optimization for leaf leaning trees [[[a, b], c, d], e, [g], f] == [a b | c d | e [g] f] but with \n\n instead of |). But the only way I can ...
0
votes
1
answer
193
views
Lark: how to inline rule. DRY
I dont want the func rule here, it's merely to avoid repetition.
func: monad | dyad | builtin
dyad: "{" dyad* func+ "}" | func+ ":"
monad: "(" monad* func+ &...
0
votes
1
answer
132
views
Disambiguating expressions in Lark syntax
I have a (Lark) grammar that I think should be unambiguous, but depending on the version of Lark, fails to parse in one way or another:
import lark
syntax = r"""
stmt: mov_stmt
| ...
0
votes
2
answers
181
views
Why is my example to parse bold text with Lark not working?
I defined the following grammar:
from lark import Lark
grammar = r'''
start: ( bold_text | text)
bold_text.2: "**" text "**"
text.1: /.+/
'''
parser = Lark(grammar, ...
1
vote
1
answer
161
views
SQL Select Statement Parser not returning JOIN type
I want to parse through a SQL Select Statement that has all the features a normal SQL dialect like MySQL has too. I looked for parsing libraries in python but couldn't find one that is doing the job. ...
1
vote
1
answer
256
views
Using Lark to parse a message definition file then generate C++ code
So I'm definitely new to the concept and application of ENBF grammar and Lark in python. I'm having a bit of success but also am stuck on how to optimally do the next step of this project. To start ...
0
votes
1
answer
246
views
Newline handling in python3 lark parser
I am using python(3.11.5) with lark-parser.
I am directly using the included python3 grammar, from https://github.com/lark-parser/lark/blob/master/lark/grammars/python.lark.
I am facing an issue in ...
0
votes
0
answers
612
views
Capturing inner string in lark using regex
Ok, so, this is probably a bit convoluted solution and I should probably use something simple, but it is what is.
I have a huge text I want to parse using python's lark and I'm piecing together ...
0
votes
3
answers
708
views
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]
...
0
votes
1
answer
115
views
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
...
0
votes
1
answer
434
views
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 this:
MEAN(1,SUM({T(F_01....
1
vote
1
answer
358
views
Failed tree-less parsing using python lark
I use lark to parse lines of a log file. The log file contains some equations and I would like to extract the left hand side and right hand side of the equations and store them in a dictionary. ...
1
vote
1
answer
914
views
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"
| "...
0
votes
1
answer
301
views
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
---&...
0
votes
1
answer
157
views
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 ...
0
votes
1
answer
121
views
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 ...
1
vote
0
answers
82
views
Replacing Arithmetic operations in C program with ternary operations and return the modified program
This is my first post on a community forum like stackoverflow so please forgive any mistakes.
I am working in the field of program repair and unable to pass this roadblock.
For every arithmetic ...
3
votes
3
answers
2k
views
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 ...
1
vote
0
answers
176
views
Boolean expression parser
I'd like to implement a parser that helps me working on more complex boolean logic expressions for designing digital circuits. But I seem to be dumb.
start:equation
equation: SYMBOL
| ...
2
votes
1
answer
815
views
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?...
0
votes
2
answers
1k
views
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 ...
0
votes
1
answer
692
views
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
...
1
vote
0
answers
856
views
How to define end-of-file in a Lark grammar?
Suppose I am trying to define a grammar for text like this (simplified example):
foo=bar
baz=x
y=z
The goal is to be able to parse, modify and write back data like this. I want to preserve whitespace....
0
votes
0
answers
520
views
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 ...
2
votes
1
answer
2k
views
How to match any terminal string with a regex in the Python Lark Parser and the meaning of /.+/>?
Question
TLDR: I want to match anything but /.+?/ doesnt' seem to work, why?
I have the following super simple grammar and code:
from lark import Lark, Tree
parser: Lark = Lark(r"""
...
1
vote
1
answer
214
views
Trouble parsing next line Lark
What's up.
So, I'm having trouble getting more than one line to be accepted properly by the parser.
from lark import Lark
class SetLanguageLarkParser():
def __init__(self):
self....
1
vote
0
answers
253
views
How to remove ambiguity of this grammar using lark
I have build a grammar for propositional formulas, however I have found that it is ambiguous, i.e., there is more than one derivation tree for my input formulas.
This is the smallest ambiguous grammar ...
0
votes
1
answer
84
views
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 : (...
0
votes
0
answers
712
views
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 ...
1
vote
2
answers
2k
views
how does one match EOL (newline) with lark?
I'm using the lark parser with python. I'd like to use EOL as part of the grammar since it is line oriented. I'm getting an error when I try to put the regex in for matching EOL. I see some examples ...
1
vote
1
answer
366
views
Parsing elements/fields without end marker, problems with non-greedy regex, usage of a custom lexer
I want to be able to parse files in the Textile markup lanaguage (https://textile-lang.com/) in order to convert it to LaTeX. The file I have is a bit of an extension of Textile, since it adds fields ...
0
votes
1
answer
775
views
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
...
0
votes
1
answer
981
views
recognizing multi-line sections with lark grammar
I'm trying to write a simple grammar to parse text with multi-line sections..
I'm not able to wrap my head around how to do it.
Here's the grammar that I've written so far - would appreciate any help ...
1
vote
1
answer
135
views
Matching arbitrary player names
I'm using lark but can't figure out how I could match all players name as they can be complex with lark rules?
Example pattern is "Seat {number}: {player} ({chips} in chips)" and I want all ...
2
votes
0
answers
121
views
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 ...
2
votes
2
answers
945
views
Why does python's open() function mangle my utf-8 files?
This is a strange one, and it might be due to a python update, because it worked fine yesterday with no changes. Here we go:
I have a program that opens utf-8 files (that use accented characters, etc, ...
0
votes
0
answers
166
views
Python LARK: terminal character inside text confusion
I'm trying to parse using Python Lark the output of a plan from a database. Here's my grammar:
start: op
op: command "(" op ")" "[" text "]"
| command &...
1
vote
2
answers
759
views
Lark matching custom delimiter multiline strings
I am trying to use lark to extract some information from perl files. For that, I need a basic understanding of what a statement is. The issue I came across are "Here Document" strings. I ...
0
votes
0
answers
353
views
How to "catch" terminals in Lark-based parser using the 'dynamic' lexers
This is a follow-up question to my previous: Why do we need to specify the standard Lark lexer to be able to catch comment terminals?
I need to "catch" and save comments in the DSL parsed by ...
3
votes
1
answer
786
views
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 ...