pyparsing

pyparsing syntax tree from named value list

pyparsing syntax tree from named value list Question: I’d like to parse tag/value descriptions using the delimiters :, and • E.g. the Input would be: Name:Test•Title: Test•Keywords: A,B,C the expected result should be the name value dict { "name": "Test", "title": "Title", "keywords: "A,B,C" } potentially already splitting the keywords in "A,B,C" to a list. …

Total answers: 3

Parsing only some lines with pyparsing

Parsing only some lines with pyparsing Question: I’m trying to parse a file, actually some portions of the file. The file contains information about hardwares in a server and each line starts with a keyword denoting the type of hardware. For example: pci24 u2480-L0 fcs1 g4045-L1 pci25 h6045-L0 en192 v7024-L3 pci26 h6045-L1 Above example doesnt …

Total answers: 2

Pyparsing Precedence breaks with Unary operator

Pyparsing Precedence breaks with Unary operator Question: I’m trying to implement a subset of Python’s operators for arithmetic parsing using pyparsing. I have the following code implementing my parser: variable_names = pyparsing.Combine(pyparsing.Literal(‘$’) + pyparsing.Word(pyparsing.alphanums + ‘_’)) integer = pyparsing.Word(pyparsing.nums) double = pyparsing.Combine(pyparsing.Word(pyparsing.nums) + ‘.’ + pyparsing.Word(pyparsing.nums)) parser = pyparsing.operatorPrecedence(variable_names | double | integer, [ (‘**’, …

Total answers: 2

Parse a colon separated string with pyparsing

Parse a colon separated string with pyparsing Question: This is the data: C:/data/my_file.txt.c:10:0x21:name1:name2:0x10:1:OK C:/data/my_file2.txt.c:110:0x1:name2:name5:0x12:1:NOT_OK ./data/my_file3.txt.c:110:0x1:name2:name5:0x12:10:OK And I would like to get this result [C:/data/my_file.txt.c, 10, 0x21, name1, name2, 0x10, 1, OK] [C:/data/my_file2.txt.c, 110, 0x1, name2, name5, 0x12, 1, NOT_OK] [./data/my_file3.txt.c, 110, 0x1, name2, name5, 0x12, 10, OK] I know how to do that with some …

Total answers: 3

Use pyparsing to parse expression starting with parenthesis

Use pyparsing to parse expression starting with parenthesis Question: I’m trying to develop a grammar which can parse expression starting with parenthesis and ending parenthesis. There can be any combination of characters inside the parenthesis. I’ve written the following code, following the Hello World program from pyparsing. from pyparsing import * select = Literal("select") predicate …

Total answers: 1

How can I do a non-greedy (backtracking) match with OneOrMore etc. in pyparsing?

How can I do a non-greedy (backtracking) match with OneOrMore etc. in pyparsing? Question: I am trying to parse a partially standardized street address into it’s components using pyparsing. I want to non-greedy match a street name that may be N tokens long. For example: 444 PARK GARDEN LN Should be parsed into: number: 444 …

Total answers: 1

what next after pyparsing?

what next after pyparsing? Question: 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 of the tips and tricks …

Total answers: 5

How best to parse a simple grammar?

How best to parse a simple grammar? Question: 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 …

Total answers: 6

Parsing SQL with Python

Parsing SQL with Python Question: 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 algebra expression. Then return …

Total answers: 6