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
1
vote
1 answer

Getting date parts from a simple treetop parser: wrong argument type Class (expected Module)

For the following treetop grammer, when parsing '3/14/01' (via t = Parser.parse('3/14/01') in irb), I get a "TypeError: wrong argument type Class (expected Module)". grammar SimpleDate rule dateMDY whitespace? month_part ( '/' / '-')…
rdnewman
  • 1,379
  • 20
  • 28
1
vote
1 answer

Treetop: parsing single node returns nil

I'm trying to get the basic of Treetop parsing. Here's a very simple bit of grammar so that I can say ArithmeticParser.parse('2+2').value == 4. grammar Arithmetic rule additive first:number '+' second:number { def value …
Matchu
  • 83,922
  • 18
  • 153
  • 160
1
vote
1 answer

Treetop parser error handling mechanism providing useless output

I've been experimenting with Treetop lately to create simple parser for CFG DSL language for one of my clients. I was successful to implement all the features he required, but working with Treetop turned out to be quite a painful experience. The…
Martin Macak
  • 3,507
  • 2
  • 30
  • 54
1
vote
1 answer

Writing Treetop rule to parse input in any order

I'm looking for a way to write Treetop rules which will find some values in any order. So: rule top # ? end rule gender ('women'/'men') / '' end rule age_under ('under' age) / '' end rule age [0-9]+ end I would like to parse these…
Leszek Andrukanis
  • 2,114
  • 2
  • 19
  • 30
1
vote
1 answer

Treeptop & Rails where .treeptop files are loaded from

I can't seem to find any examples of Treetop in Rails apps. In a non rails app, when I do Treetop.load('name_of_treetop_file') it looks in the same folder and loads the .treetop file. In my rails app, no matter where I put it I keep getting: No…
pk1m
  • 286
  • 1
  • 4
  • 12
1
vote
1 answer

BBCode Treetop parser and smart tag closing?

I have written a treetop grammer file that mostly works. For tags like [b] I want to pass them into a function that has a hash of configured BBCodes for that forum. If bold was allowed it would return the HTML, otherwise it would ignore the BB…
Kansha
  • 570
  • 4
  • 12
1
vote
1 answer

Treetop infinite loop when parsing Latex document

I'm trying to write a parser with treetop to parse some latex commands into HTML markup. With the following I get a deadspin in generated code. I've build the source code with tt and stepped through but it doesn't really elucidate what the…
1
vote
1 answer

Treetop Grammar does not recognize "/"

I'm new to Treetop, and have a very simple grammar that I just can't make work. I have some tests: it "parses a open tag as some text surrouded by brackets" do document = "[b]" Parser.parse(document).should_not be_nil end it "parses a close tag…
DVG
  • 17,392
  • 7
  • 61
  • 88
1
vote
1 answer

Treetop backtracking similar to regex?

Everything I've read suggests Treetop backtracks like regular expressions, but I'm having a hard time making that work. Suppose I have the following grammar: grammar TestGrammar rule open_close '{' .+ '}' end end This does not match the…
rlkw1024
  • 6,455
  • 1
  • 36
  • 65
1
vote
1 answer

Matching plural words in Treetop

Is there a way to programmatically match plural words using Treetop. The Linguistics gem will pluralize a word, but how can that be inserted back into the parser. Here's an example of what I'm trying to do: #!/usr/bin/env ruby require…
Josh Voigts
  • 4,114
  • 1
  • 18
  • 43
0
votes
3 answers

Making BBcode parser with PEG problem

I am making bbcode parser with PEG (Citrus implementation for Ruby) and I am stuck on parsing this [b]sometext[anothertext[/b] There is code grammar BBCodeParser rule document (open_tag | close_tag | new_line | text)* end rule open_tag …
Schovi
  • 1,960
  • 5
  • 19
  • 33
0
votes
1 answer

parsing fractions in treetop

I'm having a bit of difficulty parsing fractions in my treetop grammar. My grammar looks like this grammar Numbers rule number regular_number optional_frac { def value [:number, text_value] …
pedalpete
  • 21,076
  • 45
  • 128
  • 239
0
votes
1 answer

parsing data and POS with treetop vs. stanford nlp

I'm trying to parse event (concerts, movies, etc. etc.) data in Ruby and can't decide on what tool to use. I thought the stanford parser was the way to go initially, but then heard of treetop. I'm struggling with both, as getting the stanford…
pedalpete
  • 21,076
  • 45
  • 128
  • 239
0
votes
1 answer

Simple Arithmetic Grammar with Treetop Infinitely Recursing

I'm trying to write a simple calculation grammar with Treetop. To simplify my example for this question, I'm only using variables, numbers and the + operator. I'd like to be able to write expressions like this: A 1 A+B A+1 A+1+B Here's my…
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
0
votes
1 answer

How do you handle no nonterminal node in a 0 or more statement when using elements.map in Ruby Treetop?

I am trying to create a custom syntax node class that maps all its nonterminal nodes. The problem is that one of the nodes does not necessary have to be there which creates a problem when using the elements.map in the custom syntax node class, as…
Sebastian
  • 15
  • 4