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
0
votes
2 answers

Implement heredocs with trim indent using PEG.js

I working on a language similar to ruby called gaiman and I'm using PEG.js to generate the parser. Do you know if there is a way to implement heredocs with proper indentation? xxx = <<
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
0 answers

Converting pegjs to C++

I have used pegjs to create a parser, quite similar actually to the example shown here for a custom string-formatting function. I would like to port this to C++. What might be the best way to do this? Are there are existing parsers in C/C++ that are…
David542
  • 104,438
  • 178
  • 489
  • 842
0
votes
0 answers

Use lexer or parser generator to generate bash autocompletions for a text parameter?

I'd like to customize auto-completion in bash (such as is described at https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Programmable-Completion) such that a parameter can use auto-completion, where the parameter is an expression that…
mwag
  • 3,557
  • 31
  • 38
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

Why does this Python parser using parsimonious never find the ifdef blocks

This is a simplified version of a larger parser. I has been driving me slightly mad as I can't seem to get it to work consistently. The larger version works but has so many edge cases it does not work well enough, I'm finding myself having to teach…
Jay M
  • 3,736
  • 1
  • 24
  • 33
0
votes
1 answer

How can i make a backslash for change line with peg.js?

Currently, I use '\n' to split each line (paragraph), but now, I want to make a backslash like python for change line. This is my current rule: Start = _ head:Line tail:('\n'+ l:Line { return l })* _ { return [head].concat(tail) …
MoeCasts
  • 33
  • 5
0
votes
1 answer

Parsing and validating conditional IF in PEG parser

Trying to parse a single line conditional where code tries to test the left hand is equal to the right hand. { user = {id: 'abc123'} function_name() {...} } if (user.id === 'abc123...') { function_name() } I've so far looked at these posts…
Chris
  • 514
  • 6
  • 22
0
votes
1 answer

PEGjs grammar star (*) not matching as expected

I have this lexeme: a().length() And this PEGjs grammar: start = func_call func_call = header "(" ")" header = "a" suffix* suffix = "(" ")" ("." "length") In the grammar, I'm parsing a function call. This currently parses, as you can try online…
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
0
votes
0 answers

Why is there a difference in error messages for SyntaxErrors in Python 3.9 compared to previous Python versions?

Missing commas while writing lists is a pretty common source of errors (for me at least). In Python 3.8 and lower, missing a comma in a list passed to a function as a keyword argument generates a sensible error that clearly points out the error's…
krm
  • 847
  • 8
  • 13
0
votes
1 answer

Parsing a table using preferably grammar or regex

few days i am stuck; i would like to parse a big document with many page amongts things it has tables like this one : Col1 Col2 Col3 Col4 TXT1 TTT Fnam1, LNam1 TXT2 TEE Fnam2,…
ibstelix
  • 103
  • 7
0
votes
1 answer

How to write a PEG parser that fully consumes any and all text whilst still matching other given rules?

I'm making an application to make writing (PEG) parsers more approachable and user friendly for people without experience. Yes it has been done before but it's a good learning experience for me regarding GUIs. Part of what makes it approachable…
Shefeto
  • 178
  • 1
  • 10
0
votes
1 answer

Peg.JS: Simple if..then..else implementation

I am trying to implement a grammar for a simple if..then..else statement along with simple statements. It should be able to parse a statement like: if things are going fine then things are supposed to be this way just go with it else …
funkycoder
  • 525
  • 4
  • 17
0
votes
1 answer

Difficulty writing PEG recursive expression grammar with Arpeggio

My input text might have a simple statement like this: aircraft In my language I call this a name which represents a set of instances with various properties. It yields an instance_set of all aircraft instances in this example. I can apply a filter…
Leon Starr
  • 480
  • 1
  • 4
  • 10
0
votes
1 answer

NodeJS Parser with VueJS

I have a task - parsing data of this type ("Query1" OR "Query2") AND ("Quesy3" OR "Query4") I am using TsPeg for this. Everything worked out, but how can you use the parse() method of library inside a Vue project? Simply put, I need to pull out a…
Harvey
  • 172
  • 1
  • 7
0
votes
1 answer

How to fix GCC type warning on variable returned by the parser generator?

I expect Packcc parser generator "$0s" or "$0e" variables to throw an int in the parser actions, because theses variables represents a position in the input. I made a minimal parser that prints the position of the last char of the word. word <-…
Ploumploum
  • 311
  • 1
  • 9