pyparsing

Restructuring pyparsing parse results of multithreaded log file

空扰寡人 提交于 2019-12-11 11:23:43
问题 I have a log file of a multithreaded process which looks like this: <timestamp_in> <first_function_call_input> <thread:1> input_parameter_1: value input_parameter_2: value <timestamp_in> <another_function_call_input> <thread:2> input_parameters: values <timestamp_out> <another_function_call_output> <thread:2> output_parameters: values <timestamp_out> <first_function_call_output> <thread:1> output_parameters: values In my parse results variable I would like to have the input and output

pyparsing: skip to the next token ignoring everything in between

醉酒当歌 提交于 2019-12-11 07:25:50
问题 I am trying to parse a log file that contains multiple entries with the following format: ITEM_BEGIN item_name some_text some_text may optionally contain an expression matched by my_expr anywhere within itself. I am only interested in item_name and my_expr (or None if it is missing). Ideally, what I want is a list of (item_name, my_expr) pairs. What is the best way to extract this information using pyparsing? 回答1: If you are not trying to define a parser for the entire input text, but only

add own text inside nested braces + exception

混江龙づ霸主 提交于 2019-12-11 07:06:59
问题 Original question locates here, current question is desire to avoid one problem. I have this code which works perfect with html_1 data: from pyparsing import nestedExpr, originalTextFor html_1 = ''' <html> <head> <title><?php echo "title here"; ?></title> <head> <body> <h1 <?php echo "class='big'" ?>>foo</h1> </body> </html> ''' html_2 = ''' <html> <head> <title><?php echo "title here"; ?></title> <head> <body> <h1 <?php echo $tpl->showStyle(); ?>>foo</h1> </body> </html> ''' nested_angle

Get token position in string with pyparsing, using named values

蹲街弑〆低调 提交于 2019-12-11 06:26:38
问题 I'm trying to get the token position in the string when using pyparsing. I want to report the location of an include guard issue in C files: import pyparsing as pp m = None n = None #a sample C header file lines = "\ #ifndef HEADER_FILE_H\n\ #define HEADER_FILE_H 1\n\ \n\ \n\ /* code is here */\n\ \n\ #endif /* HEADER_FILE_H */\ " LBRACE,RBRACE,LBRACK,RBRACK,LT,GT,LPAREN,RPAREN,DQ,SEMI = map(pp.Suppress,'{}[]<>()";') CIDENT = pp.Word(pp.alphanums + "_") #any C identifier LCOMMENT = pp

How to use pyparsing Group with SkipTo for a file parsing?

折月煮酒 提交于 2019-12-11 06:14:19
问题 When I used pyparsing SkipTo together with other parser, the file parsing seems hang. unexpected = pp.SkipTo(pp.LineEnd())('unexpected*') rules = pp.Group(predefined_parser) | unexpected parser = pp.Dict(pp.OneOrMore(rules) parser.ignore('*' + pp.restOfLine) parser.parseFile(filename, True) I turned on setDebug, here's the debug message. Any insights is highly appreciated. Match Dict:([{Group:({Combine:({"something" W:(_) Combine:({W:(ABCD...) [W:(0123...)]}) W:(_) {"sth1" | "sth2"}})

add own text inside nested braces

好久不见. 提交于 2019-12-11 05:28:51
问题 I have this source of text which contains HTML tags and PHP code at the same time: <html> <head> <title><?php echo "title here"; ?></title> <head> <body> <h1 <?php echo "class='big'" ?>>foo</h1> </body> </html> and I need place my own text (for example: MY_TEXT) after opened tag and get this result: <html> <head> <title><?php echo "title here"; ?></title> <head> <body> <h1 <?php echo "class='big'" ?>>MY_TEXTfoo</h1> </body> </html> thus I need consider nested braces if I will use regex it

To get the join columns from a SQL (query) using PYparsing, python script

核能气质少年 提交于 2019-12-11 04:43:14
问题 I want to parse a Teradata ANSI sql and get the join columns and tables used in the query. For example below is the query select * from TABLEA A INNER JOIN TABLEB b ON A.COL1 =B.COL2 INNER JOIN TABLEc C ON A.COL1 =C.COL3 I want to get the result like below Tables :tableA ,tableb, tablec columns = a.col1,b.col2,c.col3 I already have the code to get all the tablenames from a SQL. Iam using the below script from Paul to parse the tablename I want to modify the below script to get the join column

pyparsing how to pass identifiers to the parser

巧了我就是萌 提交于 2019-12-11 04:33:37
问题 I am trying to pass a list of valids identifiers to the parser. That is to say: I have a list with the identifiers and the parser should use them, I'm passing them as a parameter into the constructor. Instead of identifiers = Literal('identifier1') | Literal('identifier2') | Literal('identifier whatever') I have an array of identifiers identifiers = ['identifier1', 'identifier2', 'identifier whatever', ... 'identifier I can not what'] that I need to tell pyparsing to use as identifiers. This

python regex in pyparsing

孤者浪人 提交于 2019-12-11 03:56:08
问题 How do you make the below regex be used in pyparsing? It should return a list of tokens given the regex. Any help would be greatly appreciated! Thank you! python regex example in the shell: >>> re.split("(\w+)(lab)(\d+)", "abclab1", 3) >>> ['', 'abc', 'lab', '1', ''] I tried this in pyparsing, but I can't seem to figure out how to get it right because the first match is being greedy, i.e the first token will be 'abclab' instead of two tokens 'abc' and 'lab' . pyparsing example (high level, i

Stack Overflow when Pyparsing Ada 2005 Scoped Identifiers using Reference Manual Grammar

依然范特西╮ 提交于 2019-12-11 02:37:20
问题 I'm currently implementing an Ada 2005 parser using Pyparsing and the reference manual grammar rules. We need this in order to analyze and transform parts of our aging Ada-codebase to C/C++. Most things work. However, one little annoying problem remains: The grammar rule name when parsing scoped identifiers (rule selected_component ) such as the expression "Global_Types.Integer2" fails because it is part of a left-associative grammar rule cycle. I believe this rule is incorrectly written: the