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

Pegjs reserved keyword

I got a grammar supporting this: AND, OR, NOT, ( and ), ", ' Few samples of things I need to be able parse: a1 OR a2 a1 a2 (same as above) a1 AND a2 "a1" AND 'a2' a1 OR a2 NOT a3 a1 a2 OR "a3" NOT(a1 AND a2 'a6') Considering a1, a2,…
Deisss
  • 63
  • 5
2
votes
2 answers

how to write a simple peg grammar for a liquid-like templating language?

edit: you can follow the progress here: https://github.com/simple-updates/template I'm using peg.js and trying to write something that could interpret a template like: hello {{ "world" }} {% if a %} good {{ a }} {% else %} bad {% endif %} I've…
localhostdotdev
  • 1,795
  • 16
  • 21
2
votes
1 answer

Can PEGjs take the "closing" character of a statement as input?

I've been working on a PEGjs grammar. Most of it works, but I'm having trouble with one last thing. My parser takes input that looks like this: First:[content]; and returns the type (First or Second) and each of the elements inside content ("c",…
Sara M
  • 23
  • 2
2
votes
1 answer

Match the string literal containing underscope using PEG.js

i am continue to learning PEG.js, but stuck on the next issue. PEG.js-generated parser unable to match string containing underscopes: CONFIG += stl_off but successfully parse the string without them: CONFIG += static (this is a built-in variable…
eraxillan
  • 1,552
  • 1
  • 19
  • 40
2
votes
1 answer

PEG.js in Angular 2+ app

I've generated a parser using PEG.js and I'm trying to use the parser in a service class. I just have no idea how to import it into my typescript class. Do I just need to create a typescript definition file? I'm new to typescript and I'm not great…
Jimeh
  • 367
  • 1
  • 6
  • 16
2
votes
1 answer

Save variable value for future use on peg.js

I am implementing a Relational Algebra to SQL converter using Peg.js. I got implementing almost all actions, but I not implement the assigment operator, where a relation is converted to SQL and is saved in a variable for future use. (Ex: A <- Π id…
2
votes
1 answer

The element of the two statements are mutually referenced with peg.js

define the block like this compound_stat = '{' decl exp_stat '}' exp_stat = exp ';' decl = decl_specs id ';' decl_specs = 'int'/'float' id =name:[a-z]+ {return name.join("");} exp_stat = left:multiplicative "+" right:exp_stat {…
freyone
  • 349
  • 1
  • 8
2
votes
0 answers

Is it possible to use PEG.js with an array of tokens instead of a string?

I have the following classes which will represent different kinds of data: class A { ... } class S { ... } class F { ... } Then I construct input array: var input = [new F(), new A([11,22]), new S([33,44]), new F([55,66]), new A([77,88])] Then I…
vbarbarosh
  • 3,502
  • 4
  • 33
  • 43
2
votes
1 answer

Left Recursion Error in Peg.JS

I am currently making a programming language for a science fair. This is my PEG.js grammar: start = s:Statements { return ['Program', {}].concat(s); } / _ Statements = s:Statement ";" { return s; } / ss:Statements s:Statement ";" …
2
votes
1 answer

PEGJS predicate grammar

I need to create a grammar with the help of predicate. The below grammar fails for the given case. startRule = a:namespace DOT b:id OPEN_BRACE CLOSE_BRACE {return {"namespace": a, "name": b}} namespace = id (DOT id)* DOT = '.'; OPEN_BRACE =…
djadmin
  • 1,742
  • 3
  • 19
  • 27
2
votes
2 answers

PEGJS: How to pass a grammar

Quoting from PEGJS Tutorial: To generate a parser, call the PEG.buildParser method and pass your grammar as a parameter: var parser = PEG.buildParser("start = ('a' / 'b')+"); My grammar is a bit more complicated: start =…
elmazzun
  • 1,066
  • 2
  • 18
  • 44
2
votes
1 answer

Return key, value object with dynamic key name

In PEG.js I have the following rule label = l:[a-zA-Z\$\#\% ]* { return word(l); } block = "[" l:label "]" { return l; } option = "\n"* key:block value:label "\n"? {return {key : value}; } If it parses [hello] world it results in: {"key":…
Tessmore
  • 1,054
  • 1
  • 9
  • 23
2
votes
1 answer

Why does this peg grammar not recognisze 42?

Using the grammar start = b / a a = "4" "2" b = "4" with peg.js recognizes 4 but not 42 in which case the error "Line 1, column 2: Expected end of input but "2" found." is reported. Obviously the parser completes the start -> b rule…
citykid
  • 9,916
  • 10
  • 55
  • 91
2
votes
1 answer

How to build PEG.js 0.7.0 parser using Rhino (Java SE 6 ScriptEngine API)

I've been building parsers using a Maven Plugin (i.e. calling PEG.js from Java code) successfully using PEG.js version 0.6.1, but now while trying to upgrade to the new version, it's failing with the error message: …
Leo Gomes
  • 1,113
  • 9
  • 14
1
vote
1 answer

Selector in PEG.js grammar accepting what is shouldn't

I've recently been working on a custom programming language using PEG.js. I made a system that recognises variable names and evaluates variable values, supporting access to object/array properties. Global variables (glob): { "null":null, …
MfyDev
  • 439
  • 1
  • 12
1 2
3
8 9