pyparsing

SQL parsing using pyparsing

对着背影说爱祢 提交于 2020-01-22 15:36:45
问题 I am learning PyParsing in last few weeks. I plan to use it to get table names from SQL statements. I have looked at http://pyparsing.wikispaces.com/file/view/simpleSQL.py. But I intend to keep the grammar simple because I am not trying to get every part of select statement parsed rather I am looking for just table names. Also it is quite involved to define the complete grammar for any commercially available modern day database like Teradata. #!/usr/bin/env python from pyparsing import *

Adding external information to ParseResults before return

和自甴很熟 提交于 2020-01-22 03:03:26
问题 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 pyparsing import * # a hypothetical outer parser, with an unparsed SkipTo element color = oneOf("red orange yellow green blue purple") expression = SkipTo("XXX") + Literal("XXX").setResultsName('ex') + color.setResultsName('color') data = "JUNK 100

Can a BNF handle forward consumption?

梦想的初衷 提交于 2020-01-14 11:52:53
问题 Recently I've discovered the python module pyparsing , a wonderful tool for parsing data by writing the grammar , not the parser. I'm new to the idea of context-free grammars, so please correct any false assumptions in this question. Pyparsing can implement a BNF (Backus–Naur Form) context-free grammar. This grammar can be recursive, but can it have a forward look-ahead? I've been wondering about the answer to this since I stumbled across this question. Let me give you a concrete example.

Incremental but complete parsing with PyParsing?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-14 08:02:26
问题 I'm using PyParsing to parse some rather large text files with a C-like format (braces and semicolons and all that). PyParsing works just great, but it is slow and consumes a very large amount of memory due to the size of my files. Because of this, I wanted to try to implement an incremental parsing approach wherein I'd parse the top-level elements of the source file one-by-one. The scanString method of pyparsing seems like the obvious way to do this. However, I want to make sure that there

Pyparsing: get token location in results name

拈花ヽ惹草 提交于 2020-01-11 03:57:06
问题 I am working on a program that parses a command line with pyparsing. It uses the readline library to provide command edition and completion. In the context of the application, a valid command line is a path (optional), followed by a command name (optional) and some parameters (also optional). To offer command completion, the application parses the command line to see if the element to complete is a path, a command or a completion. Readline gives the indexes of the element that needs

How best to parse a simple grammar?

依然范特西╮ 提交于 2020-01-09 12:18:09
问题 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 catalog. The descriptions almost always follow a certain form, which makes me think I can parse most of them. From the text, I would like to generate a graph of course pre-requisite relationships. (That part will be easy, after I have parsed the data.)

How do I get PyParsing set up on the Google App Engine?

天涯浪子 提交于 2020-01-01 19:58:06
问题 I saw on the Google App Engine documentation that http://www.antlr.org/ Antlr3 is used as the parsing third party library. But from what I know Pyparsing seems to be the easier to use and I am only aiming to parse some simple syntax. Is there an alternative? Can I get pyparsing working on the App Engine? 回答1: "Just do it"!-) Get pyparsing.py, e.g. from here, and put it in your app engine app's directory; now you can just import pyparsing in your app code and use it. For example, tweak the

Parsing xdot draw attributes with pyparsing

你说的曾经没有我的故事 提交于 2020-01-01 19:07:14
问题 New to PyParsing. I'm trying to work out how to parse the draw (and similar) attributes in xdot files. There are a number of items where the number of following elements is given as an integer at the start - sort of similar to NetStrings. I've looked at some of the sample code to deal with netstring like constructs, but it does not seem to be working for me. Here are some samples: Polygon with 3 points (the 3 after the P indicates the number of points following): P 3 811 190 815 180 806 185

Need help on making the recursive parser using pyparsing

拥有回忆 提交于 2020-01-01 14:26:56
问题 I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser. Let me explain the problem I want to make the Cartesian product of the elements. The syntax is cross({elements },{element}) I put in more specific way cross({a},{c1}) or cross({a,b},{c1}) or cross({a,b,c,d},{c1}) or So the general form is first group will have n elements (a,b,c,d). The second group will have one element that so the final output will be Cartesian Product. The syntax is to be made

changing ** operator to power function using parsing?

北战南征 提交于 2019-12-31 03:23:28
问题 My requirement is to change ** operator to power function For example 1.Input -"B**2" Output - power(B,2) 2."B**2&&T**2*X" Output - power(B,2) I have wrote following regular expression to address that problem rx=r"([a-zA-Z0-9]+)\*\*([a-zA-Z0-9()]+)" result = regex.sub(rx, r"power(\1,\2)", expression, 0, regex.IGNORECASE | regex.MULTILINE) But above code successfully converting expression similar to the example 1 and example 2, but failed to convert expression like (a+1)**2 or ((a+b)*c)**2 . I