Questions tagged [peg]

A “Parsing Expression Grammar” (“PEG”) is a formal language to describe formal languages.

A Parsing Expression Grammar (“PEG”) is a formal language that defines a set of rules to describe a certain class of formal languages similar to context-free grammars.

In comparison to context-free grammars, PEGs have the advantage of always being unambiguous, and of mapping naturally to recursive descent parsers, which makes them easy to implement.

288 questions
3
votes
1 answer

What is the purpose of bitwise_or in Python PEG?

What does bitwise_or mean in PEG grammar? More accurately, there are lots of bitwise_or in contexts where it's not even parsing for | yet there are occurrences. Does bitwise_or serve any other purpose in PEG other than being the | in Python? Example…
Shreyan Avigyan
  • 183
  • 1
  • 11
3
votes
1 answer

Using Pest.rs, how can I specify that comments are to be anchored and whole line?

Exim uses a really awkward comment syntax, Blank lines in the file, and lines starting with a # character (ignoring leading white space) are treated as comments and are ignored. Note: A # character other than at the beginning of a line is not…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
3
votes
1 answer

Using Pest.rs, is there a way to store comments as tokens?

Pest.rs gives us a method of doing comments, COMMENT - runs between rules and sub-rules But if we're building a linter we may want the comments. Is there a way to have them saved on the tree?
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
3
votes
1 answer

Is this description of alternatives in regexes wrong?

The wikipedia article on PEG states: The fundamental difference between context-free grammars and parsing expression grammars is that the PEG's choice operator is ordered. If the first alternative succeeds, the second alternative is…
Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64
3
votes
1 answer

Need confirmation about PEG's semantic predicates in pyparsing

The PEG paper describes two semantic predicate parsing expressions: And predicate &e Not predicate !e Does pyparsing support the And predicate ? Or is that just a synonym for the sequencing parsing expression ? In that case it should be equivalent…
Frankie Ribery
  • 11,933
  • 14
  • 50
  • 64
3
votes
1 answer

Handle correcly state with pegtl grammar

I'm very new to peg and pegtl, so probably I'm missing something. I have a grammar very similar to the following one: using namespace tao::pegtl; struct A : one<'A'> { }; struct B : one<'B'> { }; struct comp : seq, A>>,eof> {…
alangab
  • 849
  • 5
  • 20
3
votes
1 answer

Parse multiline text using the Parsimonious Python library

I am trying to parse multiline text with the python parsimonious library. I've been playing with it for a while and can't figure out how to deal effectively with newlines. One example is below. The behavior below makes sense. I saw this comment from…
Mark
  • 309
  • 1
  • 9
3
votes
1 answer

How to parse alternatives in parsimonious that start with same characters

I'm using parsimonious to do some parsing and I'm having trouble figuring out how to properly parse alternatives that share the first character in an unordered away: For example: Text: 2 > 3 2 >= 3 Grammar: expr = ~"[0-9]+" space operator space…
therealtypon
  • 455
  • 2
  • 5
  • 12
3
votes
2 answers

PEG recursive grammar

I'm trying to write a Tiger parser. I initially used PyPEG, but due to some difficulties, I went with Arpeggio. My grammar is really simple. def number(): return _(r'[0-9]+') def string(): return _(r"\".*?\"") def id(): return…
kino
  • 43
  • 4
3
votes
2 answers

Example of how to use PEG.js

I'm playing around with PEG.js. I created some simple code that accepts inputs in the form [LettersNumbers]: abc123 hello98765 etc. This is the code: start = expression expression = text + number text = a: [a-z]+ {return a.join("");} number =…
Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
3
votes
1 answer

Parboiled2 grammar for parsing escaped CSV line

I am trying to parse a single line which contains strings separated by delimiters into a sequence of these strings. It should be able to have any character in the strings, if a field contains a delimiter it needs double quotes around it. In order to…
dreamflasher
  • 1,387
  • 15
  • 22
3
votes
1 answer

Access Control String (ACS) Parser/Interpreter with PEG.js

Preface I'm working on creating a Access Control String (or System) (ACS) string Parser/Interpreter with PEG.js. ACS strings are commonly used on Bulletin Board Systems (BBSs) to check access rights to particular areas of the board. For example, see…
NuSkooler
  • 5,391
  • 1
  • 34
  • 58
3
votes
2 answers

Rule precedence issue with grako

I'm redoing a minilanguage I originally built on Perl (see Chessa# on github), but I'm running into a number of issues when I go to apply semantics. Here is the grammar: (* integers *) DEC = /([1-9][0-9]*|0+)/; int =…
Aerdan
  • 143
  • 7
3
votes
2 answers

Intellisense from PEG (Parsing expression grammar)

I apologise in advance if this has already been asked. I have a language, defined by a grammar, and I'd to know how people go about implementing Intellisense for their custom grammars. This seems mechanical to me; the user types something that is…
Mohamed Bana
  • 1,251
  • 2
  • 17
  • 27
3
votes
1 answer

Re-write Parsing Expression Grammar (PEG) without left recursion

Using https://github.com/JetBrains/Grammar-Kit how to rewrite grammar without left recursion? grammar ::= exprs exprs::= (sum_expr (';')?)* private sum_expr::= sum_expr_infix | sum_expr_prefix sum_expr_infix ::= number sum_expr_prefix left…
okigan
  • 1,559
  • 2
  • 18
  • 33