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.

898 questions
53
votes
4 answers

Parsing SQL with Python

I want to create a SQL interface on top of a non-relational data store. Non-relational data store, but it makes sense to access the data in a relational manner. I am looking into using ANTLR to produce an AST that represents the SQL as a relational…
codeape
  • 89,707
  • 22
  • 139
  • 171
37
votes
1 answer

Pyparsing : white spaces sometimes matter... sometimes don't

I would like to create a grammar for a file that contains several sections (like PARAGRAPH below). A section starts with its keyword (e.g. PARAGRAPH), is followed by a header (title here) and has its contents on the following lines, one line of…
carrieje
  • 495
  • 4
  • 11
32
votes
5 answers

How best to parse a simple grammar?

Ok, so I've asked a bunch of smaller questions about this project, but I still don't have much confidence in the designs I'm coming up with, so I'm going to ask a question on a broader scale. I am parsing pre-requisite descriptions for a course…
Nick Heiner
  • 108,809
  • 177
  • 454
  • 689
21
votes
5 answers

what next after pyparsing?

I have a huge grammar developed for pyparsing as part of a large, pure Python application. I have reached the limit of performance tweaking and I'm at the point where the diminishing returns make me start to look elsewhere. Yes, I think I know most…
Tal Weiss
  • 8,438
  • 6
  • 51
  • 58
19
votes
1 answer

Debugging Pyparsing Grammar

I'm building a parser for an imaginary programming language called C-- (not the actual C-- language). I've gotten to the stage where I need to translate the language's grammar into something Pyparsing can accept. Unfortunatly when I come to parse my…
greenie
  • 1,662
  • 3
  • 18
  • 33
19
votes
2 answers

parsing a complex logical expression in pyparsing in a binary tree fashion

I am trying to parse complex logical expression like the one below; x > 7 AND x < 8 OR x = 4 and get the parsed string as a binary tree. For the above expression the expected parsed expression should look like [['x', '>', 7], 'AND', [['x', '<',…
consumer
  • 689
  • 2
  • 7
  • 19
17
votes
4 answers

Simple recursive descent in PyParsing

I've tried taking this code and converting it to something for a project I'm working on for programming language processing, but I'm running into an issue with a simplified version: op = oneOf( '+ - / *') lparen, rparen = Literal('('),…
Charlie
16
votes
2 answers

Pyparsing setParseAction function is getting no arguments

I'm trying to parse a simple key = value query language. I've actually accomplished it with a huge monstrosity parser that I then make a second pass through to clean up the parse tree. What I'd like to do is make a clean parse from the bottom up,…
deontologician
  • 2,626
  • 1
  • 19
  • 31
14
votes
2 answers

How can I use pyparsing to parse nested expressions that have multiple opener/closer types?

I'd like to use pyparsing to parse an expression of the form: expr = '(gimme [some {nested [lists]}])', and get back a python list of the form: [[['gimme', ['some', ['nested', ['lists']]]]]]. Right now my grammar looks like this: nestedParens =…
Derek
  • 155
  • 2
  • 6
13
votes
1 answer

Can't get pyparsing Dict() to return nested dictionary

I'm trying to parse strings of the form: 'foo(bar:baz;x:y)' I'd like the results to be returned in form of a nested dictionary, i.e. for the above string, the results should look like this: { 'foo' : { 'bar' : 'baz', 'x' : 'y' } } Despite numerous…
kgr
  • 9,184
  • 2
  • 36
  • 42
12
votes
1 answer

PyParsing lookaheads and greedy expressions

I'm writing a parser for a query language using PyParsing, and I've gotten stuck on (what I believe to be) an issue with lookaheads. One clause type in the query is intended to split strings into 3 parts (fieldname,operator, value) such that…
Michael C. O'Connor
  • 9,186
  • 3
  • 34
  • 49
12
votes
3 answers

Python - pyparsing unicode characters

:) I tried using w = Word(printables), but it isn't working. How should I give the spec for this. 'w' is meant to process Hindi characters (UTF-8) The code specifies the grammar and parses accordingly. 671.assess :: अहसास ::2 x=number + "." + src…
boddhisattva
  • 5,836
  • 9
  • 44
  • 71
12
votes
2 answers

Parsing logical sentence very slow with pyparsing

I try to use pyparsing to parse logical expressions such as these x FALSE NOT x (x + y <= 5) AND (y >= 10) OR NOT (z < 100 OR w) (A=True OR NOT (G < 8) => S = J) => ((P = A) AND not (P = 1) AND (B = O)) => (S = T) ((P = T) AND NOT (K =J) AND (B…
Vu Nguyen
  • 947
  • 1
  • 6
  • 20
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
  • 903
  • 8
  • 21
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,232
  • 6
  • 35
  • 45
1
2 3
59 60