Lexer and parser generators using CTFE
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Feb 28 15:49:26 PST 2012
On Tue, Feb 28, 2012 at 10:03:42PM +0100, Martin Nowak wrote:
[...]
> I won't deny that the combination of CTFE text processing and static
> introspection could improve on this. It could be made more feasible by
> some conventions, e.g. parse result always uses structs or classes and
> built-in arrays.
Excellent idea, I like this.
> class Module
> {
> this(Declaration[]);
> }
>
> class StructDeclaration : Declaration
> {
> enum _enbf = "struct $1=Identifier { $2=Declaration* }";
>
> this(Identifier, Declaration[]);
> }
>
> ...
>
> Parser!(Module, StructDeclaration, ...) parser;
> Module m = parser.parse(read("file.d"));
I like this! Definitely an improvement over yacc syntax.
T
--
Unix was not designed to stop people from doing stupid things, because
that would also stop them from doing clever things. -- Doug Gwyn
More information about the Digitalmars-d
mailing list