1,019 questions
1
vote
1
answer
87
views
Combining similar alternative grammar definitions
I am attempting to scan specific names from a CDL file (a variant of SPICE) which is a line oriented syntax. Superficially, regex would work, but is in fact more complex given the full language ...
4
votes
3
answers
81
views
pyparsing for syllables is too greedy
I'm trying to parse syllables with pyparsing. I'm working with a language that has a CV(C) syllable template, so every syllable starts with a consonant. However, my parser is "eating" the ...
1
vote
0
answers
73
views
Pyparsing ParseResults attributes type hinting
I'm using Pyparsing and I'm getting a reportArgumentType error from Pyparse:
from dataclasses import dataclass
import pyparsing as pp
@dataclass
class Foo:
value: int
def parse_foo(line: str) -&...
1
vote
1
answer
27
views
pyparsing LineStart not matching on indented line
I couldn't find this anywhere. I'm using pyparsing on a project right now and I need to match keywords at the start of the line. I looked at the LineStart for this which is close but not quite the ...
1
vote
1
answer
142
views
How do I parse ambiguous indented blocks like this using pyparsing?
I'm trying to parse data in the following format:
data = """\
map=1
sub=1
int=99
foo=bar
sub=2
foo=bar
int=99
bar=qux
"""
I based my grammar on ...
1
vote
1
answer
39
views
simple-mockforce dependency conflict on pyparsing<3.0.0
I’m working on a Python project that utilizes moto[all] version 5.0.0 or higher for mocking AWS services in pytest test cases. Additionally, the project depends on simple-salesforce and simple-...
1
vote
1
answer
58
views
How to a match any sequence of text until "#{" in pyparsing
I want to do string templating with py parsing.
I have failed multiple times to define a grammar that can parse a string with inserted text inbetween "#{" and "}" (seems pretty ...
2
votes
1
answer
57
views
Why is pyparsing removing whitespace?
I am using pyparsing to parse sass files. I need to get the sass files into a particular format to work with them, and preserving whitespace is very important.
import pyparsing as pp
pp.ParserElement....
2
votes
1
answer
126
views
Using pyparsing for parsing filter expressions
I'm currently trying to write a parser (using pyparsing) that can parse strings that can then be applied to a (pandas) dataframe to filter data. I've already got it working after much trial & ...
1
vote
1
answer
66
views
Infinite recursion in pyparsing grammar for method signatures
Below is my pyparsing grammar for parsing the method signature of a Solidity function, and an example signature to parse:
from pyparsing import Word, alphas, alphanums, oneOf, Group, Forward, ...
1
vote
1
answer
103
views
Using pyparsing to parse infix expression [closed]
I am learning Paul McGuire's fabulous pyparsing Python module. I'm posting this for discussion and hopefully to get a deeper insight into pyparsing.
The following code parses a parenthetical ...
2
votes
2
answers
763
views
pyparsing - back to basics
In attempting to put together a very simple example to illustrate an issue I'm having with pyparsing, I have found that I can't get my simple example to work - this example is barely more complex than ...
1
vote
1
answer
116
views
Why are pyparsing's `DelimitedList` and `Dict` so awkward to use together?
Pyparsing offers the ParseElementEnhance subclass DelimitedList for parsing (typically comma-separated) lists:
>>> kv_element = pp.Word(pp.alphanums)
>>> kv_list = pp.DelimitedList(...
1
vote
1
answer
80
views
Unable to strip whitespace from a string using pyparsing set_parse_action()
I've got a generic "text block" element, for which I copied the whitespace-stripping code from the documentation:
import pyparsing as pp
text_block = pp.Group(
pp.OneOrMore(
pp....
1
vote
1
answer
55
views
How to make sure element has parsing precedence before other elements in pyparsing?
I have a simple markup grammar that can have matched and standalone tags:
{tag}Tagged content{/tag} plain text {standalone}{tag}Tagged again!{/tag}
I wrote the following pyparsing grammar:
import ...
1
vote
1
answer
63
views
Railroad diagrams in Pyparsing: How about Forward() declarations? Rule renaming?
I'm using pyparsing 3.0.9, python 3.9.16, and I'm trying to write a grammar for a (sub-)set of YAML. Not so much for the produced parser, as for the railroad diagrams. The actual state of the program ...
1
vote
2
answers
72
views
pyparsing transform_string with negative lookahead
I'm trying to implement simple shell-style string variable interpolation with $varname syntax, using pyparsing. For example, if I have a variable foo with value "bar", then transform "...
1
vote
1
answer
70
views
Make (a quite simple) pyparsing based parser fault tolerant
I wrote a little parser using pyparsing to parse Google-like search strings, like foo AND (bar OR baz) (full code below). Like Google, I would like to make the parser fully fault-tolerant. It should ...
1
vote
1
answer
46
views
How to parse an optional operator with pyparsing library?
I want to parse strings like alpha OR beta gamma where a missing operator (in this case between beta and gamma a implicit AND is used.
Here is the code I tried:
import pyparsing as pp
class Term:
...
2
votes
1
answer
77
views
How to get pyparsing to match "1 day" or "2 days" but fail "1 days" and "2 day"?
I'm trying to match a sentence fragment of the form "after 3 days" or "after 1 month". I want to be particular with the single and plural forms, so "1 day" is valid but &...
1
vote
1
answer
88
views
Why parser return ParseException with wrong message?
I'm working on implementing a parser that is supposed to process the input string, extracting its components, validating them, and then creating a SQL Alchemy query from it. At the moment, I'm working ...
1
vote
0
answers
61
views
Generate output from PyParsing tree
Ive created a very large PyParsing tree from reading ISB Bind9 named.conf file.
Now I wish to redirect my attention to generating an output back to the way it was syntactically read and created from.
...
1
vote
0
answers
43
views
Recursive IndentedBlock with optional contents
IndentedBlock from pyparsing not dedenting
I am trying to write a parser in pyparsing that has a container that has optional contents, and I'm not getting the results I'm expecting.
Here's the ...
1
vote
1
answer
59
views
Pyparsing SQL Selects: Unable to extract complex UNIONS as a Dict
I am trying to parse and read the components of a complex select statement based on the select_parser.py example, but I cannot seem to make it work for a select statement with a UNION.
My sample ...
1
vote
0
answers
112
views
AttributeError: module 'pyparsing' has no attribute 'downcaseTokens' when importing tensorflow
I'm getting the follow dependency error when attempting to import tensorflow on a jupyter notebook:
AttributeError: module 'pyparsing' has no attribute 'downcaseTokens'
The full error message is:
...
1
vote
0
answers
35
views
Difference in parsing behavior between runTests and parseString?
I observe a difference in the results between runTests as a string and when reading from a file .
This is the code that I have
import pyparsing as pp
import sys
from pathlib import Path
# Largely ...
1
vote
1
answer
94
views
PyParsing throws Exception in one string while not in another case
2.2.1
I am a newcomer to PyParsing. I use Python 3.12 on Ubuntu 20.04 and installed PyParsing using pip install
I have 2 different outcomes (an exception from 1 ) and no exception from from 2 ...
1
vote
1
answer
117
views
Output as a specific Dict and a List of Dict
I'm trying to parse some commands-like string/file content into a Dict output and I learned about pyparsing.
So let's say I have the following input:
str = "p1 start a, {alias = b, for : 30}; c, ...
0
votes
1
answer
51
views
How to specify a pyparsing expression that has two parts, the length of each may varies but their sum is fixed?
I need to specify an expression that is defined as ambn, such that:
m + n = t; t is fixed
0 <= m <= t - 1
1 <= n <= t
Here's how the current code looks like, simplified:
from pyparsing ...
0
votes
1
answer
92
views
How to get a dynamic number (n) of inputs from a string, where n is the first word?
I have a string which looks like the following.
"""
1: a
2: a, b
3: a, b, c
"""
I would like to use pyparsing to define a grammar which is dynamic and picks up the ...
2
votes
0
answers
58
views
Why might PyParsing's output railroad diagram be covered up with black shapes?
I am learning PyParsing and just tried to run the example Python file for creating Railroad diagrams but the output looks wrong. Basically, I downloaded the code from https://github.com/pyparsing/...
1
vote
1
answer
79
views
pyparsing produces different results for asDict() and asList()
I have no ideas why pyparsing produces different results for asDict() and asList(). Please push me in the right direction.
import pyparsing as pp
WALRUS = pp.Keyword(':=').suppress()
number = pp....
1
vote
1
answer
78
views
How to know which pyparsing ParserElement created which ParseResults?
The problem
I have a bunch of Group-ed expressions like these, all of which contribute to the same grammar:
first_and_operator = Group(Char('ab')('first') + Char('+-')('operator'))
full_expression = ...
1
vote
0
answers
90
views
Pyparsing returns ParseException: , found '-'
I'm trying to parse a relatively simple expression with pyparsing, but I'm getting an error that I don't understand.
Here's the parser setup. I can parse user and feature separately, but combining ...
1
vote
1
answer
63
views
Constructing large character ranges with pyparsing.srange is extremely slow
I have some of these constructions in my code:
from pyparsing import Char, srange
_non_ascii = Char(srange('[\x80-\U0010FFFF]'))
The generation of the ranges is extremely slow, taking 6-8 seconds (...
-1
votes
1
answer
239
views
pyparsing how to express functions inside an infixNotation
I'm building a recursive grammar using pyparsing, to express a series of possible operations, but I've hit an issue with how to express functions. I wish to describe an operator that has a name, ...
1
vote
0
answers
29
views
Pyparsing grammar incorrect
Why does the following pyparsing grammar not parse the string correctly?
import pyparsing as pp
token_any = pp.Word(pp.printables)
comment = pp.Literal("*") + token_any("comment text&...
1
vote
1
answer
74
views
Parsing several multi-line blocks with pyparsing
I'm a complete pyparsing newbie, and am trying to parse a large file with multi-line blocks describing archive files and their contents.
I'm currently at the stage where I'm able to parse a single ...
1
vote
2
answers
64
views
Recursive pyparsing of function invocation expression with args and kwargs
I am trying to create a parser using pyparsing that parses an expression of below formats:
FUNC_NAME(ARG1, ARG2, ..., ARGN, K1=V1, K2=V2, ..., KN=VN)
ARGs and KWARG values can be literals (quoted ...
1
vote
1
answer
176
views
PyParsing: Conditional parsing, depending on value
I need to parse Touchstone files (version 1.1, and version 2.0), but these have a strange rule in the syntax (see page 11 in the 1.1 spec, the top paragraph starting with Note.
So, I need to change ...
1
vote
1
answer
79
views
How do I represent an optional component in a grammar with pyparser?
I am developing a parser that extracts the dose and name from expressions of medication dosages. For example, pulling "10 mg" and "aspirin" from "10mg of aspirin" and &...
3
votes
1
answer
918
views
How do I remove comments from an Oracle SQL script using pyparsing in Python 3.x?
I have an oracle sql script containing multiple statements which are separated by ";". I'm trying to remove all comments within this entire script. This includes:
single line comments -- ...
1
vote
1
answer
117
views
Can I overwrite operator_rules of infix_notation and keep pyparsing code dry when using forward-defined elements?
In shortened and simplified pseudocode I have something like this:
arg = Forward()
...
...
func_call = somestuff + arg
term = ... | ... | arg
expression = infix_notation(term, operator_rules)
...
......
1
vote
1
answer
148
views
Is there an easy way to add custom error messages in pyparsing?
Suppose we have a grammar where there is an element that was expected but is not found. Assume that the backtracking is disabled, i.e. the element is preceded by a - sign.
Is there any way in the ...
1
vote
1
answer
967
views
How to resolve AttributeError: 'version_info' object has no attribute '__version__'
C:\Coursera\CarlaSimulator\PythonClient\Course1FinalProject>python module_7.py
Traceback (most recent call last):
File "module_7.py", line 26, in <module>
import matplotlib....
2
votes
2
answers
175
views
pyparsing: NotAny(FollowedBy()) failing
i have some input data like
[gog1] [G1] [gog2] [gog3] [gog4] [G2] [gog5] [G3] [gog6]
and want to find all gogs, if not G after it. so in this case i want to get gog2 and gog3 (and maybe gog6).
looks ...
1
vote
0
answers
53
views
How to construct a column name when an aggregate function is used on a column using pyparsing library in Python?
I am trying parse a SQL query using Python's pyparsing library.
As part of that, I implemented the below code:
from pyparsing import *
ParserElement.enablePackrat()
select_stmt = Forward().setName(&...
1
vote
1
answer
49
views
pyparsing fails to find a complete parse in presence of an ambiguous grammar?
I am trying to apply pyparsing to solve the Advent of Code 2015 Day 19 puzzle.
The simplest example shows an ambiguous grammar e => H; e => O; H => HO; H => OH; O => HH and seeks the ...
3
votes
2
answers
236
views
Pyparsing: how to match parentheses around comma_separated_list
I cannot figure out how to combine expressions with the comma_separated_list in order to match a list in parentheses. The following does not work, because the csv expression eats up the last ...
1
vote
1
answer
92
views
Python Pyparsing Located vs locatedExpr
I am changing a few pyparsing patterns from pyparsing version 2 to pyparsing version 3.
The contents of the sample file I use for parsing
this is a sample page to test parsing
line 0001 line 1
line ...