Questions tagged [pegjs]

PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. Forked to a now-maintained version called Peggy.

PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting.

See https://pegjs.org/

The project was forked to create Peggy, which is now maintained at:

https://peggyjs.org/

123 questions
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
1 answer

Parse expression with JavaScript using PEG

I have written the code to parse the following expression !=10 AND <=99 To { operator: 'AND', values: [ { op: '!=', value: '10', }, { op: '<=', value: '99', }, …
Benk I
  • 185
  • 13
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
1 answer

pegjs: How to handle character class preceded by more general class

I have identifiers that may contain dots but not as the last character. For example, I would like to parse "date.ymd" as identifier but "execute." as (identifier + punctuation character). A regexp would be…
0
votes
1 answer

Terminating list of expressions in PEG.js

I have another question related to How to extend default PEG.js arithmetic example to allow multiple expressions not single one? I have this grammar: start = code:statements { return { "type": "Program", "body": code }; …
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
1 answer

How to extend default PEG.js arithmetic example to allow multiple expressions not single one?

As part of my parser I want to add arithmetic and boolean expressions. I wanted to take default PEG.js example at https://pegjs.org/online but the problem is that that parser is recursive and you can't write two or more lines: For instance this is…
jcubic
  • 61,973
  • 54
  • 229
  • 402
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
0 answers

PEG js : How to match string within a single quote in peg js grammer rule expression?

I am writing a peg js grammar to parse logical query literals into a json format but facing an issue with selecting a multi value word in a condition value. Like (city = 'a' OR city = 'b') works properly but (city = 'a b' OR city = 'b') is not…
Harshad Sindhav
  • 171
  • 2
  • 7
0
votes
1 answer

Is it possible to create a simple parser and create a javascript file and then call that file with that parser?

I am trying to create a parser, a file. I am trying to use this file created to be parsed by the parser. The steps are: Add pegjs with Create an parser with var parserFile Create file with var makeFile Add contentFile, nameFile with var…
user12169855
0
votes
1 answer

Use PEG.js generated parser to beautify code

I want to create a formatter/linter for a custom program language and was reading about it but seems that im missing something. Was looking/playing with PEG.js and seems that it will do the work. Ive wrote a small parser and when ran - it correctly…
Stefan Stoichev
  • 4,615
  • 3
  • 31
  • 51
0
votes
1 answer

parser unable to match the consequent rule due to error evaluating a former rule

Example: start = name / invocation; name = [a-zA-Z]+ { return text() }; invocation = a:name "()" { return {type: 'inv', value: a } }; If input is abc() I am getting error: Expected [a-zA-Z] or end of input but "(" found However, if start was…
deostroll
  • 11,661
  • 21
  • 90
  • 161
0
votes
1 answer

PegJS Maths Parsing

Currently, my grammar supports basic variable assignments, which I'll be using for this example, but I am experiencing some issues with the maths parsing. It returns correctly when tried with: test = 10^2 for example, but it returns: Line 1, column…
Llama Boy
  • 103
  • 8
0
votes
1 answer

Deep labeling of parameters inside pegjs regex group

Consider the following grammar: list = head:item (',' tail:item)* { return [head].concat(tail); } item = $ ([0-9]*) It should describe lists of positive integers. The problem is that tail is undefined as it is inside parens. So I'm forced to do…
Pierre Arlaud
  • 4,040
  • 3
  • 28
  • 42
1 2 3
8 9