treetop

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 love a better tutorial than the on-site docs or the video, if there is one. On a lower leve...

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 parse. Is there a better way to handle capturing all characters than my chars rule? Ther...

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 implementing a style within a style. e.g: #rule #one { #two { color: red; } c...

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.. ...

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? ...

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. ...

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' end jspToken should match '<%' while jspPageToken should match '<%@page' When I try this in irb: ...

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: (myline.treetop) grammar MyLine rule line string whitespace condition end rule string ...

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") { def content [:adjective, text_value] end } e...

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 cc}}. I want to extract this array so I can use it in ruby. My first thought was, "No probl...

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 N2}{3:{108:XBS/091502}}{4: :20:XBS/091202/0001 :25:5887/507004-50 :28C:140/1 :60F:C0914CHF7789, :61:0912021202D36,80NTRFNONREF//0887-1202-29-941 04392579-0 LUTHY + xxx, ZUR :86:6034?60LUTHY + xxxx, ZUR vom 01.12.0...

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. Can I exit rule if I find that the length of text_value is not between 2 and 5? ...

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 first.value + second.value end } end rule number [1-9] [0-9]* { def value...

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) parsed.should_not be_nil parsed.transform.should be expected_output end Which produces this outpu...

Is there something like Ruby's Treetop for PHP?

Hi, as I wrote a small PHP framework with a DSL parser, and I'm not satisfied with the result, is there any tool like Treetop for PHP? It would lead to far better (and nicer) results. ...

Problem with treetop grammar, not matching all options

I am writing a small, really simple lisp parser in ruby with the treetop gem just to experiment with it. However, it is not really working out how I want it to, and the documentation is pretty poor so it's hard to understand what I am doing wrong. Currently, the grammar can match both a symbol and a boolean, but not a number. However, wh...

Circular Dependency Grammar

I am using treetop to construct a grammar but am having problems with what seems to be a circular dependency. Note: this is not really a treetop question, but more of a question with loading files. Consider the following structure: test.rb lib/A.treetop lib/B.treetop lib/AB.treetop lib/all.rb And the sources for the files # test.rb ...

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 existing way in Treetop to say "hey, look for Ruby code here, and give me its breakdown" with...