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
1
vote
1 answer

LARK: All occurrences but the last one?

Let say I have the following : items : (item separator)+ this would work for : i1, i2, i3, but not for : i1, i2, i3 how to make it so it does not require end-separator ?
sten
  • 7,028
  • 9
  • 41
  • 63
1
vote
3 answers

LARK: Parsing : Implementing import file?

How would you implement a grammar that can import a file and still parsing it using LARK ? f.e.: @import file.txt .....
sten
  • 7,028
  • 9
  • 41
  • 63
1
vote
1 answer

Node depth encoded as number of stars

Documents in this language look like * A top-level Headline Some text about that headline. ** Sub-Topic 1 Text about the sub-topic 1. *** Sub-sub-topic More text here about the sub-sub-topic ** Sub-Topic 2 Extra text here about…
Hatshepsut
  • 5,962
  • 8
  • 44
  • 80
1
vote
1 answer

Lark parser grammar works with Earley but not LALR

Consider this simple test of the Python Lark parser: GRAMMAR = ''' start: container* container: string ":" "{" (container | attribute | attribute_value)* "}" attribute: attribute_name "=" (attribute_value | container) attribute_value: string ":"…
C. E.
  • 10,297
  • 10
  • 53
  • 77
1
vote
2 answers

How to exclude certain possibilities from a regular expression?

For a parser I am creating, I use this regular expression as the definition of an ID: ID: /[a-z_][a-z0-9]*/i (For anyone who is not familiar with the syntax of the particular parser I'm using, the "i" flag simply means case-insensitive.) I also…
Elektito
  • 3,863
  • 8
  • 42
  • 72
1
vote
2 answers

Collision in between "END" and "END IF" in BASIC grammar, using Lark

I'm trying to create an LALR parser for BASIC using Lark, and I'm having a hard time fixing a collision between the "END" statement and statements like "END IF". Here's a simplified version of the grammar: %ignore /[ \t\f]+/ program: _nlopt…
Elektito
  • 3,863
  • 8
  • 42
  • 72
1
vote
0 answers

difference between earley and lalr parser in lark?

I have a simple grammar, which parse key-value pairs section by section. k1:1 k2:x k3:3 k4:4 The grammar I have for it is: start: section (_sep section)* _sep: _NEWLINE _NEWLINE+ section: item (_NEWLINE item)* item: NAME ":" VALUE _NEWLINE:…
echo
  • 2,666
  • 1
  • 25
  • 17
1
vote
1 answer

How to parse invalid JSON using Lark?

Let's start by considering a simple json parser using lark: import sys from lark import Lark, Transformer, v_args json_grammar = r""" ?start: value ?value: object | array | string | SIGNED_NUMBER ->…
BPL
  • 9,632
  • 9
  • 59
  • 117
1
vote
2 answers

RecursionError: maximum recursion depth exceeded while using lark in python

I've written the decaf grammar specified in cs143 course. Here is my code. import sys from lark import Lark, Transformer, v_args decaf_grammar = r""" start : PROGRAM PROGRAM : DECL+ DECL : VARIABLEDECL | FUNCTIONDECL | CLASSDECL |…
Umair Javaid
  • 421
  • 2
  • 7
  • 22
1
vote
1 answer

How to get a control flow graph of a program?

I want to get a control flow graph of a code/program (be it any programming language and given its grammar). I have tried using lark library in python to parse a basic C sample program [I provided the grammar for basic c syntax to lark]. As a…
1
vote
0 answers

Understanding what constitutes an ambiguity in a lark grammar

I was trying to simplifying the case presented in another question and got to the following parsing attempt using lark: from lark.lark import Lark text = """ start_thing { loc int { from 0, to 1093, strand plus, id gi 384632836 …
bli
  • 7,549
  • 7
  • 48
  • 94
1
vote
1 answer

Correctly set priorities between rules and terminals in a grammar for lark

This is my first time writing a parser using a grammar and a parser generator. I want to parse some kind of asn.1 format using the lark python module. Here is an example of the data I'm trying to parse: text = """ start_thing { literal { …
bli
  • 7,549
  • 7
  • 48
  • 94
1
vote
1 answer

LARK parsing error for hex number

I try to parse hex number with: hex_number : "0x" HEXDIGIT+ and with 0xA as input, and it always throws me an error, A is unexpected token.
1
vote
0 answers

Python: create grammar and realize operators

I try to describe grammar and operators. I use next code from lark import Lark json_parser = Lark(r""" ?start: value ?value: dict | array | operator |…
Petr Petrov
  • 4,090
  • 10
  • 31
  • 68
1
vote
0 answers

Python: creating DSL

I need to solve some specialized task, connecting with creating a DSL to specific purposes. But I have no experience with it and after some research I choose python Lark. I need to realize some like age1 = 20, age2 = 35; If age1 more than age2,…
Petr Petrov
  • 4,090
  • 10
  • 31
  • 68