Questions tagged [pypeg]

pyPEG is a plain and simple intrinsic parser interpreter framework for Python version 2.7 and 3.x. It is based on Parsing Expression Grammar, PEG.

https://fdik.org/pyPEG

11 questions
5
votes
1 answer

pyPEG2 parsing of newlines

I'm trying to use pyPEG2 to translate MoinMoin markup to Markdown, and I need to pay attention to newlines in certain cases. However, I can't even get my newline parsing tests to work. I'm new to pyPEG and my Python is rusty. Please bear with…
3
votes
1 answer

Using a dollar sign in enum (pypeg)?

I want to match types of the form either $f, $c, ..., $d using pypeg, so I tried putting it in an Enum as follows: class StatementType(Keyword): grammar = Enum( K("$f"), K("$c"), K("$v"), K("$e"), …
Dair
  • 15,910
  • 9
  • 62
  • 107
2
votes
1 answer

add a macro call at start of every function definition in c++ source file

I would like to add a single line of code at the beginning of each function in my c++ visual studio 2015 project. It would take months to manually add a line into each function. Are there any quick way or tool to solve this problem ? function…
usmanharoon
  • 173
  • 2
  • 13
2
votes
1 answer

pyPEG - data identified by a `flag()` function are returned incorrectly by `compose()` function

I'm in a situation where I need to parse a legacy format. What I want to do is to write a parser that recognizes the format and transform it to an object which is easier to work with. I managed to parse the input, the problem is when I want to…
Jan Vorcak
  • 19,261
  • 14
  • 54
  • 90
1
vote
1 answer

pyPEG2 giving wrong result

I have created grammar with pyPEG2 for parsing such statements as: A loves B but B hates A, A hates B and A loves D while B loves C Here is my code below: import pypeg2 as pp class Person(str): grammar = pp.word class Action(pp.Keyword): …
Michael
  • 1,170
  • 2
  • 14
  • 35
1
vote
1 answer

How to match unordered things in pyPEG?

I have the following file: orange apple orange apple apple lime banana Each type of fruit has a class to match it: class Banana: grammar = .... class Apple: ... I have to match each fruit unordered, I cannot tell upfront what will be the…
Felipe Lavratti
  • 2,887
  • 16
  • 34
1
vote
1 answer

pypeg cannot compose grammar with list?

class A(List): grammar = [(Symbol, ':', Symbol), Symbol] compose(parse('a', A)) This raises a compose error while parsing is fine. I can only bypass it by using a dummy class: class B(List): grammar = Symbol, ':', Symbol class A2(List): …
colinfang
  • 20,909
  • 19
  • 90
  • 173
0
votes
0 answers

Solving left recursion in packrat parser

I am looking at parsing arithmetic expression like (2 + (a + b ) ) + (3 + 2 ) * 2 using pypeg2. How to write grammar for this? The intension is to implement bin_expr ::= optional('('), var_or_const, Binary_operator, var_or_const, optional(')') |…
Mangesh T
  • 15
  • 4
0
votes
1 answer

How to handle all possible C like block comment styles in PyPEG

After giving up on parsimonous I tried PyPEG. I've had much more success in that I've achieved my initial goal, but can't seem to handle comments properly. I've distilled the issue into the following code. You can see that not all the test cases…
Jay M
  • 3,736
  • 1
  • 24
  • 33
0
votes
1 answer

Unable to parse function declaration with Python like syntax

I am using pyPEG to parse the declaration of a function. Currently I have this written: from pypeg2 import attr, \ optional, \ csl, \ name, \ List, \ …
Dair
  • 15,910
  • 9
  • 62
  • 107
-2
votes
1 answer

Replace function in pyPEG

How can i replace some words in pyPEG? For example i have sentence John plays football I want replace John to Bob and compose it to: Bob plays footbal. from pypeg2 import * class Try(str): grammar = 'John ', restline # I am think that…
gongarek
  • 984
  • 1
  • 8
  • 19