本文整理汇总了Java中org.antlr.v4.parse.ANTLRParser.ASSIGN属性的典型用法代码示例。如果您正苦于以下问题:Java ANTLRParser.ASSIGN属性的具体用法?Java ANTLRParser.ASSIGN怎么用?Java ANTLRParser.ASSIGN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.antlr.v4.parse.ANTLRParser
的用法示例。
在下文中一共展示了ANTLRParser.ASSIGN属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LabelElementPair
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;
}
}
}
示例2: findOptionValueAST
/** 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;
}
示例3: setNodeOptions
/** Given ^(TOKEN_REF ^(OPTIONS ^(ELEMENT_OPTIONS (= assoc right))))
* set option assoc=right in TOKEN_REF.
*/
public static void setNodeOptions(GrammarAST node, GrammarAST options) {
if ( options==null ) return;
GrammarASTWithOptions t = (GrammarASTWithOptions)node;
if ( t.getChildCount()==0 || options.getChildCount()==0 ) return;
for (Object o : options.getChildren()) {
GrammarAST c = (GrammarAST)o;
if ( c.getType()==ANTLRParser.ASSIGN ) {
t.setOption(c.getChild(0).getText(), (GrammarAST)c.getChild(1));
}
else {
t.setOption(c.getText(), null); // no arg such as ID<VarNodeType>
}
}
}
示例4: grammarSymbolCausesIssueInGeneratedCode
public boolean grammarSymbolCausesIssueInGeneratedCode(GrammarAST idNode) {
switch (idNode.getParent().getType()) {
case ANTLRParser.ASSIGN:
switch (idNode.getParent().getParent().getType()) {
case ANTLRParser.ELEMENT_OPTIONS:
case ANTLRParser.OPTIONS:
return false;
default:
break;
}
break;
case ANTLRParser.AT:
case ANTLRParser.ELEMENT_OPTIONS:
return false;
case ANTLRParser.LEXER_ACTION_CALL:
if (idNode.getChildIndex() == 0) {
// first child is the command name which is part of the ANTLR language
return false;
}
// arguments to the command should be checked
break;
default:
break;
}
return visibleGrammarSymbolCausesIssueInGeneratedCode(idNode);
}
示例5: LeftRecursiveRuleFunction
public LeftRecursiveRuleFunction(OutputModelFactory factory, LeftRecursiveRule r) {
super(factory, r);
CodeGenerator gen = factory.getGenerator();
// Since we delete x=lr, we have to manually add decls for all labels
// on left-recur refs to proper structs
for (Pair<GrammarAST,String> pair : r.leftRecursiveRuleRefLabels) {
GrammarAST idAST = pair.a;
String altLabel = pair.b;
String label = idAST.getText();
GrammarAST rrefAST = (GrammarAST)idAST.getParent().getChild(1);
if ( rrefAST.getType() == ANTLRParser.RULE_REF ) {
Rule targetRule = factory.getGrammar().getRule(rrefAST.getText());
String ctxName = gen.getTarget().getRuleFunctionContextStructName(targetRule);
RuleContextDecl d;
if (idAST.getParent().getType() == ANTLRParser.ASSIGN) {
d = new RuleContextDecl(factory, label, ctxName);
}
else {
d = new RuleContextListDecl(factory, label, ctxName);
}
StructDecl struct = ruleCtx;
if ( altLabelCtxs!=null ) {
StructDecl s = altLabelCtxs.get(altLabel);
if ( s!=null ) struct = s; // if alt label, use subctx
}
struct.addDecl(d); // stick in overall rule's ctx
}
}
}
示例6: getElementOffset
private int getElementOffset(CommonTree tree) {
switch (tree.getType()) {
case ANTLRParser.MODE:
case ANTLRParser.ASSIGN:
case ANTLRParser.RULE:
if (tree.getChildCount() > 0 && tree.getChild(0) instanceof CommonTree) {
CommonTree child = (CommonTree)tree.getChild(0);
if (child.getToken() instanceof CommonToken) {
CommonToken token = (CommonToken)child.getToken();
return token.getStartIndex();
}
}
break;
case ANTLRParser.ID:
break;
default:
throw new UnsupportedOperationException();
}
if (tree.getToken() instanceof CommonToken) {
return ((CommonToken)tree.getToken()).getStartIndex();
}
return 0;
}