public class Grammar extends Object implements AttributeResolver
Modifier and Type | Field and Description |
---|---|
static Set<String> |
actionOptions |
GrammarRootAST |
ast |
ATN |
atn
The ATN that represents the grammar with edges labelled with tokens
or epsilon.
|
static String |
AUTO_GENERATED_TOKEN_NAME_PREFIX |
Map<Integer,DFA> |
decisionDFAs |
List<IntervalSet[]> |
decisionLOOK |
static Set<String> |
doNotCopyOptionsToLexer |
String |
fileName |
static String |
GRAMMAR_FROM_STRING_NAME |
static Map<String,AttributeDict> |
grammarAndLabelRefTypeToScope |
LexerGrammar |
implicitLexer
Was this parser grammar created from a COMBINED grammar? If so,
this is what we extracted.
|
List<Grammar> |
importedGrammars |
List<Rule> |
indexToRule |
LinkedHashMap<ActionAST,Integer> |
lexerActions
Tracks all user lexer actions in all alternatives of all rules.
|
static Set<String> |
LexerBlockOptions |
static Set<String> |
lexerOptions |
String |
name |
Map<String,ActionAST> |
namedActions
Map a name to an action.
|
Grammar |
originalGrammar
If this is an extracted/implicit lexer, we point at original grammar
|
Grammar |
parent
If we're imported, who imported us? If null, implies grammar is root
|
static Set<String> |
ParserBlockOptions |
static Set<String> |
parserOptions |
static Set<String> |
ruleOptions |
static Set<String> |
ruleRefOptions
Legal options for rule refs like id
|
OrderedHashMap<String,Rule> |
rules
All rules defined in this specific grammar, not imported.
|
static Set<String> |
semPredOptions |
LinkedHashMap<PredAST,Integer> |
sempreds
All sempreds found in grammar; maps tree node to sempred index;
sempred index is 0..n-1
|
Map<String,Integer> |
stringLiteralToTypeMap
Map token literals like "while" to its token type.
|
String |
text |
Map<String,Integer> |
tokenNameToTypeMap
Map token like ID (but not literals like "while") to its token type
|
static Set<String> |
tokenOptions
Legal options for terminal refs like ID
|
org.antlr.runtime.TokenStream |
tokenStream
Track stream used to create this grammar
|
Tool |
tool |
List<String> |
typeToStringLiteralList
Reverse index for stringLiteralToTypeMap.
|
List<String> |
typeToTokenList
Map a token type to its token name.
|
Constructor and Description |
---|
Grammar(String grammarText)
For testing
|
Grammar(String grammarText,
ANTLRToolListener listener)
For testing
|
Grammar(String grammarText,
LexerGrammar tokenVocabSource) |
Grammar(String fileName,
String grammarText)
For testing; builds trees, does sem anal
|
Grammar(String fileName,
String grammarText,
ANTLRToolListener listener)
For testing; builds trees, does sem anal
|
Grammar(String fileName,
String grammarText,
Grammar tokenVocabSource,
ANTLRToolListener listener)
For testing; builds trees, does sem anal
|
Grammar(Tool tool,
GrammarRootAST ast) |
Modifier and Type | Method and Description |
---|---|
LexerInterpreter |
createLexerInterpreter(CharStream input) |
ParserInterpreter |
createParserInterpreter(TokenStream tokenStream) |
protected static boolean |
defAlias(GrammarAST r,
String pattern,
org.antlr.runtime.tree.TreeWizard wiz,
List<Pair<GrammarAST,GrammarAST>> lexerRuleToStringLiteral) |
void |
defineAction(GrammarAST atAST) |
boolean |
defineRule(Rule r)
Define the specified rule in the grammar.
|
int |
defineStringLiteral(String lit) |
int |
defineStringLiteral(String lit,
int ttype) |
int |
defineTokenAlias(String name,
String lit) |
int |
defineTokenName(String name) |
int |
defineTokenName(String name,
int ttype) |
IntSet |
getAllCharValues()
Return min to max char as defined by the target.
|
List<Grammar> |
getAllImportedGrammars()
Get list of all imports from all grammars in the delegate subtree of g.
|
String |
getDefaultActionScope()
Given a grammar type, what should be the default action scope?
If I say @members in a COMBINED grammar, for example, the
default scope should be "parser".
|
List<Grammar> |
getGrammarAncestors()
Return list of imported grammars from root down to our parent.
|
static String |
getGrammarTypeToFileNameSuffix(int type) |
LexerGrammar |
getImplicitLexer()
Get delegates below direct delegates of g
public List
|
Grammar |
getImportedGrammar(String name)
Return grammar directly imported by this grammar
|
List<Grammar> |
getImportedGrammars() |
int |
getMaxCharValue()
What is the max char value possible for this grammar's target? Use
unicode max if no target defined.
|
int |
getMaxTokenType()
How many token types have been allocated so far?
|
int |
getNewTokenType()
Return a new unique integer in the token type space
|
String |
getOptionString(String key) |
Grammar |
getOutermostGrammar()
Return the grammar that imported us and our parents.
|
String |
getRecognizerName()
Get the name of the generated recognizer; may or may not be same
as grammar name.
|
Rule |
getRule(int index) |
Rule |
getRule(String name) |
Rule |
getRule(String grammarName,
String ruleName) |
String[] |
getRuleNames() |
static List<Pair<GrammarAST,GrammarAST>> |
getStringLiteralAliasesFromLexerRules(GrammarRootAST ast)
Return list of (TOKEN_NAME node, 'literal' node) pairs
|
String |
getStringLiteralLexerRuleName(String lit) |
Set<String> |
getStringLiterals() |
String |
getTokenDisplayName(int ttype)
Given a token type, get a meaningful name for it such as the ID
or string literal.
|
String[] |
getTokenDisplayNames() |
List<String> |
getTokenDisplayNames(IntegerList types) |
String[] |
getTokenNames() |
org.antlr.runtime.TokenStream |
getTokenStream() |
int |
getTokenType(String token) |
IntSet |
getTokenTypes()
Return a set of all possible token or char types for this grammar
|
int |
getType() |
String |
getTypeString() |
void |
importTokensFromTokensFile() |
void |
importVocab(Grammar importG) |
protected void |
initTokenSymbolTables() |
boolean |
isCombined() |
boolean |
isLexer() |
boolean |
isParser() |
static boolean |
isTokenName(String id)
Is id a valid token name? Does id start with an uppercase letter?
|
static Grammar |
load(String fileName)
convenience method for Tool.loadGrammar()
|
void |
loadImportedGrammars() |
boolean |
resolvesToAttributeDict(String x,
ActionAST node) |
boolean |
resolvesToLabel(String x,
ActionAST node) |
boolean |
resolvesToListLabel(String x,
ActionAST node) |
boolean |
resolvesToToken(String x,
ActionAST node) |
Attribute |
resolveToAttribute(String x,
ActionAST node) |
Attribute |
resolveToAttribute(String x,
String y,
ActionAST node) |
void |
setLookaheadDFA(int decision,
DFA lookaheadDFA) |
static void |
setNodeOptions(GrammarAST node,
GrammarAST options)
Given ^(TOKEN_REF ^(OPTIONS ^(ELEMENT_OPTIONS (= assoc right))))
set option assoc=right in TOKEN_REF.
|
void |
setTokenForType(int ttype,
String text) |
boolean |
undefineRule(Rule r)
Undefine the specified rule from this
Grammar instance. |
public static final String GRAMMAR_FROM_STRING_NAME
public static final Map<String,AttributeDict> grammarAndLabelRefTypeToScope
public String name
public GrammarRootAST ast
@NotNull public final org.antlr.runtime.TokenStream tokenStream
public String text
public String fileName
public LexerGrammar implicitLexer
public Grammar originalGrammar
public Grammar parent
public OrderedHashMap<String,Rule> rules
public ATN atn
public List<IntervalSet[]> decisionLOOK
public Map<String,Integer> tokenNameToTypeMap
public Map<String,Integer> stringLiteralToTypeMap
public List<String> typeToStringLiteralList
public List<String> typeToTokenList
public Map<String,ActionAST> namedActions
public LinkedHashMap<ActionAST,Integer> lexerActions
public LinkedHashMap<PredAST,Integer> sempreds
public static final String AUTO_GENERATED_TOKEN_NAME_PREFIX
public Grammar(Tool tool, @NotNull GrammarRootAST ast)
public Grammar(String grammarText) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
public Grammar(String grammarText, LexerGrammar tokenVocabSource) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
public Grammar(String grammarText, ANTLRToolListener listener) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
public Grammar(String fileName, String grammarText) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
public Grammar(String fileName, String grammarText, @Nullable ANTLRToolListener listener) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
public Grammar(String fileName, String grammarText, Grammar tokenVocabSource, @Nullable ANTLRToolListener listener) throws org.antlr.runtime.RecognitionException
org.antlr.runtime.RecognitionException
protected void initTokenSymbolTables()
public void loadImportedGrammars()
public void defineAction(GrammarAST atAST)
public boolean defineRule(@NotNull Rule r)
Rule.index
according to the ruleNumber
field, and adds
the Rule
instance to rules
and indexToRule
.r
- The rule to define in the grammar.true
if the rule was added to the Grammar
instance; otherwise, false
if a rule with this name already
existed in the grammar instance.public boolean undefineRule(@NotNull Rule r)
Grammar
instance. The
instance r
is removed from rules
and
indexToRule
. This method updates the Rule.index
field
for all rules defined after r
, and decrements ruleNumber
in preparation for adding new rules.
This method does nothing if the current Grammar
does not contain
the instance r
at index r.index
in indexToRule
.
r
- true
if the rule was removed from the Grammar
instance; otherwise, false
if the specified rule was not defined
in the grammar.public Rule getRule(int index)
public List<Grammar> getAllImportedGrammars()
public LexerGrammar getImplicitLexer()
public List<Grammar> getGrammarAncestors()
public Grammar getOutermostGrammar()
public String getRecognizerName()
public Grammar getImportedGrammar(String name)
public int getTokenType(String token)
public String getTokenDisplayName(int ttype)
public String[] getRuleNames()
public List<String> getTokenDisplayNames(IntegerList types)
public String[] getTokenNames()
public String[] getTokenDisplayNames()
public int getMaxCharValue()
public IntSet getTokenTypes()
public IntSet getAllCharValues()
public int getMaxTokenType()
public int getNewTokenType()
public void importTokensFromTokensFile()
public void importVocab(Grammar importG)
public int defineTokenName(String name)
public int defineTokenName(String name, int ttype)
public int defineStringLiteral(String lit)
public int defineStringLiteral(String lit, int ttype)
public void setTokenForType(int ttype, String text)
public Attribute resolveToAttribute(String x, ActionAST node)
resolveToAttribute
in interface AttributeResolver
public Attribute resolveToAttribute(String x, String y, ActionAST node)
resolveToAttribute
in interface AttributeResolver
public boolean resolvesToLabel(String x, ActionAST node)
resolvesToLabel
in interface AttributeResolver
public boolean resolvesToListLabel(String x, ActionAST node)
resolvesToListLabel
in interface AttributeResolver
public boolean resolvesToToken(String x, ActionAST node)
resolvesToToken
in interface AttributeResolver
public boolean resolvesToAttributeDict(String x, ActionAST node)
resolvesToAttributeDict
in interface AttributeResolver
public String getDefaultActionScope()
public int getType()
public org.antlr.runtime.TokenStream getTokenStream()
public boolean isLexer()
public boolean isParser()
public boolean isCombined()
public static boolean isTokenName(String id)
public String getTypeString()
public static String getGrammarTypeToFileNameSuffix(int type)
public static void setNodeOptions(GrammarAST node, GrammarAST options)
public static List<Pair<GrammarAST,GrammarAST>> getStringLiteralAliasesFromLexerRules(GrammarRootAST ast)
protected static boolean defAlias(GrammarAST r, String pattern, org.antlr.runtime.tree.TreeWizard wiz, List<Pair<GrammarAST,GrammarAST>> lexerRuleToStringLiteral)
public void setLookaheadDFA(int decision, DFA lookaheadDFA)
public LexerInterpreter createLexerInterpreter(CharStream input)
public ParserInterpreter createParserInterpreter(TokenStream tokenStream)
Copyright © 1992–2014 ANTLR. All rights reserved.