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
2 answers

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 would describe them as multiline strings with custom…
user766308
  • 103
  • 7
1
vote
1 answer

Getting next possible tokens with lark parsing

I wanted to know if there is a way to get the next possible token of a given string and a given grammar with lark parsing. For example if I have the grammar. ?start: NAME "=" possible_values possible_values: "apple" | "banana" | "orange" and I…
Pablo Estrada
  • 3,182
  • 4
  • 30
  • 74
1
vote
1 answer

How to add a small bit of context in a grammar?

I am tasked to parse (and transform) a code of a computer language, that has a slight quirk in its rules, at least I see it this way. To be exact, the compiler treats new lines (as well as semicolons) as statement separators, but other than that…
Jock Tanner
  • 70
  • 2
  • 8
1
vote
1 answer

Lark : how to pick only some patterns

I would like to extract from a text file only some structured patterns. example, in the text below: blablabla foo FUNC1 ; blabliblo blu I would like to isolate only 'foo FUNC1 ;'. I was trying to use lark parser with the following…
Pierre G.
  • 4,346
  • 1
  • 12
  • 25
1
vote
0 answers

How to implement lookaheads in Lark?

I'm currently looking at the work done to write the Python 3.8 grammar with Lark, and I'm wondering how that can be done with the Python 3.9 grammar specification which looks a bit simpler to me. Note that I'm not sure of whether my approach…
PatW
  • 141
  • 5
1
vote
1 answer

How can I split a rule with Lark EBNF?

I'm writing a grammar for parsing PlantUML State diagrams and have the following doubt: I had: transition: STATE arrow STATE (":" event? guard? action?)? "\n" arrow: ("->" | "-->" | "-left->" | "-right->" | "-up->" | "-down->") But had to change…
1
vote
1 answer

Beginner Question: "No terminal defined for 'i' at line 2 col 1 int "i" 10" Lark

I am very new to lark and am trying to create a simple parser, but I am getting suck on a seemingly simple quesion, why does "No terminal defined for 'i' at line 2 col 1 int "i" 10" show up? Here is my grammar: start: set_str |…
Asra
  • 151
  • 1
  • 11
1
vote
0 answers

How to match opening and closing tags in Lark?

I'm trying to create a parser using Lark for WordPress shortcodes. The self-closing tags in the language have no differentiating features from standard opening tags, causing a fair bit of ambiguity even in perfectly valid syntax. I've got it mostly…
A.Gudek
  • 11
  • 2
1
vote
1 answer

Lark Parser raising error when evaluating print statement after if/else statement

so I'm making a programming language using python and the lark library for parsing. When I'm parsing the following if 5 == 4 { print("TRUE"); } else { print("FALSE"); } print("Done!"); It raises the following error PS E:\ParserAndLexer> &…
1
vote
1 answer

Parse trailing line comments with lark and LALR

Given are the following lark grammar and Python source code: start: (TEXT _NEWLINE)+ TEXT: /[^\n]+/ COMMENT: /\/\/[^\n]*/ _NEWLINE %ignore COMMENT _NEWLINE: (" "* "\n")+ from lark import Lark parser = Lark.open("grammar.lark",…
Scriptim
  • 1,743
  • 2
  • 20
  • 37
1
vote
0 answers

Python - Lark - Grammar - String

I'm trying to parse a little pseudo-code I'm writing and having some trouble finding which expression format is actually provided as a string. I was successful to get it working with regex and tokenizer methods, but the strings will be more in…
DonOfDen
  • 3,968
  • 11
  • 62
  • 112
1
vote
1 answer

retrieve tokens in lark python

so I'm using the Lark library in python to parse some text and I'm facing 2 problems. I searched in the documentation but I couldn't find a way to retrieve tokens from a tree, and the second one is that I was expecting a Tree with multiple tokens,…
Djellal Mohamed Aniss
  • 1,723
  • 11
  • 24
1
vote
1 answer

Match substrings in lark

How can properly match substrings using Lark? My intention (maybe it's not possible/advisable with Lark, or any CFG) is to match and parse only important parts of the string, ignoring the rest. For example: From "John", I'd like to parse "John" as…
Rodrigo
  • 321
  • 2
  • 11
1
vote
1 answer

Lark: parsing special characters

I'm starting with Lark and got stuck on an issue with parsing special characters. I have expressions given by a grammar. For example, these are valid expressions: Car{_}, Apple3{3+}, Dog{a_7}, r2d2{A3*}, A{+}... More formally, they have form:…
Matho
  • 295
  • 5
  • 14
1
vote
1 answer

Lark Parser: No terminal defined for ':' (Seeming bias against colon character ":")

I have the following rule (taken from SMTP - RFC5321): !path : "<" [ a_d_l ":" ] mailbox ">" When I try to parse this line: I get the following error: No terminal defined for ':' What's unusual is that if I…
Benjamin Basmaci
  • 2,247
  • 2
  • 25
  • 46