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 class
GrammarSpelunker.Scanner
Strip comments and then return stream of words and tokens {';', ':', '{', '}'}
-
Field Summary
Fields Modifier and Type Field Description protected String
grammarFileName
protected String
grammarModifier
protected String
grammarName
protected List<String>
importedGrammars
protected String
inputDirectory
protected String
language
protected GrammarSpelunker.Scanner
scanner
protected String
token
protected String
tokenVocab
-
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 String
getGrammarModifier()
String
getGrammarName()
List<String>
getImportedGrammars()
String
getLanguage()
String
getTokenVocab()
protected void
grammarHeader()
protected void
imports()
static void
main(String[] args)
Tester; Give grammar filename as argprotected void
match(String expecting)
protected void
options()
void
parse()
-
-
-
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
-
-