[antlr-interest] ASTLabelType C# Problem
Sam Harwell
sharwell at pixelminegames.com
Sun Jul 10 17:58:58 PDT 2011
If your parser uses a special tree type, you should implement the following
method in your helper file to ensure that there's never a case where the
user forgets to set the tree adaptor.
partial void CreateTreeAdaptor(ref ITreeAdaptor adaptor) {
adaptor = new MyTreeAdaptor(this);
}
You'll need to implement a tree adaptor for the new node type, which at a
minimum should implement the following methods:
internal class MyTreeAdaptor : CommonTreeAdaptor {
public override object Create(IToken payload) {
return new MyTreeNodeType(payload);
}
public override object ErrorNode(ITokenStream input, IToken start,
IToken stop, RecognitionException e) {
return new MyTreeNodeErrorType(input, start, stop, e);
}
}
Sam
-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of DJB MASTER
Sent: Sunday, July 10, 2011 6:05 PM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] ASTLabelType C# Problem
Ok, I downloaded the preview release and it has seemed to fix those errors.
I was using the stable release because I didn't want to use a library that
was 'temperamental'.
Just one more thing, now when using my ASTNode I get an invalid cast from
CommonTree to ASTNode in my rules. On these lines...
'Number16_tree = (ASTNode)adaptor.Create(Number16);'
I've set the adaptor using...
'ASTAdaptor treeAdaptor = new ASTAdaptor(); parser.TreeAdaptor =
treeAdaptor;'
Do I have to set the adaptor somewhere else? I've seen people talking about
invalid casts from CommonTree, not sure what's required.
Thanks again.
--
View this message in context:
http://antlr.1301665.n2.nabble.com/ASTLabelType-C-Problem-tp6567453p6568868.
html
Sent from the ANTLR mailing list archive at Nabble.com.
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
More information about the antlr-interest
mailing list