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

Treetop boolean logic operations

I am implementing DSL which has syntax: "[keyword] or ([other keyword] and not [one more keyword])" Each keyword will transform to boolean (true, false) value and after that it should be calculated using operators and, or, not My current grammar…
djsmentya
  • 315
  • 1
  • 12
3
votes
1 answer

Can I use Treetop to parse an IO?

I've got a file that I want to parse with Treetop. If I wanted to parse the entire thing, I'd use rule document category_listing* end I don't really want to read the entire file into memory at once. I know I can set up the parser to parse one…
rampion
  • 87,131
  • 49
  • 199
  • 315
3
votes
1 answer

What's wrong with my Treetop grammar?

I have the grammar file alexa_scrape.tt: grammar AlexaScrape rule document category_listing* end rule category_listing category_line url_line* end rule category_line category "\n" end rule category ("/" [^/]+)+ end …
rampion
  • 87,131
  • 49
  • 199
  • 315
3
votes
1 answer

How can I avoid left-recursion in treetop without backtracking?

I am having trouble avoiding left-recursion in this simple expression parser I'm working on. Essentially, I want to parse the equation 'f x y' into two expressions 'f x' and '(f x) y' (with implicit parentheses). How can I do this while avoiding…
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
2
votes
1 answer

Simplest treetop grammar is returning a parse error, just learning

I'm trying to learn treetop and was taking most of the code from https://github.com/survival/lordbishop for parsing names and was going to build from that. My structure is a bit different because I'm building it in rails, rather than ruby command…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
2
votes
1 answer

Recursive treetop is not working

I'm trying to create a parser using Treetop that is somewhat recursive. An expression can be a number but it also can be an addition of expressions, so I wrote this: grammar Language rule expression "(" _ expression _ ")" / addition / integer…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
2
votes
1 answer

Could not find treetop-1.4.9 in any of the sources - cap deploy:migrate

I am running into an issue when trying to run migrations from capistrano (cap deploy:migrate). latest => /var/www/site/releases/20110108002015 * executing "cd /var/www/site/releases/20110108002015; rake RAILS_ENV=production db:migrate" servers:…
St_Heave
  • 21
  • 1
2
votes
2 answers

matching tag pairs in Treetop grammar

I don't want a repeat of the Cthulhu answer, but I want to match up pairs of opening and closing HTML tags using Treetop. Using this grammar, I can match opening tags and closing tags, but now I want a rule to tie them both together. I've tried…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
2
votes
1 answer

RSpec test of Treetop parser output doesn't match when it should

I have this spec: it 'can parse armies with only section headers' do list = <<-LIST :Core :Special :Omgg :Moarheaders LIST expected_output = "## Core\n## Special\n## Omgg\n## Moarheaders\n" parsed = @parser.parse(list) …
Josiah Kiehl
  • 3,593
  • 3
  • 26
  • 28
2
votes
1 answer

best way to parse plain text file with a nested information structure

The text file has hundreds of these entries (format is MT940 bank statement) {1:F01AHHBCH110XXX0000000000}{2:I940X …
Beffa
  • 915
  • 1
  • 8
  • 18
2
votes
1 answer

Turning a Treetop parse tree into an abstract syntax tree (AST)

I have simplified a grammar expressed in Treetop, and I am trying to filter the parser's output into an AST, using custom nodes. grammar Elem rule top lpar 'top' space args_:(lpar 'args' space ((ident / number) space?)* rpar) space? …
JCLL
  • 5,379
  • 5
  • 44
  • 64
2
votes
2 answers

Treetop basic parsing and regular expression usage

I'm developing a script using the ruby Treetop library and having issues working with its syntax for regex's. First off, many regular expressions that work in other settings dont work the same in treetop. This is my grammar:…
user289111
  • 21
  • 2
2
votes
1 answer

Treetop ignores methods defined in grammar

I'm trying to parse a percentage with treetop. I wrote the following grammar: grammar Numerals rule percentage (decimal "%") { def to_f decimal.to_f / 100 end } end rule decimal sign [0-9]+ '.' [0-9]* { …
crater2150
  • 899
  • 9
  • 25
2
votes
1 answer

Rule's order does matter in TreeTop?

I am just starting to use TreeTop to do parsing works. The following is the snippets that puzzles me: grammar Fortran rule integer [1-9] [0-9]* end rule id [a-zA-Z] [a-zA-Z0-9]* end end parser =…
Li Dong
  • 1,088
  • 2
  • 16
  • 27
2
votes
2 answers

How to define {min,max} matches in treetop peg

With Ruby's regular expressions I could write /[0-9]{3,}/ I can't figure out how to write this in treetop other than: rule at_least_three_digit_number [0-9] [0-9] [0-9]+ end Is there a 'match [at least|most] n' rule for treetop?
Samuel Danielson
  • 5,231
  • 3
  • 35
  • 37