pyparsing

Using PyParsing to parse language with signficant newlines (like Python)

孤街浪徒 提交于 2021-02-19 08:58:20
问题 I am implementing a language where the newlines are significant, sometime, as in Python, with exactly the same rules. For the purpose of my question we can take the Python fragment that has to do with assignments, parentheses, and the treatment of newlines and semicolons. For example, one could write: a = 1 + 2 + 3 # ok b = c but not a = 1 + 2 + 3 b = c # incorrect because one needs a newline to divide the two statements. However we can have a = 1 + 2 + 3; b = c # ok using the semicolon. Also

pyparsing parsing csv files with semi-colon instead of comma

♀尐吖头ヾ 提交于 2021-02-19 06:20:11
问题 In mainland europe, the csv files are separated through semicolons because numbers have , in them instead of . So, i am trying to write a semicolonSeparatedList same as commaSeparatedList but with ; instead of ,: _semicolonsepitem = Combine(OneOrMore(Word(printables, excludeChars=';') + Optional( Word(" \t") + ~Literal(";") + ~LineEnd() ) ) ).streamline().setName("semicolonItem") semicolonSeparatedList = delimitedList( Optional( quotedString.copy() | _semicolonsepitem, default="") ).setName(

PyParsing Parse nested loop with brace and specific header

淺唱寂寞╮ 提交于 2021-02-19 05:49:07
问题 I found several topics about pyparsing. They are dealing with almost the same problem in parsing nested loop, but even with that, i can't find a solution to my errors. I have the following format : key value; header_name "optional_metadata" { key value; sub_header_name { key value; }; }; key value; Key is alphanum Value may be type of Int, String, with alphanum + "@._" key/value may be after a brace block key/value may be in the file before the first brace block key/value before or after a

How to treat prefixed keywords?

别来无恙 提交于 2021-01-28 17:57:10
问题 I have following parsing problem. My keywords can be prefixed with an underscore for deactivation of the option, block etc. #coding: utf8 from pyparsing import Keyword, Combine, pyparsing_common, Literal, Suppress, Group, OneOrMore test_string = r''' keyword1list { keyword1 { option 213 } _keyword1 { option 214 } } ''' This can happen to any keyword, here keyword1list , keyword1 or option . What I like to achieve is to either leave those blocks out during parsing or parse them but catch the

How to treat prefixed keywords?

爱⌒轻易说出口 提交于 2021-01-28 17:53:52
问题 I have following parsing problem. My keywords can be prefixed with an underscore for deactivation of the option, block etc. #coding: utf8 from pyparsing import Keyword, Combine, pyparsing_common, Literal, Suppress, Group, OneOrMore test_string = r''' keyword1list { keyword1 { option 213 } _keyword1 { option 214 } } ''' This can happen to any keyword, here keyword1list , keyword1 or option . What I like to achieve is to either leave those blocks out during parsing or parse them but catch the

Parse a list of expressions using pyparsing

喜夏-厌秋 提交于 2021-01-27 21:18:00
问题 I'm trying to use pyparsing to parse simple basic program: import pyparsing as pp pp.ParserElement.setDefaultWhitespaceChars(" \t") EOL = pp.LineEnd().suppress() # Identifiers is a string + optional $ identifier = pp.Combine(pp.Word(pp.alphas) + pp.Optional("$")) # Literals (number or double quoted string) literal = pp.pyparsing_common.number | pp.dblQuotedString line_number = pp.pyparsing_common.integer function = pp.Forward() operand = function | identifier | literal expression = pp

Edit RTF file using Python

二次信任 提交于 2021-01-27 13:19:12
问题 Maybe this is a dumb question, but I don't get it so appologize :) I have an RTF document, and I want to change it. E.g. there is a table, I want to duplicate a row and change the text in the second row in my code in an object-oriented way. I think pyparsing should be the way to go, but I'm fiddling around for hours and don't get it. I'm providing no example code because it's all nonsense I think :/ Am I on the right path or is there a better approach? Anyone did something like that before?