cjheath / treetop

A Ruby-based parsing DSL based on parsing expression grammars.

Home Page:https://cjheath.github.io/treetop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Short syntax for terminals/sequences modules

hesalx opened this issue · comments

(To be shorter I will mean "sequences and terminal expressions" when just say "terminals" and "ordered choice and nonterminal expressions" when say "nonterminals")

Now it is possible either declare a module name for nonterminals or a class name for terminals with angle brackets. It is also possible to declare a module explicitly for terminals to override default accessors.

Such syntax works:

def rule property
    [a-z]+ <Property> {
        def value
             text_value
        end
    }
end

How about to provide short syntax for terminals' module too?

def rule property
    [a-z]+ <Property> <PropertyAccessors>
end

It should be also possible to declare just either a module or a class for terminals with <>:

def rule property
    [a-z]+ <PropertyAccessors>
end

because TreeTop raises an error in such case now, but it means that it knows what kind of thing was passed to <>, so when it is a module TreeTop may behave just like when the module was declared explicitly.

You can apply two modules to the same expression by enclosing it in parentheses (a sequence) as in:

([a-z]+ )

We'e discussed the class/module thing a couple of years ago and I think the current state is already the best compromise between capability, consistency and confusion.

Gah, that didn't work. Try this:

([a-z]+ <Property>) <PropertyAccessors>