Questions tagged [pyparsing]

The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. The pyparsing module provides a library of classes that client code uses to construct the grammar directly in Python code.

Pyparsing is a Python module for creating and executing simple grammars. This is an alternative approach to the traditional lex/yacc or regular expressions. The pyparsing module provides a library of classes that client code uses to construct the grammar directly in Python code.

981 questions
0
votes
2 answers

how to preserve types when using pyparsing and returning the result as a dictionary

I'm a newbie in pyparsing and hope somebody can help me.The type of text I am trying to parse is of the following structure: I have key=value pairs in a line that can have one or more pairs. The values can be of many types such as string, int,…
Sandra
  • 11
  • 2
0
votes
1 answer

Python: Can't install pyparsing for matplotlib on Mac

I am trying to install Matplotlib for Python on Mac. First it threw an error stating that dateutil is not installed. After I installed that, I got the error message that pyparsing should be installed first. So I started to download pyparsing and…
SexyBeast
  • 7,913
  • 28
  • 108
  • 196
0
votes
4 answers

Need help designing a regex or pyparsing approach to modify all words enclosed within pipes

For example: blahblah|0A 4D 5E 43|adfsdasd|92| sgagrewas|12 5E| Must become blahblahx0Ax4Dx5Ex43adfsdasdx92 sgagrewasx12x5E I'm trying something along the lines of: re.sub(r'\|(\w+ ?)*\|', r'x\1', a) But I'm having trouble getting it to work on…
jck
  • 1,910
  • 4
  • 18
  • 25
0
votes
2 answers

Adding external information to ParseResults before return

I want to add external information to ParseResults before return. I return the results of parsing as asXML(). The external data represented as dictionary so as to parsed as XML in the final parsing. This the code before adding external data from…
0
votes
1 answer

Contextual parsing of structured text configuration files using pyparsing

I'm trying to build a simple parser using pyparsing. My example file looks as follows: # comment # comment name1 = value1 name2 = value2 example_list a foo bar grp1 ( example_list2 aa foo bar example_list3 bb foo bar ) grp2…
Colin 't Hart
  • 7,372
  • 3
  • 28
  • 51
0
votes
1 answer

How can I use pyparsing to data from VC++ autoexp.dat?

I cannot understand how parse following data using python. I don't understand how get values from nested #( and #if(. preview ( #if ($e.d.stateFlags == 0) ( $e.d ) #else ( #( $e.d->scheme, $e.d->host, $e.d->path ) …
KindDragon
  • 6,558
  • 4
  • 47
  • 75
0
votes
1 answer

Pyparsing: a list of optional elements: weird issue with Optional, Each, and ordering of parser elements

I'm trying to parse an XML-like file (with no associated DTD) with pyparsing. Part of each record looks has the following contents: Something within and tags, One or more things within and tags, Optionally, something within
ShreevatsaR
  • 38,402
  • 17
  • 102
  • 126
0
votes
1 answer

setResultsName shows only first list item

Consider the following minimal example: from pyparsing import Word, delimitedList the_list = delimitedList(Word("fine").setResultsName("extension", listAllMatches=True)) prefixed = Word("okay").setResultsName("base") +…
Inkane
  • 1,440
  • 1
  • 15
  • 32
-1
votes
1 answer

Suppress C++ comments in pyparsing to load enums correcly

The second answer in this link provides a way to load enums from C++ to python: Can python load definitions from a C header file? The code works with the given example: sample = """ stuff before enum hello { Zero, One, Two, Three, …
-1
votes
3 answers

python regex: either or or both with separator

I need a regular expression to match a, b or a;b. I cannot write a|b|a;b because a and b contain named groups and if I try to do this I get an Exception: redefinition of group name 'a' as group 8; was group 3 at position 60. a;?b does not work…
jakun
  • 624
  • 5
  • 13
-1
votes
2 answers

python - pyparsing - How to parse functions containing tuples?

So I am making a parser, but the program doesn't parse functions that have tuples as arguments. For example, when I use the dist function defined as below: def dist(p, q): """Returns the Euclidean distance between two points p and q, each given…
TheOneMusic
  • 1,776
  • 3
  • 15
  • 39
-1
votes
2 answers

pyparsing - How to parse commas to use in functions

So I am making a parser, but the program doesn't parse commas. For example: >>> evaluate("round(pi)") 3 >>> evaluate("round(pi, 2)") SyntaxError: Expected {{[- | +] {{{{{{{W:(ABCD..., ABCD...) Suppress:("(") : ...} Suppress:(")")} | 'PI'} | 'E'} |…
TheOneMusic
  • 1,776
  • 3
  • 15
  • 39
-1
votes
1 answer

How to handle backslash and tilde appearing in a string while using pyparsing

I need to handle backslash and tilde while using pyparsing in my piece of code and to keep it simple I used printables but this code raises an exception: import string import pyparsing as pp from pyparsing import * log_display =…
nlp
  • 109
  • 1
  • 4
  • 19
-1
votes
1 answer

How capture everything before operator in Pyparsing

Referring to Pyparsing problem with operators I am trying to create pyparsing grammar. I want to capture space separated entity as single word before operator "and"/"or". Expected result is : (United kingdom or Sweden) ['United…
Vikram Sangat
  • 136
  • 11
-1
votes
1 answer

pyparsing - String parsing to generate Where clause

I have a string that looks something like this - ((COL1==VAL1)+(COL2==VAL2)) I want to convert this to following format: ((a.col1 == 'VAL1') & (a.col2 == 'VAL2')) Another example - From: ((COL1==VAL1)|(COL2==VAL2/A)) TO: ((a.col1 == 'VAL1') |…
santosh
  • 57
  • 7
1 2 3
65
66