Package org.antlr.tool
Class GrammarSpelunker
- java.lang.Object
-
- org.antlr.tool.GrammarSpelunker
-
public class GrammarSpelunker extends Object
Load a grammar file and scan it just until we learn a few items of interest. Currently: name, type, imports, tokenVocab, language option. GrammarScanner (at bottom of this class) converts grammar to stuff like: grammar Java ; options { backtrack true memoize true } import JavaDecl JavaAnnotations JavaExpr ; ... : ... First ':' or '@' indicates we can stop looking for imports/options. Then we just grab interesting grammar properties.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGrammarSpelunker.ScannerStrip comments and then return stream of words and tokens {';', ':', '{', '}'}
-
Field Summary
Fields Modifier and Type Field Description protected StringgrammarFileNameprotected StringgrammarModifierprotected StringgrammarNameprotected List<String>importedGrammarsprotected StringinputDirectoryprotected Stringlanguageprotected GrammarSpelunker.Scannerscannerprotected Stringtokenprotected StringtokenVocab
-
Constructor Summary
Constructors Constructor Description GrammarSpelunker(String inputDirectory, String grammarFileName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetGrammarModifier()StringgetGrammarName()List<String>getImportedGrammars()StringgetLanguage()StringgetTokenVocab()protected voidgrammarHeader()protected voidimports()static voidmain(String[] args)Tester; Give grammar filename as argprotected voidmatch(String expecting)protected voidoptions()voidparse()
-
-
-
Field Detail
-
grammarFileName
protected String grammarFileName
-
token
protected String token
-
scanner
protected GrammarSpelunker.Scanner scanner
-
grammarModifier
protected String grammarModifier
-
grammarName
protected String grammarName
-
tokenVocab
protected String tokenVocab
-
language
protected String language
-
inputDirectory
protected String inputDirectory
-
-
Method Detail
-
match
protected void match(String expecting) throws IOException
- Throws:
IOException
-
parse
public void parse() throws IOException- Throws:
IOException
-
grammarHeader
protected void grammarHeader() throws IOException- Throws:
IOException
-
options
protected void options() throws IOException- Throws:
IOException
-
imports
protected void imports() throws IOException- Throws:
IOException
-
getGrammarModifier
public String getGrammarModifier()
-
getGrammarName
public String getGrammarName()
-
getTokenVocab
public String getTokenVocab()
-
getLanguage
public String getLanguage()
-
main
public static void main(String[] args) throws IOException
Tester; Give grammar filename as arg- Throws:
IOException
-
-