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

Treetop grammar issues using regular expressions

I have a simple grammar setup like so: grammar Test rule line (adjective / not_adjective)* { def content elements.map{|e| e.content } end } end rule adjective ("good" / "bad" / "excellent")…
user289111
  • 21
  • 2
0
votes
1 answer

How to embed Ruby code in Treetop for fully custom AST generation?

I am trying to write a parser using Treetop, for a toy langage that simply looks like this : prog test is a = b; if c then d=f; end; end My grammar seems ok, but when I try to embed Ruby code in the grammar, I get weird messages that I…
JCLL
  • 5,379
  • 5
  • 44
  • 64
0
votes
2 answers

Treetop ignore grammar rules

Treetop seems to ignore turther rules after the first and fails to parse anything that doesn't match the first rule on the grammar file. I already tried to swap the order of the rules, but still, only the first one is considered. #…
paul.ago
  • 3,904
  • 1
  • 22
  • 15
0
votes
1 answer

Treetop: How to make combined rule?

I want to make a simple JSP parser by using Treetop. Now, I have the following problem: My basic grammar for starting is: grammar Jspgrammar rule jspToken '<%' end rule jspPageToken jspToken '@page' …
poseid
  • 6,986
  • 10
  • 48
  • 78
0
votes
2 answers

How to code an action trigger with treetop?

I'm trying to have some bit of code running each time the parser recognises a token. Let's say grammar FooBar rule start (foo "\n")+ end rule foo stuff_i_want:([a-z]+) { puts "Hi there I found: #{stuff_i_want.text_value}" …
The Mighty Rubber Duck
  • 4,388
  • 5
  • 28
  • 27
0
votes
1 answer

Roman numerals in treetop grammar

I want to parse an ordered list, which is something like: I - Something II - Something else... IX - Something weird XIII - etc So far, my treetop grammar is: rule text roman_numeral separator text newline end rule roman_numeral &. ('MMM' /…
Bruno Carvalho
  • 167
  • 3
  • 7
0
votes
1 answer

PEG grammar to parse optional content

Can anyone tell me how to write syntax on Treetop that supports both: system u AAA1 car=5, motor=4 and system u car=5, motor=4
Sokmesa Khiev
  • 2,910
  • 3
  • 19
  • 30
0
votes
1 answer

What does SyntaxNode+[Node] mean in treetop? (Ruby)

I have defined a syntax using treetop and most of the values parse fine, but some look like Response+Isupport1 offset=0, "...orted by this server" (host,space1,space2,nickname,space3): ... and ... ... SyntaxNode+Isupport0 offset=52, "WATCH=128 "…
Speed
  • 1,424
  • 1
  • 16
  • 24
0
votes
2 answers

How to parse parse directory path containing whitespaces and escaped symbols using treetop?

I need to parse some strings which contain paths to directories. The problem is that the contains escaped whitespaces and other escaped symbols. For example: "/dir_1/dir_2/dir_3/dir/another/dest_dir\ P\&G/" Note that there is a whitespace before…
roman
  • 5,100
  • 14
  • 44
  • 77
-3
votes
1 answer

Rule for a regex enclosed by two /

How can I match everything between a pair of / characters with treetop? I would also like to match escaped / characters as well. For example, if I were to parse a "regex": /blarg: dup\/md5 [0-9a-zA-Z]{32}/ The result would return: blarg: dup\/md5…
Jym Morrison
  • 185
  • 1
  • 3
  • 9
1 2 3 4 5
6