mental / rydia.net writes: > Quoting Christophe Grandsire <christophe.grandsire / free.fr>: > >> > Matz rejected this claim because we cannot add this syntax >> > without any (yacc's) conflict. >> >> First the block default arguments, now this... It's indeed time >> to get rid of yacc or patch it... Don't look at me! I can't do >> C :(( ... > > Seconded. I really don't think letting yacc dictate the shape of > the language (in ways contrary to human expectation) is a good > thing. Once that starts happening, it urgently needs to go... Full ack. > It'd be different if we were, say, hitting the limits of what could > be expressed as a context-free grammar, but in this case -- as far > as I know -- we're simply getting bitten by the limits of a > particular LALR(1) parser generator. > > Unfortunately, the only authoritative specification I've been able > to find for Ruby's syntax is the YACC grammar. Makes replacing > YACC a bit hard. > > If somebody wanted to do that, though, I guess the first few steps > (all doable in pure Ruby) would be something like: > > 1. write a grammar for Ruby in some neutral format like EBNF > > 2. write a simple parser generator for this format > > 3. write a mapping from the raw parse tree to Ruby AST > > 4. test the grammar against real Ruby ASTs obtained via MetaRuby > > (to an extent, these steps can be done incrementally and in > parallel) > > Once the neutral grammar's been defined, anyone can take it as a > basis for a real parser in C (or really any language... I imagine > JRuby would find it helpful too -- perhaps the JRuby folks have > already done some of this?), and then lobby for Matz's approval. > > But, hopefully there would be ongoing work to keep the neutral > grammar in sync with language developments, so it could also form > the basis of a more comprehensive language specification. > > Now, I am relying on the rest of you to tell me what is wrong with > this idea. I don't think the real problem is the real grammar, that part of parse.y looks like the easier one (and rather readable) to me. The problem is the lexer-parser communication, think heredocs, %q[] etc. There is no way to express that in BNF. > -mental -- Christian Neukirchen <chneukirchen / gmail.com> http://chneukirchen.org