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
35
votes
5 answers

PEG for Python style indentation

How would you write a Parsing Expression Grammar in any of the following Parser Generators (PEG.js, Citrus, Treetop) which can handle Python/Haskell/CoffeScript style indentation: Examples of a not-yet-existing programming language: square x = x…
Matt
  • 17,290
  • 7
  • 57
  • 71
17
votes
8 answers

Learning Treetop

I'm trying to teach myself Ruby's Treetop grammar generator. I am finding that not only is the documentation woefully sparse for the "best" one out there, but that it doesn't seem to work as intuitively as I'd hoped. On a high level, I'd really…
user54650
  • 4,388
  • 2
  • 24
  • 27
9
votes
4 answers

recognize Ruby code in Treetop grammar

I'm trying to use Treetop to parse an ERB file. I need to be able to handle lines like the following: <% ruby_code_here %> <%= other_ruby_code %> Since Treetop is written in Ruby, and you write Treetop grammars in Ruby, is there already some…
Sarah Vessels
  • 30,930
  • 33
  • 155
  • 222
7
votes
2 answers

Visual Studio Code: Disabling Error/Warning checks in for specific file type

At work, my team created our own little scripting language using Ruby and the Treetop parser. The syntax for the language itself is very similar to Ruby. I'm using Ruby and the Ruby extension for syntax highlighting for our files for this language,…
OmriSama
  • 302
  • 5
  • 11
6
votes
1 answer

How to deal with Treetop left-recursion

I have a grammar file for a new general-purpose programming language I'm trying to build. I'm trying to make the language robust and natural to use (it is heavily inspired by Ruby, among others), and in doing so I have introduced some left-recursive…
ravinggenius
  • 816
  • 1
  • 6
  • 14
6
votes
4 answers

Vim indenting file for Treetop (Ruby parser)

Has anyone seen a vim indent file for treetop, the Ruby parser/generator? I've found a vim syntax highlighting file, but haven't seen one for indentation.
Peter
  • 127,331
  • 53
  • 180
  • 211
5
votes
2 answers

CSS/HSS Parser in Treetop and Nested Stylesheet Rules

I'm new to Treetop and attempting to write a CSS/HSS parser. HSS augments the basic functionality of CSS with nested styles, variables and a kind of mixin functionality. I'm pretty close - the parser can handle CSS - but I fall down when it comes to…
toothygoose
  • 1,292
  • 1
  • 10
  • 9
5
votes
2 answers

Treetop grammar infinite loop

I have had some ideas for a new programming language floating around in my head, so I thought I'd take a shot at implementing it. A friend suggested I try using Treetop (the Ruby gem) to create a parser. Treetop's documentation is sparse, and I've…
ravinggenius
  • 816
  • 1
  • 6
  • 14
4
votes
1 answer

simplest rules in treetop not working

I have a treetop grammar with only two rules: grammar RCFAE rule num [0-9]+ end rule identifier [a-zA-Z] [a-zA-Z]* end end I'm trying to parse simple strings ("A" and "5"). The "5" is recognized as a…
timichanga
  • 53
  • 3
4
votes
3 answers

Non-greedy matching in Treetop/PEG?

How would I do something like this in Treetop? /.+?;/ It seems like the only way is to do: [^;]+ ';' Which is kind of ugly.. any other way? .+? doesn't seem to work..
cloudhead
  • 15,253
  • 6
  • 42
  • 37
3
votes
2 answers

Treetop parser : Function definition syntax - n arguments

I'm currently trying to describe some basic Ruby grammar but I'm now stuck with function definition. Indeed, I don't know how to handle 'n' argument. Here is the code I use to handle functions containing from 0 to 2 args : rule…
user740316
3
votes
1 answer

Whitespace in Treetop grammar

How explicit do I need to be when specifying were whitespace is or is not allowed? For instance would these rules: rule lambda 'lambda' ( '(' params ')' )? block end rule params # ... end rule block '{' # ... '}' end be sufficient to…
ravinggenius
  • 816
  • 1
  • 6
  • 14
3
votes
1 answer

Treetop SGF Parsing

I am currently trying to write a Treetop grammar to parse Simple Game Format files, and have it mostly working so far. However, there are a few questions that have come up. I am unsure how to actually access the structure Treetop generates after a…
bojo
  • 1,407
  • 13
  • 15
3
votes
1 answer

How to Eliminate Left Recursion in A Verilog Grammar Example

I am using Treetop to create a grammar for the Verilog language, and have come across some cases where the language specification involves a left recursive construct which does not translate to Treetop. I have done some reading on this, and this…
Ginty
  • 3,483
  • 20
  • 24
3
votes
1 answer

How can I associate many alternatives to same class when defining a grammar node with treetop?

I have the following simple grammar: grammar MyGrammar rule comparison_operator '=' / '>' end end When I'm parsing the string >, it returns successfully with: ComparisonOperator When I'm parsing the string =, it…
p.matsinopoulos
  • 7,655
  • 6
  • 44
  • 92
1
2 3 4 5 6