Questions tagged [peg]

A “Parsing Expression Grammar” (“PEG”) is a formal language to describe formal languages.

A Parsing Expression Grammar (“PEG”) is a formal language that defines a set of rules to describe a certain class of formal languages similar to context-free grammars.

In comparison to context-free grammars, PEGs have the advantage of always being unambiguous, and of mapping naturally to recursive descent parsers, which makes them easy to implement.

288 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

PEG grammar to accept late definition

I want to write a PEG parser with PackCC (but also peg/leg or other libraries are possible) which is able to calculate some fields with variables on random position. The first simplified approach is the following grammar: %source { …
Achim
  • 442
  • 1
  • 3
  • 13
0
votes
1 answer

PEG parser for PEG grammars

I am looking for a library which, given an input of a PEG grammar, e.g.: Expression = A B A = [0-9] B = [a-z] Would output a machine readable version, e.g.: { "expression":{ "components":[ { "type":…
Igor Nadj
  • 324
  • 2
  • 9
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

Should I use a regex or a PEG to handle these use cases?

Examples of the data I'm looking to parse: Manufacturer XY-2822, 10-mill, 17-25b Other Manufacturer 16b Part Another Manufacturer WER M9000, 11-mill, 11-40 18b Part Maker 11-36, 10-mill Maker 1x or 2x; Max sizes 1x (34b), 2x (38/24b) I'm trying to…
whistler
  • 767
  • 7
  • 11
0
votes
1 answer

Multiline comments in a recursive descent parser

I'm trying to wrap my head around how to handle C-style multiline comments (/* */) with a recursive descent parser. Because these comments can appear anywhere, how do you account for them? For example, suppose you're parsing a sentence into word…
0
votes
1 answer

Having trouble with simple tree top grammar

I'm having a play with tree top and I just can't get a simple grammar to work and generate the AST I expect. My rules are 1: LINE can be made up of one or more PIPED COMMANDs separated by ; 2: a PIPED COMMAND is one or more COMMANDs separated by |…
Michael Baldry
  • 1,990
  • 2
  • 14
  • 28
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

Why is generated parser so slow?

I was playing around on PEG.js in an attempt to create a parser that is able to take a string and create an object. For example, take the string "a&b" and create: {type:"operator",value:operator, children:[a, b]} However, I have reached the stage…
Budgy
  • 1
0
votes
1 answer

Ruby & Treetop - No such file or directory @ rb_sysopen

I am trying to learn working with Treetop PEG grammar parser, but I am getting weird error straight from beginning. I have this file structure node_extensions.rb parser.rb tranlan.treetop And contents of files is following (listings are in…
Martin Macak
  • 3,507
  • 2
  • 30
  • 54
0
votes
1 answer

Meet "name undefined " error while using pypeg2

I want to use pypeg2 to parse c# code. So I have to define C# grammar first. I know little about parsing expression grammar(PEG), and assume that it has a lot in common with Backus-Naur form(BNF). Recursion is allowed in BNF, so I define my grammar…
sparrow
  • 41
  • 1
  • 8
0
votes
0 answers

Floats in lists halt the parser with 'no available options' error

Given this grammar: (* integers *) DEC = /([1-9][0-9]*|0+)/; int = /(0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)/ | DEC; (* floats *) pointfloat = /([0-9]*\.[0-9]+|[0-9]+\.)/; expfloat = /([0-9]+\.?|[0-9]*\.)[eE][+-]?[0-9]+/; float = pointfloat |…
Aerdan
  • 143
  • 7
0
votes
1 answer

Stack level too deep using Citrus for Parsing Expression Grammar

I'm trying to process what will eventually be Boolean logic using a grammar in Treetop-like Citrus for Ruby. I'm getting a recursion issue, but I'm unclear on exactly why. Here's the text I'm trying to process (it should have a newline at the very…
aardvarkk
  • 14,955
  • 7
  • 67
  • 96
0
votes
1 answer

Parsing string text to num in spanish grammar

I need to write a Python programm to convert spanish numbers in string text into digit numbers: Input: 'Ciento Veinticuatro Mil Ochocientos Treinta y Cinco' Output desired: 124835 I've wrote some code, but I've realized that I'm reinventing the…
Trimax
  • 2,413
  • 7
  • 35
  • 59
0
votes
0 answers

Isolate part of the memory to be used only by specific code in C++

The story is the following. I'm playing with the peg/leg parser generator, which has an excellent syntax for defining PEG grammars and is extremely easy to use. I was completely happy with it until I got mysterious segfaults with generated parser.…