本文整理汇总了Java中org.antlr.v4.parse.ANTLRParser类的典型用法代码示例。如果您正苦于以下问题:Java ANTLRParser类的具体用法?Java ANTLRParser怎么用?Java ANTLRParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ANTLRParser类属于org.antlr.v4.parse包,在下文中一共展示了ANTLRParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getAltLabel
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
/** Walk ancestors of this node until we find ALT with
* alt!=null or leftRecursiveAltInfo!=null. Then grab label if any.
* If not a rule element, just returns null.
*/
public String getAltLabel() {
List<? extends Tree> ancestors = this.getAncestors();
if ( ancestors==null ) return null;
for (int i=ancestors.size()-1; i>=0; i--) {
GrammarAST p = (GrammarAST)ancestors.get(i);
if ( p.getType()== ANTLRParser.ALT ) {
AltAST a = (AltAST)p;
if ( a.altLabel!=null ) return a.altLabel.getText();
if ( a.leftRecursiveAltInfo!=null ) {
return a.leftRecursiveAltInfo.altLabel;
}
}
}
return null;
}
开发者ID:antlr,项目名称:codebuff,代码行数:20,代码来源:GrammarAST.java
示例2: LabelElementPair
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public LabelElementPair(Grammar g, GrammarAST label, GrammarAST element, int labelOp) {
this.label = label;
this.element = element;
// compute general case for label type
if ( element.getFirstDescendantWithType(tokenTypeForTokens)!=null ) {
if ( labelOp==ANTLRParser.ASSIGN ) type = LabelType.TOKEN_LABEL;
else type = LabelType.TOKEN_LIST_LABEL;
}
else if ( element.getFirstDescendantWithType(ANTLRParser.RULE_REF)!=null ) {
if ( labelOp==ANTLRParser.ASSIGN ) type = LabelType.RULE_LABEL;
else type = LabelType.RULE_LIST_LABEL;
}
// now reset if lexer and string
if ( g.isLexer() ) {
if ( element.getFirstDescendantWithType(ANTLRParser.STRING_LITERAL)!=null ) {
if ( labelOp==ANTLRParser.ASSIGN ) type = LabelType.LEXER_STRING_LABEL;
}
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:LabelElementPair.java
示例3: _createATN
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
protected void _createATN(Collection<Rule> rules) {
createRuleStartAndStopATNStates();
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
for (Rule r : rules) {
// find rule's block
GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
ATNBuilder b = new ATNBuilder(nodes,this);
try {
setCurrentRuleName(r.name);
Handle h = b.ruleBlock(null);
rule(r.ast, r.name, h);
}
catch (RecognitionException re) {
ErrorManager.fatalInternalError("bad grammar AST structure", re);
}
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:20,代码来源:ParserATNFactory.java
示例4: set
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public List<SrcOp> set(GrammarAST setAST, GrammarAST labelAST, boolean invert) {
MatchSet matchOp;
if ( invert ) matchOp = new MatchNotSet(this, setAST);
else matchOp = new MatchSet(this, setAST);
if ( labelAST!=null ) {
String label = labelAST.getText();
RuleFunction rf = getCurrentRuleFunction();
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
defineImplicitLabel(setAST, matchOp);
TokenListDecl l = getTokenListLabelDecl(label);
rf.addContextDecl(setAST.getAltLabel(), l);
}
else {
Decl d = getTokenLabelDecl(label);
matchOp.labels.add(d);
rf.addContextDecl(setAST.getAltLabel(), d);
}
}
if ( controller.needsImplicitLabel(setAST, matchOp) ) defineImplicitLabel(setAST, matchOp);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(matchOp, labelAST);
return list(matchOp, listLabelOp);
}
开发者ID:antlr,项目名称:codebuff,代码行数:24,代码来源:ParserFactory.java
示例5: wildcard
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public List<SrcOp> wildcard(GrammarAST ast, GrammarAST labelAST) {
Wildcard wild = new Wildcard(this, ast);
// TODO: dup with tokenRef
if ( labelAST!=null ) {
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
wild.labels.add(d);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), d);
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
TokenListDecl l = getTokenListLabelDecl(label);
getCurrentRuleFunction().addContextDecl(ast.getAltLabel(), l);
}
}
if ( controller.needsImplicitLabel(ast, wild) ) defineImplicitLabel(ast, wild);
AddToLabelList listLabelOp = getAddToListOpIfListLabelPresent(wild, labelAST);
return list(wild, listLabelOp);
}
开发者ID:antlr,项目名称:codebuff,代码行数:19,代码来源:ParserFactory.java
示例6: getChoiceBlock
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts, GrammarAST labelAST) {
int decision = ((DecisionState)blkAST.atnState).decision;
Choice c;
if ( !g.tool.force_atn && AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) {
c = getLL1ChoiceBlock(blkAST, alts);
}
else {
c = getComplexChoiceBlock(blkAST, alts);
}
if ( labelAST!=null ) { // for x=(...), define x or x_list
String label = labelAST.getText();
Decl d = getTokenLabelDecl(label);
c.label = d;
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), d);
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
String listLabel = gen.getTarget().getListLabel(label);
TokenListDecl l = new TokenListDecl(this, listLabel);
getCurrentRuleFunction().addContextDecl(labelAST.getAltLabel(), l);
}
}
return c;
}
开发者ID:antlr,项目名称:codebuff,代码行数:26,代码来源:ParserFactory.java
示例7: getEBNFBlock
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
if (!g.tool.force_atn) {
int decision;
if ( ebnfRoot.getType()==ANTLRParser.POSITIVE_CLOSURE ) {
decision = ((PlusLoopbackState)ebnfRoot.atnState).decision;
}
else if ( ebnfRoot.getType()==ANTLRParser.CLOSURE ) {
decision = ((StarLoopEntryState)ebnfRoot.atnState).decision;
}
else {
decision = ((DecisionState)ebnfRoot.atnState).decision;
}
if ( AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) {
return getLL1EBNFBlock(ebnfRoot, alts);
}
}
return getComplexEBNFBlock(ebnfRoot, alts);
}
开发者ID:antlr,项目名称:codebuff,代码行数:22,代码来源:ParserFactory.java
示例8: getLL1EBNFBlock
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
int ebnf = 0;
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
Choice c = null;
switch ( ebnf ) {
case ANTLRParser.OPTIONAL :
if ( alts.size()==1 ) c = new LL1OptionalBlockSingleAlt(this, ebnfRoot, alts);
else c = new LL1OptionalBlock(this, ebnfRoot, alts);
break;
case ANTLRParser.CLOSURE :
if ( alts.size()==1 ) c = new LL1StarBlockSingleAlt(this, ebnfRoot, alts);
else c = getComplexEBNFBlock(ebnfRoot, alts);
break;
case ANTLRParser.POSITIVE_CLOSURE :
if ( alts.size()==1 ) c = new LL1PlusBlockSingleAlt(this, ebnfRoot, alts);
else c = getComplexEBNFBlock(ebnfRoot, alts);
break;
}
return c;
}
开发者ID:antlr,项目名称:codebuff,代码行数:22,代码来源:ParserFactory.java
示例9: getComplexEBNFBlock
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public Choice getComplexEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
int ebnf = 0;
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
Choice c = null;
switch ( ebnf ) {
case ANTLRParser.OPTIONAL :
c = new OptionalBlock(this, ebnfRoot, alts);
break;
case ANTLRParser.CLOSURE :
c = new StarBlock(this, ebnfRoot, alts);
break;
case ANTLRParser.POSITIVE_CLOSURE :
c = new PlusBlock(this, ebnfRoot, alts);
break;
}
return c;
}
开发者ID:antlr,项目名称:codebuff,代码行数:19,代码来源:ParserFactory.java
示例10: buildNormalRuleFunction
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public void buildNormalRuleFunction(Rule r, RuleFunction function) {
CodeGenerator gen = delegate.getGenerator();
// TRIGGER factory functions for rule alts, elements
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(r.ast.token.getInputStream());
GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
walker = new SourceGenTriggers(nodes, this);
try {
// walk AST of rule alts/elements
function.code = DefaultOutputModelFactory.list(walker.block(null, null));
function.hasLookaheadBlock = walker.hasLookaheadBlock;
}
catch (org.antlr.runtime.RecognitionException e){
e.printStackTrace(System.err);
}
function.ctxType = gen.getTarget().getRuleFunctionContextStructName(function);
function.postamble = rulePostamble(function, r);
}
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:OutputModelController.java
示例11: getRuleDependencies
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public static Map<Rule, Set<Rule>> getRuleDependencies(Grammar g, Collection<Rule> rules) {
Map<Rule, Set<Rule>> dependencies = new HashMap<Rule, Set<Rule>>();
for (Rule r : rules) {
List<GrammarAST> tokenRefs = r.ast.getNodesWithType(ANTLRParser.TOKEN_REF);
for (GrammarAST tref : tokenRefs) {
Set<Rule> calls = dependencies.get(r);
if ( calls==null ) {
calls = new HashSet<Rule>();
dependencies.put(r, calls);
}
calls.add(g.getRule(tref.getText()));
}
}
return dependencies;
}
开发者ID:antlr,项目名称:codebuff,代码行数:18,代码来源:UseDefAnalyzer.java
示例12: discoverLexerRule
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public void discoverLexerRule(RuleAST rule, GrammarAST ID, List<GrammarAST> modifiers,
GrammarAST block)
{
checkInvalidRuleDef(ID.token);
if (modifiers != null) {
for (GrammarAST tree : modifiers) {
if (tree.getType() == ANTLRParser.FRAGMENT) {
inFragmentRule = true;
}
}
}
if (!inFragmentRule) {
nonFragmentRuleCount++;
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:19,代码来源:BasicSemanticChecks.java
示例13: checkImport
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
void checkImport(Token importID) {
Grammar delegate = g.getImportedGrammar(importID.getText());
if ( delegate==null ) return;
List<Integer> validDelegators = validImportTypes.get(delegate.getType());
if ( validDelegators!=null && !validDelegators.contains(g.getType()) ) {
g.tool.errMgr.grammarError(ErrorType.INVALID_IMPORT,
g.fileName,
importID,
g, delegate);
}
if ( g.isCombined() &&
(delegate.name.equals(g.name+Grammar.getGrammarTypeToFileNameSuffix(ANTLRParser.LEXER))||
delegate.name.equals(g.name+Grammar.getGrammarTypeToFileNameSuffix(ANTLRParser.PARSER))) )
{
g.tool.errMgr.grammarError(ErrorType.IMPORT_NAME_CLASH,
g.fileName,
importID,
g, delegate);
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:21,代码来源:BasicSemanticChecks.java
示例14: checkRuleArgs
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public void checkRuleArgs(Grammar g, List<GrammarAST> rulerefs) {
if ( rulerefs==null ) return;
for (GrammarAST ref : rulerefs) {
String ruleName = ref.getText();
Rule r = g.getRule(ruleName);
GrammarAST arg = (GrammarAST)ref.getFirstChildWithType(ANTLRParser.ARG_ACTION);
if ( arg!=null && (r==null || r.args==null) ) {
errMgr.grammarError(ErrorType.RULE_HAS_NO_ARGS,
g.fileName, ref.token, ruleName);
}
else if ( arg==null && (r!=null&&r.args!=null) ) {
errMgr.grammarError(ErrorType.MISSING_RULE_ARGS,
g.fileName, ref.token, ruleName);
}
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:18,代码来源:SymbolChecks.java
示例15: getUnusedParserRules
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public static Map<String,GrammarAST> getUnusedParserRules(Grammar g) {
if ( g.ast==null || g.isLexer() ) return null;
List<GrammarAST> ruleNodes = g.ast.getNodesWithTypePreorderDFS(IntervalSet.of(ANTLRParser.RULE_REF));
// in case of errors, we walk AST ourselves
// ANTLR's Grammar object might have bailed on rule defs etc...
Set<String> ruleRefs = new HashSet<String>();
Map<String,GrammarAST> ruleDefs = new HashMap<String,GrammarAST>();
for (GrammarAST x : ruleNodes) {
if ( x.getParent().getType()==ANTLRParser.RULE ) {
// System.out.println("def "+x);
ruleDefs.put(x.getText(), x);
}
else if ( x instanceof RuleRefAST ) {
RuleRefAST r = (RuleRefAST) x;
// System.out.println("ref "+r);
ruleRefs.add(r.getText());
}
}
ruleDefs.keySet().removeAll(ruleRefs);
return ruleDefs;
}
开发者ID:antlr,项目名称:intellij-plugin-v4,代码行数:22,代码来源:ANTLRv4ExternalAnnotator.java
示例16: createGrammar
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
@Override
public Grammar createGrammar(GrammarRootAST ast) {
final Grammar g;
LOGGER.debug("ast " + ast.getGrammarName());
if (ast.grammarType == ANTLRParser.LEXER) {
g = new InmemantlrLexerGrammar(this, ast);
} else {
g = new InmemantlrGrammar(this, ast);
}
// ensure each node has pointer to surrounding grammar
GrammarTransformPipeline.setGrammarPtr(g, ast);
return g;
}
开发者ID:julianthome,项目名称:inmemantlr,代码行数:16,代码来源:InmemantlrTool.java
示例17: findOptionValueAST
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
/** Manually get option node from tree; return null if no defined. */
public static GrammarAST findOptionValueAST(GrammarRootAST root, String option) {
GrammarAST options = (GrammarAST)root.getFirstChildWithType(ANTLRParser.OPTIONS);
if ( options!=null && options.getChildCount() > 0 ) {
for (Object o : options.getChildren()) {
GrammarAST c = (GrammarAST)o;
if ( c.getType() == ANTLRParser.ASSIGN &&
c.getChild(0).getText().equals(option) )
{
return (GrammarAST)c.getChild(1);
}
}
}
return null;
}
开发者ID:antlr,项目名称:codebuff,代码行数:16,代码来源:Tool.java
示例18: augmentTokensWithOriginalPosition
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public static void augmentTokensWithOriginalPosition(final Grammar g, GrammarAST tree) {
if ( tree==null ) return;
List<GrammarAST> optionsSubTrees = tree.getNodesWithType(ANTLRParser.ELEMENT_OPTIONS);
for (int i = 0; i < optionsSubTrees.size(); i++) {
GrammarAST t = optionsSubTrees.get(i);
CommonTree elWithOpt = t.parent;
if ( elWithOpt instanceof GrammarASTWithOptions ) {
Map<String, GrammarAST> options = ((GrammarASTWithOptions) elWithOpt).getOptions();
if ( options.containsKey(LeftRecursiveRuleTransformer.TOKENINDEX_OPTION_NAME) ) {
GrammarToken newTok = new GrammarToken(g, elWithOpt.getToken());
newTok.originalTokenIndex = Integer.valueOf(options.get(LeftRecursiveRuleTransformer.TOKENINDEX_OPTION_NAME).getText());
elWithOpt.token = newTok;
GrammarAST originalNode = g.ast.getNodeWithTokenIndex(newTok.getTokenIndex());
if (originalNode != null) {
// update the AST node start/stop index to match the values
// of the corresponding node in the original parse tree.
elWithOpt.setTokenStartIndex(originalNode.getTokenStartIndex());
elWithOpt.setTokenStopIndex(originalNode.getTokenStopIndex());
}
else {
// the original AST node could not be located by index;
// make sure to assign valid values for the start/stop
// index so toTokenString will not throw exceptions.
elWithOpt.setTokenStartIndex(newTok.getTokenIndex());
elWithOpt.setTokenStopIndex(newTok.getTokenIndex());
}
}
}
}
}
开发者ID:antlr,项目名称:codebuff,代码行数:33,代码来源:GrammarTransformPipeline.java
示例19: getLexerAction
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
public ActionAST getLexerAction() {
Tree blk = getFirstChildWithType(ANTLRParser.BLOCK);
if ( blk.getChildCount()==1 ) {
Tree onlyAlt = blk.getChild(0);
Tree lastChild = onlyAlt.getChild(onlyAlt.getChildCount()-1);
if ( lastChild.getType()==ANTLRParser.ACTION ) {
return (ActionAST)lastChild;
}
}
return null;
}
开发者ID:antlr,项目名称:codebuff,代码行数:12,代码来源:RuleAST.java
示例20: getDefaultActionScope
import org.antlr.v4.parse.ANTLRParser; //导入依赖的package包/类
/** 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".
*/
public String getDefaultActionScope() {
switch ( getType() ) {
case ANTLRParser.LEXER :
return "lexer";
case ANTLRParser.PARSER :
case ANTLRParser.COMBINED :
return "parser";
}
return null;
}
开发者ID:antlr,项目名称:codebuff,代码行数:15,代码来源:Grammar.java
注:本文中的org.antlr.v4.parse.ANTLRParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论