Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created September 17, 2012 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroreys/3738477 to your computer and use it in GitHub Desktop.
Save pedroreys/3738477 to your computer and use it in GitHub Desktop.
Using Irony with strongly typed AST nodes
public class MyDslGrammar : Grammar
{
public MyDslGrammar(): base(caseSensitive:false)
{
var binaryExpression = new NonTerminal("binaryExpression", typeof(BinaryExpressionNode));
/*...*/
}
}
public class BinaryExpressionNode : AstNode
{
public AstNode Left { get; private set; }
public AstNode Right { get; private set; }
public string Op { get; private set; }
public override void Init(Irony.Parsing.ParsingContext context, Irony.Parsing.ParseTreeNode treeNode)
{
base.Init(context, treeNode);
Left = AddChild("Arg", treeNode.ChildNodes[0]);
Right = AddChild("Arg", treeNode.ChildNodes[2]);
var opToken = treeNode.ChildNodes[1].FindToken();
Op = opToken.Text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment