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

Parsing complete mathematical expressions with PEG.js

I'm trying to extend the example grammar of PEG.js for parsing mathematical expressions with all the 4 operators for my online BASIC interpreter experiment: http://www.dantonag.it/basicjs/basicjs.html but not all the expressions are parsed…
friol
  • 6,996
  • 4
  • 44
  • 81
5
votes
3 answers

Eliminate Left Recursion on this PEG.js grammar

(Note: I've read other questions like this, but I haven't been able to figure this out). I wrote this grammar: start = call ident = [a-z]+ spaces = [ ]+ call = f:ident spaces g:(call / ident) { return f + "(" + g + ")"; } With this input a b…
user1527166
  • 3,229
  • 5
  • 26
  • 26
5
votes
1 answer

Trouble with PEG.js end of input

I am trying to write a simple grammer for PEG.js that would match something like this: some text; arbitrary other text that can also have µnicode; different expression; let's escape the \; semicolon, and \not recognized escapes are not a…
RushPL
  • 4,732
  • 1
  • 34
  • 44
4
votes
2 answers

Using PEG.js for simple search/replace

Im trying to understand how to use PEG.js for simple search/replace in a text. Surely this is not the intended use for a parser but anyway Im curious about the logic behind these kind of languages to produce some search/replace. The problem that Im…
Masacroso
  • 249
  • 2
  • 12
4
votes
3 answers

How to make optional word in PEG.js

I'm trying to build a simple parser with PEG.js. I want the user to be able to input a series of keywords, with an optional "AND" between them, but I can't seem to get the optional and working. It always expects it, even though I've marked it with…
T Nguyen
  • 3,309
  • 2
  • 31
  • 48
3
votes
1 answer

PEGJs, Grammar to create nested array

I'm having following input string: ( ( (App = smtp AND "Server Port" != 25) OR (App = pop3 AND "Server Port" == 20) ) AND (App = smtp AND "Server Port" != 35) ) OR (App = pop3 AND "Server Port" != 110) AND ( …
3
votes
1 answer

How to parse only comments using pegjs grammar?

I've written a pegjs grammar that is supposed to parse any kind of js/c-style comments. However, it's not quite working since I've only managed to capture the comment itself, and ignore everything else. How should I alter this grammar to only parse…
The Puma
  • 1,352
  • 2
  • 14
  • 27
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

PEGJS: Generating an AST for a predicate first syntax

I'm back to exploring pegjs and clearly have not grasped the core concept yet. I'm trying to parse a "query language" that starts with a predicate and then a list of operands (which could include another predicate). So a simple example would…
Sarus
  • 3,303
  • 1
  • 23
  • 27
3
votes
3 answers

How to use PEGjs for validation, instead of parsing?

I have the following PEGjs productions: NameStartChar = ":" / [A-Z] / "_" / [a-z] / [\u00C0-\u00D6] / [\u00D8-\u00F6] / [\u00F8-\u02FF] / [\u0370-\u037D] / [\u037F-\u1FFF] / [\u200C-\u200D] / [\u2070-\u218F] / [\u2C00-\u2FEF] /…
Domenic
  • 110,262
  • 41
  • 219
  • 271
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
1 answer

Lambda expressions in PEG.js

I have PEG grammar problem with lambda expressions, they work if I use syntax: x:{y:{x+y}}(20)(30) which is equivalent of (function(x) { return function(y) { return x+y; }; })(20)(30); but this don't work f:{f(10)}(x:{x*x}) which is equivalent…
jcubic
  • 61,973
  • 54
  • 229
  • 402
2
votes
1 answer

Pegjs Expected [0-9.] or end of input but "a" found

I want to handle string starts with number using pegjs. When I input with 1abcd it throws Expected [0-9.] or end of input but "a" found.. The expected output is { item: '1abcd', case: '=' }. What changes do I need? var parser = peg.generate(` …
kiran
  • 444
  • 3
  • 15
2
votes
2 answers

Peg parser - support for escape characters

I'm working on a Peg parser. Among other structures, it needs to parse a tag directive. A tag can contain any character. If you want the tag to include a curly brace } you can escape it with a backslash. If you need a literal backslash, that should…
user1065745
  • 787
  • 1
  • 5
  • 9
2
votes
1 answer

PegJS Member Expression Parsing

I am currently making a programming language, and using PegJS for my parsing. Here is my grammar: Start = __ program:Program __ { return program; } // ----- A.1 Lexical Grammar ----- SourceCharacter = . WhiteSpace "whitespace" = "\t" /…
Llama Boy
  • 103
  • 8
1
2
3
8 9