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

How to trigger functions in subnodes in Ruby Treetop tree. (was:How to prevent ruby Treetop doing AST squashing)

I am been using treetop for a while. I wrote rules following http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-treetop.html I can parse my whole input string but i none of the other to_array function gets triggered other than…
justrajdeep
  • 855
  • 3
  • 12
  • 29
0
votes
1 answer

how to parse multiple lines using ruby treetop?

I am new to ruby and treetop. I went through this tutorial and came up with the following set of rules. grammar Sexp rule body commentPortString *(I am stuck here)* end rule interface space? (intf / intfWithSize) space? ('\n' /…
justrajdeep
  • 855
  • 3
  • 12
  • 29
0
votes
1 answer

Custom Methods for Treetop Syntax Nodes

I have a Treetop PEG grammar that matches some keys. I want to look up the values associated with those keys in a hash I give the parser. How can I make it so that the syntax nodes have access to methods or variables from the parser? For example,…
Phrogz
  • 296,393
  • 112
  • 651
  • 745
0
votes
1 answer

Treetop parser : how to handle spaces?

Good morning everyone, I'm currently trying to describe some basic Ruby grammar but I'm now stuck with parse space? I can handle x = 1 + 1, but can't parser x=1+1, how can I parser space? I have tried add enough space after every terminal. but it…
DoubleMay
  • 3
  • 2
0
votes
1 answer

Issues using treetop parser library

I am trying to create a simple text parser in ruby using treetop. Although I have followed all steps as mentioned in the blog, I am not being able to run the program. It fails with the error message: user1-mbp15:source user1$ ruby myParser.rb…
Aditya Kotwal
  • 101
  • 2
  • 5
0
votes
1 answer

How do I process a treetop parse tree?

I have written a parser using treetop which successfully produces a parse tree, part of which is reproduced below. SyntaxNode offset=4043, " ": SyntaxNode offset=4043, " " SyntaxNode offset=4044, " " SyntaxNode offset=4045, "…
pingu
  • 8,719
  • 12
  • 50
  • 84
0
votes
1 answer

Basic Treetop grammar doesn't work

I can't make Treetop parse according to the most basic set of rules. Any help would be appreciated # my_grammar.treetop grammar MyGrammar rule hello 'hello' end rule world 'world' end rule greeting hello ' ' world …
synapse
  • 5,588
  • 6
  • 35
  • 65
0
votes
1 answer

Treetop grammar line continuation

I'm trying to create a grammar for a language like the following someVariable = This is a string, I know it doesn't have double quotes anotherString = This string has a continuation _ this means I can write it on multiple line _ like…
soulnafein
  • 1,058
  • 1
  • 10
  • 20
0
votes
1 answer

Why an empty string seems emitted instead of a custom node, sometimes, in a Treetop grammar?

I'd like your advice concerning a recurring problem concerning my usage of Treetop,that I cannot fix...from time to time. I'm probably missing something. I suspect many of you have the right idiom or habits to solve that. I generally use Treetop…
JCLL
  • 5,379
  • 5
  • 44
  • 64
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
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

Can I 'unmatch' a rule programmatically in treetop?

Is it possibe to skip a rule by validating it using ruby code in treetop? Say there is something like this: rule short_words [a-z]+ { def method1 text_value end ... } end And I want the words size to be from 2 to 5 letters.…
dimus
  • 8,712
  • 10
  • 45
  • 56
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

Treetop seems to fail on a simple grammar (5 rules)

I am trying to write a parser for a subset of C. The behavior of treetop is difficult to analyze on this simple (further simplified) grammar. grammar Shyc rule functionDef type space identifier '(' ')' bloc end rule type 'int' end …
JCLL
  • 5,379
  • 5
  • 44
  • 64
0
votes
2 answers

Parsing tcl arrays in ruby with treetop

I have a bunch of data in (what i think is) a tcl array. Basically it's in the form of {a {b c} d {e f} g}. It's only nested one deep, but isn't always nested, that is to say, a may just be a or it may be {aa bb} or possibly {}, but never {aa {bb…
enki
  • 13
  • 2