Created
June 11, 2017 12:05
-
-
Save MrCoder/b892a5db17ccee704e12cd297fa4faaf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static final String someLangSourceCode = | |
"class SomeClass {\n"+ | |
" fun1 {\n"+ | |
" instruction11\n"+ | |
" instruction12\n"+ | |
" }\n"+ | |
" fun2 {\n"+ | |
" instruction21\n"+ | |
" instruction22\n"+ | |
" }\n"+ | |
"}"; | |
public static void main( String[] args ) throws IOException { | |
System.out.println( "Hello world!" ); | |
try { | |
CodePointCharStream codePointCharStream = CharStreams.fromString(someLangSourceCode, "string"); | |
SomeLanguageLexer lexer = new SomeLanguageLexer(codePointCharStream); | |
TokenStream tokens = new CommonTokenStream(lexer); | |
SomeLanguageParser parser = new SomeLanguageParser(tokens); | |
parser.classDeclaration().children.forEach(System.out::println); | |
} catch (RecognitionException e) { | |
throw new IllegalStateException("Recognition exception is never thrown, only declared."); | |
} | |
} |
g4 file must be put under src/your/package/full/name/grammar-filename.g4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Must provide a sourceName as the second parameter in CharStreams.fromString()