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
11
votes
3 answers

Split string at commas except when in bracket environment

I would like to split a Python multiline string at its commas, except when the commas are inside a bracketed expression. E.g., the string {J. Doe, R. Starr}, {Lorem {i}psum dolor }, Dol. sit., am. et. Should be split into ['{J. Doe, R. Starr}',…
Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
11
votes
1 answer

Improving error messages with pyparsing

Edit: I did a first version, which Eike helped me to advance quite a bit on it. I'm now stuck to a more specific problem, which I will describe bellow. You can have a look at the original question in the history I'm using pyparsing to parse a small…
Jonathan Ballet
  • 973
  • 9
  • 21
11
votes
1 answer

How do I parse indents and dedents with pyparsing?

Here is a subset of the Python grammar: single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE stmt: simple_stmt | compound_stmt simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE small_stmt: pass_stmt pass_stmt: 'pass' compound_stmt:…
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
11
votes
2 answers

pyparsing - load ABNF?

can pyparsing read ABNF from a file instead of having to define it in terms of python objects? If not, is there something which can do similar (load an ABNF file into a parser object)
OJW
  • 4,514
  • 6
  • 40
  • 48
10
votes
1 answer

pyparsing capturing groups of arbitrary text with given headers as nested lists

I have a text file that looks similar to; section header 1: some words can be anything more words could be anything at all etc etc lala some other header: as before could be anything hey isnt this fun I am trying to contruct a grammar…
Matt Warren
  • 669
  • 8
  • 18
10
votes
1 answer

pyparsing example

It is my first attempt to use pyparsing and I'd like to ask how to filter this sample line: survey = '''GPS,PN1,LA52.125133215643,LN21.031048525561,EL116.898812''' to get output like: 1,52.125133215643,21.031048525561,116.898812 In general I have…
daikini
  • 1,307
  • 6
  • 23
  • 36
10
votes
1 answer

pyparsing performance and memory usage

Pyparsing worked fine for a very small grammar, but as the grammar has grown, the performance went down and the memory usage through the roof. My current gramar is: newline = LineEnd () minus = Literal ('-') plus = Literal ('+') star = Literal…
Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
10
votes
2 answers

pyparsing and line breaks

I just started with pyparsing and I have problems with line breaks. My grammar is: from pyparsing import * newline = LineEnd () #Literal ('\n').leaveWhitespace () minus = Literal ('-') plus = Literal ('+') lparen = Literal ('(') rparen = Literal…
Hyperboreus
  • 31,997
  • 9
  • 47
  • 87
10
votes
1 answer

Simple demonstration of using pyparsing's indentedBlock recursively

I am trying to use indentedBlock in pyparsing (which looks awesome to me) to dissect some nested indentations, but am struggling a bit with comprehending its description in the API reference (or the more specific examples under…
texb
  • 547
  • 2
  • 13
9
votes
2 answers

Extending the matplotlib mathtext parser

For most of my interactive plotting with matplotlib, I don't want to use latex processing of math. (Mostly because it's too slow, but also because it's just that little bit too blurry for frequent use IMHO.) But I also use my own macros all the…
Mike
  • 19,114
  • 12
  • 59
  • 91
9
votes
2 answers

pyparsing, forward, and recursion

I'm using pyparsing to parse vcd (value change dump) files. Essentially, I want to read in the files, parse it into an internal dictionary, and manipulate the values. Without going into details on the structure, my problem occurs with identifying…
RaytheonLiszt
  • 225
  • 1
  • 6
  • 15
9
votes
1 answer

Convert BNF grammar to pyparsing

How can I describe a grammar using regex (or pyparsing is better?) for a script languge presented below (Backus–Naur Form): := | := [* ] := "{" "}" | ; :=…
Max Tkachenko
  • 792
  • 1
  • 12
  • 30
9
votes
3 answers

Python delimited line split problems

I'm struggling to split text rows, based on variable delimiter, and preserve empty fields and quoted data. Examples: 1,"2",three,'four, 4',,"6\tsix" or as tab-delimited vesion 1\t"2"\tthree\t'four, 4'\t\t"6\tsix" Should both result in: ['1',…
user2123203
  • 145
  • 7
8
votes
1 answer

How to disallow spaces in between literals in pyparsing?

grammar = Literal("from") + Literal(":") + Word(alphas) The grammar needs to reject from : mary and only accept from:mary i.e. without any interleaving spaces. How can I enforce this in pyparsing ? Thanks
Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64
8
votes
2 answers

Pyparsing: space as a valid token

I'm using pyparser to process the output of a hex-to-text converter. It prints out 16 characters per line, separated by spaces. If the hex value is an ASCII-printable character, that character is printed, otherwise the converter outputs a period…
JS.
  • 14,781
  • 13
  • 63
  • 75
1
2
3
65 66