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

pegjs regular expression match words up until a word from a collection of words is found

I am using the pegjs parser generator for a project and I am having difficulty creating a grammar that should match all words up until a collection of words that it should not match. as an example in the string "the door is yellow" I want to be able…
Tyler Oliver
  • 1
  • 1
  • 4
0
votes
2 answers

Specifying quantity in PEG.js

I'm playing around with PEG.js How can I allow to enter exactly 2 letters? This is my approach: start = word word = [A-Za-z]{2} I used the {2} from regex, but unfortunately it doesn't work with PEG.js.
Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
0
votes
1 answer

Peg.js in AngularJS webapp

I have an AngularJS web application. I'd like to use peg.js in my application. I've just written a peg.js grammar: CriteriaValue.pegjs and generated the parser with the command line: pegjs CriteriaValue.pegjs, which generated CriteriaValue.js. Could…
user3181983
  • 153
  • 1
  • 4
  • 13
0
votes
2 answers

stop peg.js from throwing ParseError

Can I make PEG.js return a default value instead of throwing a parse error? basically I would like to have / anything:.* {return anything} in my grammar, but if any rule partially mathes it will still throw a Parse error. So start =…
zidarsk8
  • 3,088
  • 4
  • 23
  • 30
0
votes
1 answer

Pegjs: Don't allow reserved keywords as a variable name

I am writing my language in Pegjs and as usual, my language has some keywords, like true, false, if, else and today for instance. Now, I want to declare a variable, but apparently, the variable name cannot be one of the reserved keywords. It can be…
user1485864
  • 499
  • 6
  • 18
0
votes
1 answer

parsing boolean expression chain with pegjs

I'm trying to parse this string with peg.js: filter a > 2 or b < 3 or b > 10 or c = 12 The relevant extract of the grammar looks like: bool "bool" = left:expr space+ logicOp:logicOp space+ right:bool { return new options.BooleanExpr(left,…
orange
  • 7,755
  • 14
  • 75
  • 139
0
votes
2 answers

How to group non-empty lines with PEG.js

I'm trying to parse a categories file with PEG.js How can I group categories (set of non-empty lines followed by a blank line) stopwords:fr:aux,au,de,le,du,la,a,et,avec synonyms:en:flavoured, flavored synonyms:en:sorbets, sherbets en:Artisan…
Fabrice Theytaz
  • 305
  • 2
  • 9
0
votes
2 answers

Parsing Expression Grammars: detect next token?

I'm beginning PEG's with PEG.js. There's something I can't get my head around...I'm sure it's simple but it's giving me a headache trying to understand the concept... Consider this two-rule grammar: name = name:.* {return name.join("")} put =…
themirror
  • 9,963
  • 7
  • 46
  • 79
0
votes
0 answers

Importing PEGJS parser using require and module.exports

I'm trying to use a PEGJS parser in multiple different files. I use the method var Parser = require("./Parser"); When I try to parse something using Parser.parse, though, I am unable to do so, because Parser is undefined. How can I fix this? It had…
NumberOneRobot
  • 1,691
  • 6
  • 17
  • 23
0
votes
1 answer

PEG.js: how to use prompt?

I'm creating a C++ parser with PEG.js, and I need to be able to use cin. With the after-match JS, when I use prompt(), the (alternate) online version throws an error of 'Parse Error: prompt is not defined'. I am trying to use the initializer to…
Alonessix
  • 82
  • 1
  • 8
0
votes
1 answer

How do I match tokens starting with "?" in pegjs

I have to match tokens like this using pegjs: ?xxx ?yyy I would have thought this would work : variable = str:?[a-z]+ { console.log('---->>>',str); return str.join(""); } When I parse the source I get and error: Object ? has no method…
Johan
  • 1,189
  • 3
  • 15
  • 28
0
votes
1 answer

Parser doesn't stop parsing arbitrary newlines and whitespaces

So, I'm trying to write a very basic Lisp parser in pegjs and I got it to spit out the same code as long as the Lisp code was syntactically valid and fit on one line. I wish to extend the parser to be able to accept any newline character inserted…
Hassan Hayat
  • 1,056
  • 8
  • 20
0
votes
1 answer

Why does pegjs fail to process the whitespace rule " "*

The following simple pegjs grammar works fine: start = sentence sentence = word ws sentence / word word = [a-z]* ws = " " It is available at http://jsfiddle.net/4V3Zt/ . The gramar can be also pasted into http://pegjs.majda.cz/online…
citykid
  • 9,916
  • 10
  • 55
  • 91
0
votes
0 answers

how can I parse an object definition like in coffeescript

let's say we have this in cofeescript obj = one: one: 11 two: 12 two: 2 three: four: 34 and that compiles to var obj = { one: { one: 11, two: 12 }, two: 2, three: { four: 34 } } so let's say I have this PEG.js grammar start =…
Theofilos Mouratidis
  • 1,146
  • 12
  • 32
0
votes
1 answer

PegJS: How to match a phrase in surrounding text

I'm tryingto make a parser with PegJS I'm trying to parse something like this.. I would like to email john@gmail.com today or tomorrow. How would you make a parser that matches on certain phrases, like email john@gmail.com and throw away the…
GN.
  • 8,672
  • 10
  • 61
  • 126
1 2 3
8
9