Questions tagged [parsimonious]

Arbitrary-lookahead parser written in pure Python that accepts EBNF-alike definition of grammars to create a parser. It claims to be the fastest parser generator of this kind.

parsimonious is an arbitrary-lookahead parser written in pure Python that accepts EBNF-alike definition of grammars to create a parser. It claims to be the fastest parser generator of this kind.

It is based on Parsing Expression Grammars (PEG). PEGs can describe a superset of LL(k) languages, any deterministic LR(k) language and many others—including some that aren't context-free.

With caching, they take O(grammar size * text length) memory, but they run in O(text length) time.

The technical details are available on GitHub.

25 questions
14
votes
1 answer

Why is Parsimonious rejecting my input with an IncompleteParseError?

I've been trying to work out the basic skeleton for a language I've been designing, and I'm attempting to use Parsimonious to do the parsing for me. As of right now, I've, declared the following grammar: grammar = Grammar( """ program =…
Ethan Bierlein
  • 3,353
  • 4
  • 28
  • 42
5
votes
1 answer

parsimonious parser - error trying to parse assignment grammar

I'm using the Python Parsimonious Parser to try to build an interpreter for a simple language I'm designing. I watched this tutorial video which was very helpful, and now I'm slowly modifying the code to match my own rules. I'm stuck on an…
rafiki_rafi
  • 1,177
  • 2
  • 11
  • 27
3
votes
2 answers

NodeVisitor class for PEG parser in Python

Imagine the following types of strings: if ((a1 and b) or (a2 and c)) or (c and d) or (e and f) Now, I'd like to get the expressions in parentheses, so I wrote a PEG parser with the following grammar: from parsimonious.grammar import…
Jan
  • 42,290
  • 8
  • 54
  • 79
3
votes
1 answer

Parsimonious ParseError

Digging deeper into grammars and PEG in special, I wanted to have a DSL with the following syntax: a OR (b AND c) I am using parsimonious here with the following grammar: from parsimonious.grammar import Grammar grammar = Grammar( """ expr …
Jan
  • 42,290
  • 8
  • 54
  • 79
3
votes
1 answer

Parse multiline text using the Parsimonious Python library

I am trying to parse multiline text with the python parsimonious library. I've been playing with it for a while and can't figure out how to deal effectively with newlines. One example is below. The behavior below makes sense. I saw this comment from…
Mark
  • 309
  • 1
  • 9
3
votes
1 answer

How to parse alternatives in parsimonious that start with same characters

I'm using parsimonious to do some parsing and I'm having trouble figuring out how to properly parse alternatives that share the first character in an unordered away: For example: Text: 2 > 3 2 >= 3 Grammar: expr = ~"[0-9]+" space operator space…
therealtypon
  • 455
  • 2
  • 5
  • 12
2
votes
2 answers

Escaped Strings in Parsing Expression Grammars

I am attempting to write a grammar for a small language utility using the python library parsimonious, but I am struggling with writing a part, which covers strings, especially strings with escaped quotes and other special characters. I have the…
Drakekin
  • 1,341
  • 1
  • 11
  • 23
1
vote
2 answers

uniformly distributed unbiased 4bit parsimonious range mapping from a bit limited TRNG

I am trying to implement a range mapper for TRNG output files for a C application with ranges of up to 4 bits in size. Due to the pigeonhole bias problem I have settled on using a discard algorithm. My idea for a parsimonious algorithm would be…
iamoumuamua
  • 351
  • 2
  • 11
1
vote
1 answer

Why doesn't parsimonious parse this?

I seem to be completely stuck with understanding why this is failing to parse. Following is my simple grammar (just playing around trying to understand parsimonious and hence the grammar may not make sense). from parsimonious.grammar import…
prabhu
  • 919
  • 2
  • 12
  • 28
1
vote
1 answer

python parsing: what file format uses `=>` OR how to read custom input files to dict

When using the zmdp solver from here i came across a funky file format that I haven't seen before, it uses => for assignment. I wasn't able to find out what format it was from the package documentation (it says it is a "policy" format, but it must…
mattu
  • 944
  • 11
  • 24
1
vote
2 answers

parsimonious - Rule 'rules' matched in its entirety, but it didn't consume all the text

I am making a simple parser for expressions and this is my code: import parsimonious as parmon parser = parmon.Grammar(r""" E = E "+" E / id id = "0"/"1"/"2"/"3"/"4"/"5"/"6"/"7"/"8"/"9" """) code =…
1
vote
2 answers

python parsimonious: Parsing config file with multiple comment marks

I'm trying to parse a config file where a the value of an entry may have a comment mark in it. So the rule is only the last comment mark is the divider between the value and the comment. For example: key1 = value key2 = value;This is a…
Omer
  • 456
  • 1
  • 3
  • 19
1
vote
1 answer

Most efficient way to modify variables within a custom grammar?

I'm working with a propriety driving simulator which generates "scenario" files in a customised version of Scilab. I am provided a single 11,000 line long "master" file, and from this I need to replace certain values to generate n versions of the…
1
vote
1 answer

OrderedDict for Parsimonious

I'm using parsimonious to parse some csv. My problem is that the output generated is not coming out in the order expected. For example, if the input string is Load,File,Sample then I'd expect to get: import database from Sample What I get…
Drew Rush
  • 710
  • 5
  • 19
0
votes
0 answers

How to completely ignore whitespaces in parsimonious?

I have the following code that parses arithmetic expressions using parsimonious. It works OK but whitespaces are included in the parse tree. How can we get rid of whitespaces in the parse tree and only keep the meaningful tokens? Lark parsing…
Tarik
  • 10,810
  • 2
  • 26
  • 40
1
2