-
Notifications
You must be signed in to change notification settings - Fork 24
LeMP
Update: LeMP has a home page now!
LeMP has evolved into a rather separate idea from LES and Enhanced C#. It behaves essentially like the lexical macro processor in LISP languages, but it (currently) requires you to compile the macros in advance in their own assembly. As an example, here is a simple macro that converts any expression into a string at compile-time (which could be useful as part of something larger, such as a macro that implements INotifyPropertyChanged
for you)
[ContainsMacros]
public partial class StandardMacros
{
[LexicalMacro(@"stringify(id_or_expr)",
"Converts an expression to a string (note: original formatting is not preserved)")]
public static LNode stringify(LNode node, IMacroContext sink)
{
if (node.ArgCount != 1)
return null;
// Use the syntax of the current programming language, whatever that may be
return LNode.Literal(ParsingService.Current.Print(node.Args[0], sink, ParsingService.Exprs));
}
}
Note: I have developed lots of standard macros so that most users will not have to develop their own macros.
While developing LLLPG, I started by creating something extremely simple and modest, a very simple macro language that compiles down to C#. I originally called this "micro-LEL", and I used it to bootstrap the parser generator, LLLPG, by enabling me to input a grammar into it. However, "micro-LEL" did not seem like an appropriate name because it is not descriptive and may not closely resemble whatever I finally create and call "LEL".
I decided to rename micro-LEL to LeMP (Lexical Macro Processor), which more correctly describes what it is: a fancy preprocessor. When I completed the Enhanced C# parser, I also used LeMP to process the EC# code. Thus LeMP was no longer a layer built on top of LES, but rather something syntax-independent. So one can refer to LeMP-on-top-of-LES as LeMP-LES and LeMP-on-top-of-EC# as LeMP-EC#. As of January 2015, "Enhanced C#" really refers to the EC# parser plus LeMP.