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

Why pegjs not match Expression when __ not matched? Program = __/Expression

Example code: Program = __/Expression Expression = .* __ = [ \t\r\n]* test is 2 * (3 + 4) hahah hahhah def hahah In my mind , pegjs while match Expression when __ is not matched? But this get a error Line 1, column 1: Expected [ \t\r\n] or end…
0
votes
1 answer

Does the Peg.js engine backstep after a lookahead like regexs do?

According to regular-expressions.info on lookarounds, the engine backsteps after a lookahead: Let's take one more look inside, to make sure you understand the implications of the lookahead. Let's apply q(?=u)i to quit. The lookahead is now…
0
votes
1 answer

How do I write a grammar for this (negative lookaheads in Peg.js)?

EDIT: more info over at Does the Peg.js engine backstep after a lookahead like regexs do? So I've been learning about interpreters in general and specifically I've been working with peg.js recently to create a parser from a grammar. Here's an…
0
votes
1 answer

PegJS - match all characters including ) except if ) is the last character

I am writing a PegJS grammar to parse SQL statements. I'm working on splitting a function into function_id(function_args). For function args I want to match all characters including ( and ) except the last ), this being necessary for nested…
Aveer28
  • 127
  • 11
0
votes
1 answer

how to parse a .RC file using Javascript

I am trying to parse the data from a .RC (resource definition file) to JSON using js with simple fs.readFile function, however I am getting SyntaxError: Invalid or unexpected token. At the moment I've found no other solution to parse this type of…
N W
  • 19
  • 7
0
votes
1 answer

How to describe conditional statement (if-then-else) using PEG

i'm working on Qt's qmake project file parser (open source project). And i have a trouble with describing qmake's variant of conditional statement, called "scope" in documentation. EBNF (simplified): ScopeStatement -> Condition ScopeBody Condition…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
0
votes
1 answer

Parsing Paragraphs in Peg.JS

I am trying to learn peg.js and want to parse simple "blocks" of text, but am struggling with how to group sequential lines without getting a "possible infinite loop" error from my syntax. Goal: line 1 line 3 line 4 line 6 When parsed would…
Jeremy Thomerson
  • 722
  • 2
  • 8
  • 19
0
votes
1 answer

How to export state variable from PEG.js parser

I'm starting to use excellent PEG.JS JavaScript parser generator to implement Qt's qmake project file parser (*.pro). It looks bash script, with variable assignments and function calls. First of all, i need to parse all assignments to some kind of…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
0
votes
1 answer

Convert regular expression to PegJs Grammar

I'm new to PEGjs and I'm trying to write a PEGjs grammar convert the RegEx (\s*[\(])|(\s*[\)])|(\"[^\(\)]+?\")|([^\(\)\s]+) to grammar. Basically what I'm trying to do is transform the test input (App= smtp AND "SPort" != 25) OR (App= pop3 AND…
Reddy
  • 1,403
  • 3
  • 14
  • 27
0
votes
1 answer

How to define recursive rule for pegJS

So, I am trying to use PegJS to define a parser for a simple language. The language consists purely of infinitely deep function calls, which are separated by commas such as: f(4, g()) => [f, [4, g, []]] g() f(5) => [g, [], f, [5]] This is the…
Josh Weinstein
  • 2,788
  • 2
  • 21
  • 38
0
votes
1 answer

what is wrong with this peg grammar?

the following grammar (from RFC 2396): domainlabel = 'a' / ('a' ('a' / '-')* 'a') cannot parse this: aa why?
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
0
votes
2 answers

Expected any character but end of input found

my input is a recursive structure looks like this (notice the blank 2nd line): xxx @{} yyy @{ zzz @{} wwww }   the grammar as i see that would read it should look like this: start = item+ item = thing / space thing = '@{' item* '}' space…
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
0
votes
1 answer

Conditional grammar rule in PEGjs

I'm trying to implement a simple DSL that parses basic arithmetic expressions. This needs to be done in the browser, so I'm using PEGjs to generate the parser. Terms in the expression can be numbers (integers or real), variables (variables are…
oorst
  • 909
  • 2
  • 7
  • 29
0
votes
1 answer

PEG.js help - optional free text followed by key value pairs

I wrote the following parser (paste into http://pegjs.org/online and it works): Expression = Pairs / FullTextWithPairs Pairs = (';'? _ p:Pair { return p; })* FullTextWithPairs = fto:FullText po:Pairs { var arr = []; if (fto) { …
nadavelyashiv
  • 309
  • 1
  • 3
  • 12
0
votes
1 answer

Grammar is matching function rule more than required number of times

Here is a grammar that I used. The action after matching the rule 'Func' is called 12 times for the input string if(diff("col")) instead of 2 times. Debugging I realised the varible peg$currPos is being set back when parsing the Eq rule. I am not…
1 2 3
8 9