- Get ANTLR 4 from nuget (you will need to allow pre-release versions for now)
- Change your ANTLR build script to reference the new ANTLR JAR. The JAR is included in the nuget. This what my build script looks like
set classpath=C:\xxx\packages\Antlr4\tools\antlr4-csharp-4.1-SNAPSHOT-complete.jar
java org.antlr.v4.Tool xxx.g4 -Dlanguage=CSharp_v4_0 - Rename grammars from .g to .g4
- Remove the options block or change it to match your C# version selection
options
{
language=CSharp_v4_0;
} - Tokens should be comma delimited not semicolon delimited
- Always use a $ when referring to parameters, return variables, tokens etc. ANTLR 3.4 did not always enforce this so if you forgot it in a few places you will need to fix them
- You can still check if a optional token exists just be sure to use the .ctx. E.g. use this
if( $i.ctx != null ) - You may get errors when using properties on matched tokens. Parentheses will fix this. E.g.
($i).Text - Use “-> skip” rather than “{$channel=HIDDEN}”
- Use “.*?” rather than “options {greedy=false;}”
Hope this helps someone
No comments:
Post a Comment