Questions tagged [treetop]

Treetop is a Ruby parser generator for PEG grammars.

PEG (Parsing Expression Grammar) is a powerful top-down / recursive descent parsing strategy. That allow simpler more natural grammars than LL(k). Although potentially less efficient that LL(k) parsers, PEG grammar make easier to write the parser than using LL(k) grammars.

Treetop generate packrat Ruby parsers for PEG grammars.

What kind of question should have this tag?

  • Question about Treetop grammar construction
  • Question about Treetop APIs
  • etc.
85 questions
2
votes
1 answer

Treetop infinite recursion with negative rule

I have the following treetop grammar: grammar TestGrammar rule body text / expression end rule text not_delimiter* end rule expression delimiter text delimiter end rule delimiter '$'…
Eric
  • 2,784
  • 1
  • 20
  • 25
1
vote
1 answer

What is the ellipsis (empty string) used for in a Treetop(PEG) grammar?

The Treetop website gives the following explanation that I don't understand Ellipsis An empty string matches at any position and consumes no input. It's useful when you wish to treat a single symbol as part of a sequence, for example when an…
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
1
vote
1 answer

Treetop: parsing string literals?

So, I am trying to learn me a bit of ruby, a bit of TDD and a bit of Treetop. I have the following grammar for parsing string literals: grammar Str rule string '"' ( !'"' . / '\"' )* '"' end end And the following test…
Rom1
  • 3,167
  • 2
  • 22
  • 39
1
vote
2 answers

Finding words in treetop - some matches not being made

I've run into a bit of a strange situation. I'm trying to parse measurements using treetop. For instance - 6' of 1/2" Copper Pipe of course, this can also be written as feet, Feet, inch, inches, Inch, inch, etc. etc. so I have a rule rule…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
1
vote
2 answers

Why is this returning an 'undefined method' error

I'm getting started with Treetop (though I don't think this is a treetop error) and I'm trying to parse a simple date field. I am trying to figure out if the date includes a month, and if so return that. So i pass my parsed tree to my view and say…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
1
vote
2 answers

I believe this should be one rule in Treetop

I have this working pair of rules in Treetop that the perfectionist in me believes should be one and only one rule, or maybe something more beautiful at least: rule _ crap / " "* end rule crap " "* "\\x0D\\x0A"* " "* end I'm parsing some…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
1
vote
1 answer

Access Associating Methods with Node in Treetop

With the grammar defined as below, why I keep get error while try to access the val method of nodes created by rule key? The error message is (eval):168:in `val': undefined local variable or method `key' for…
Zifei Tong
  • 1,697
  • 1
  • 19
  • 32
1
vote
1 answer

How can you require an undetermined character to be repeated consecutively a certain number of times in Ruby Treetop?

I want to create a rule that requires a non-number, non-letter character to be consecutively repeated three times. The rule would look something like this: # Note, this code does not do what I want! grammar ThreeCharacters rule…
Sebastian
  • 15
  • 4
1
vote
1 answer

Ruby Treetop how to include everything that does not match the grammar

I am tying to create a treetop grammar. I have created the rules to match sections in the file that are of interest to me. grammar Sexp rule bodies body+ end rule body commentPortString (ifdef_blocks / interface)+ (!newLine) …
justrajdeep
  • 855
  • 3
  • 12
  • 29
1
vote
3 answers

"no such file to load -- treetop/runtime" running "rake jobs:work"

when i try and run the "rails server" or "rake jobs:work" i get the error: "no such file to load -- treetop/runtime" full trace: macbook-pro-2:domain ryan$ rake jobs:work --trace(in /Applications/htdocs/domain) rake aborted! no such file to load --…
1
vote
1 answer

Treetop ruby parser - could not parse Ordered Choice

I have defined simple grammar for parsing string and number using Treetop as below. grammar Simple rule value number / string end rule string word space string / word end rule word …
lchanmann
  • 357
  • 2
  • 10
1
vote
1 answer

Using ruby's treetop peg to parse a debian Packages.gz

I'm trying to break open a Packages.gz using Ruby's treetop and I've having trouble making keywords and values unambiguous. Here's my treetop grammar: grammar Debian rule collection entry+ end rule entry (tag space value) end rule…
xrl
  • 2,155
  • 5
  • 26
  • 40
1
vote
1 answer

Treetop: getting the offset of a node

I'm using Treetop to generate a parser for a small programming language. Upon successful parsing, I'd like to do some semantic analysis on the syntax tree. Ideally, whenever I encounter a piece of (semantically) invalid code, I would like to print…
Leo Cassarani
  • 1,289
  • 10
  • 14
1
vote
1 answer

Problem with treetop grammar, not matching all options

I am writing a small, really simple lisp parser in ruby with the treetop gem just to experiment with it. However, it is not really working out how I want it to, and the documentation is pretty poor so it's hard to understand what I am doing wrong.…
bennybdbc
  • 1,425
  • 3
  • 15
  • 24
1
vote
1 answer

Why is a custom SyntaxNode subclass not working with parentheses?

I have a treetop grammar like below: grammar Addme rule AddExpr Num '+' Num end rule Num [0-9]+ end end This is working when I parse the expression: g = AddmeParser.new t = g.parse("1234+56789") . . . there is a…
suhao399
  • 628
  • 7
  • 11