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

How to handle all possible C like block comment styles in PyPEG

After giving up on parsimonous I tried PyPEG. I've had much more success in that I've achieved my initial goal, but can't seem to handle comments properly. I've distilled the issue into the following code. You can see that not all the test cases…
Jay M
  • 3,736
  • 1
  • 24
  • 33
0
votes
1 answer

Why does this Python parser using parsimonious never find the ifdef blocks

This is a simplified version of a larger parser. I has been driving me slightly mad as I can't seem to get it to work consistently. The larger version works but has so many edge cases it does not work well enough, I'm finding myself having to teach…
Jay M
  • 3,736
  • 1
  • 24
  • 33
0
votes
1 answer

How to write a PEG parser that fully consumes any and all text whilst still matching other given rules?

I'm making an application to make writing (PEG) parsers more approachable and user friendly for people without experience. Yes it has been done before but it's a good learning experience for me regarding GUIs. Part of what makes it approachable…
Shefeto
  • 178
  • 1
  • 10
0
votes
1 answer

parsimonious - a simple recursive pattern

I want to be able to parse simple rule expressions that can be joined together using conjunction words like and and or within parsimonious. I've tried a very rudimentary grammar, which parses a simple expression, but fails as soon as I start…
Thomas Kimber
  • 10,601
  • 3
  • 25
  • 42
0
votes
0 answers

parsing ingredient list with parsimonious

from parsimonious.grammar import Grammar grammar = Grammar( ''' # item = ( ( ingredient+ '(' ingredient+ ')' comma ws?) + / comma+ / ws+ / ingredient )+ item = ((ingredient '(' ingredient ')') / ingredient )+ ingredient = ( (…
Dave
  • 390
  • 1
  • 6
  • 16
0
votes
1 answer

Get parsimonious to print useful error message for Sequence blocks

I'm using parsimonious (python PEG parser library) to parse text that looks like this: text = """ block block_name_0 { foo } block block_name_1 { bar } """ It is a series of blocks with a simple body requirement (must be alphanum) that…
therealtypon
  • 455
  • 2
  • 5
  • 12
0
votes
2 answers

Understanding Parsing Error when reading model file into PySD

I am receiving the following error message when I try to read a Vensim model file (.mdl) using Python's PySD package. My code is: import pysd import os os.chdir('path/to/model_file') model = pysd.read_vensim('my_model.mdl') The Error I receive…
Cortney
  • 1
  • 1
0
votes
0 answers

Parse bitarray in python

I am using bitarrays in one of my projects to store the bits(reading from a file which has "0"s and "1"s, and time information which is required. File can also have not necessary fields like comments etc.). Now I want to parse the bits. I filter out…
user2109788
  • 1,266
  • 2
  • 12
  • 29
0
votes
3 answers

Parse a sequence of binary digits

How can I parse sequence of binary digits in python. Following is an example for what i am trying to do. I have a sequence of binary digits, for example sequence = '1110110100110111011011110101100101100' and, I need to parse this and extract the…
user2109788
  • 1,266
  • 2
  • 12
  • 29
-1
votes
1 answer

pysd library ParseError

I'm using a library called pysd to translate vensim files to Python, but when I try to do it (library functions) I get a parse error but don't understand what it means. This is my log. ParseError Traceback (most…
Esteban
  • 11
  • 3
1
2