C
Charles Comstock
Has anyone taken a look at the idea of having embedded grammars in ruby
like perl6 is intending to add? For instance, the example they give:
grammar Letter {
rule text { <greet> <body> <close> }
rule greet :w { [Hi|Hey|Yo] $to:=(\S+?) , $$}
rule body { <line>+ }
rule close :w { Later dude, $from:=(.+) }
# etc.
}
grammar FormalLetter is Letter {
rule greet :w { Dear $to:=(\S+?) , $$}
rule close :w { Yours sincerely, $from:=(.+) }
}
* Note that this is taken from the perl6 description of grammar, so the
syntax is perl6, obviously we would want a more ruby-esque syntax.
Embedded grammar means that not only can you create grammars to match
what your parsing in the language as opposed to a third party module,
but also that you can derive a grammar from another to add functionality
for a more specific class to match with your grammar. Now I don't know
if it would be easier in ruby just to define a few classes to get
functionality like this as opposed to having it at the language level,
but I think it is a good idea. I think the lack of subroutine calls
from the ruby regex engine would make it difficult to program outside of
the interpreter. Clearly the idea of including a bare regex system in
the language is very powerful, as we have already included it in the
language, but a grammar adds even more power and seems equally
important. Plus if it is implemented correctly, it clearly extends to
allowing many meta functions across ruby if the ruby grammar is
specified internally.
I'm thinking about submitting an RCR on this, but thought I would ask
everyone what they thought?
Charles Comstock
like perl6 is intending to add? For instance, the example they give:
grammar Letter {
rule text { <greet> <body> <close> }
rule greet :w { [Hi|Hey|Yo] $to:=(\S+?) , $$}
rule body { <line>+ }
rule close :w { Later dude, $from:=(.+) }
# etc.
}
grammar FormalLetter is Letter {
rule greet :w { Dear $to:=(\S+?) , $$}
rule close :w { Yours sincerely, $from:=(.+) }
}
* Note that this is taken from the perl6 description of grammar, so the
syntax is perl6, obviously we would want a more ruby-esque syntax.
Embedded grammar means that not only can you create grammars to match
what your parsing in the language as opposed to a third party module,
but also that you can derive a grammar from another to add functionality
for a more specific class to match with your grammar. Now I don't know
if it would be easier in ruby just to define a few classes to get
functionality like this as opposed to having it at the language level,
but I think it is a good idea. I think the lack of subroutine calls
from the ruby regex engine would make it difficult to program outside of
the interpreter. Clearly the idea of including a bare regex system in
the language is very powerful, as we have already included it in the
language, but a grammar adds even more power and seems equally
important. Plus if it is implemented correctly, it clearly extends to
allowing many meta functions across ruby if the ruby grammar is
specified internally.
I'm thinking about submitting an RCR on this, but thought I would ask
everyone what they thought?
Charles Comstock