Created
September 17, 2012 16:57
-
-
Save pedroreys/3738477 to your computer and use it in GitHub Desktop.
Using Irony with strongly typed AST nodes
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
public class MyDslGrammar : Grammar | |
{ | |
public MyDslGrammar(): base(caseSensitive:false) | |
{ | |
var binaryExpression = new NonTerminal("binaryExpression", typeof(BinaryExpressionNode)); | |
/*...*/ | |
} | |
} |
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
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