Skip to content

Instantly share code, notes, and snippets.

@takeshik
Created November 27, 2011 19:39
Show Gist options
  • Save takeshik/1398037 to your computer and use it in GitHub Desktop.
Save takeshik/1398037 to your computer and use it in GitHub Desktop.
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