Created
November 27, 2011 19:39
-
-
Save takeshik/1398037 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var code = | |
@"(<html> | |
(<head> | |
(<title> 'Yacq-XML') | |
) | |
(<body> | |
(<h1> 'Hello, YACQ World!') | |
(<p> 'Now: \$(DateTime.Now).') | |
) | |
)"; | |
YacqServices.ParseLambda( | |
new SymbolTable(typeof(Symbols)), | |
code | |
).Compile().DynamicInvoke().Dump(); | |
} | |
// Define other methods and classes here | |
static class Symbols | |
{ | |
[YacqSymbol(DispatchTypes.Unknown, null)] | |
public static Expression Missing(DispatchExpression e, SymbolTable s, Type t) | |
{ | |
if (e.Name[0] == '<' && e.Name.Last() == '>') | |
{ | |
return Expression.New( | |
typeof(XElement).GetConstructor(new [] { typeof(XName), typeof(Object[]), }), | |
Expression.Convert( | |
Expression.Constant(e.Name.Substring(1, e.Name.Length - 2)), | |
typeof(XName) | |
), | |
Expression.NewArrayInit( | |
typeof(Object), | |
e.Arguments.ReduceAll(s, typeof(Object)) | |
) | |
); | |
} | |
return DispatchExpression.DefaultMissing(e, s, t); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment