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
61
votes
6 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
  • 97,830
  • 24
  • 159
  • 188
37
votes
6 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
  • 119,074
  • 188
  • 476
  • 699
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
23
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,889
  • 8
  • 54
  • 62
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,732
  • 4
  • 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
  • 709
  • 3
  • 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,764
  • 1
  • 21
  • 33
15
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
  • 165
  • 2
  • 6
14
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
  • 6,908
  • 11
  • 48
  • 72
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,750
  • 2
  • 38
  • 43
13
votes
1 answer

pyparsing nestedExpr and nested parentheses

I am working on a very simple "querying syntax" usable by people with reasonable technical skills (i.e., not coders per se, but able to touch on the subject) A typical example of what they would enter on a form is: address like street AND vote = …
Hal
  • 537
  • 4
  • 13
13
votes
3 answers

Parsing nested function calls using pyparsing

I'm trying to use pyparsing to parse function calls in the form: f(x, y) That's easy. But since it's a recursive-descent parser, it should also be easy to parse: f(g(x), y) That's what I can't get. Here's a boiled-down example: from pyparsing…
JasonFruit
  • 7,764
  • 5
  • 46
  • 61
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,742
  • 3
  • 37
  • 49
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
  • 987
  • 1
  • 9
  • 20
1
2 3
65 66