本文整理汇总了Java中org.antlr.v4.runtime.ParserRuleContext类的典型用法代码示例。如果您正苦于以下问题:Java ParserRuleContext类的具体用法?Java ParserRuleContext怎么用?Java ParserRuleContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserRuleContext类属于org.antlr.v4.runtime包,在下文中一共展示了ParserRuleContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValidBooleanValue
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
/**
* Validates boolean value.
*
* @param booleanValue value to be validated
* @param yangConstruct yang construct for creating error message
* @param ctx context object of the grammar rule
* @return boolean value either true or false
*/
public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct,
ParserRuleContext ctx) {
String value = removeQuotesAndHandleConcat(booleanValue);
if (value.equals(TRUE)) {
return true;
} else if (value.equals(FALSE)) {
return false;
} else {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(yangConstruct) + " value " + value + " is not " +
"valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
}
示例2: DefUseVisitor
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public DefUseVisitor(int iter, JavaClass[] classInfos,
DataDependenceGraph ddg, Map<ParserRuleContext, Object> pdNodes) {
Logger.log("FILE IS: " + currentFile);
this.ddg = ddg;
changed = false;
iteration = iter;
analysisVisit = false;
this.pdNodes = pdNodes;
this.classInfos = classInfos;
defList = new LinkedHashSet<>();
useList = new LinkedHashSet<>();
selfFlowList = new LinkedHashSet<>();
activeClasses = new ArrayDeque<>();
methodDefInfo = null;
methodParams = new JavaField[0];
localVars = new ArrayList<>();
}
示例3: IfLet
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public IfLet(ParserRuleContext ctx, Visitor visitor) {
SwiftParser.Condition_clauseContext conditionClause = ctx instanceof SwiftParser.If_statementContext ? ((SwiftParser.If_statementContext)ctx).condition_clause() : ((SwiftParser.Guard_statementContext)ctx).condition_clause();
if(!(WalkerUtil.isDirectDescendant(SwiftParser.Optional_binding_conditionContext.class, conditionClause))) return;
ArrayList<ParserRuleContext> ifLets = new ArrayList<ParserRuleContext>();
ifLets.add(conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_head());
if(conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_continuation_list() != null) {
List<SwiftParser.Optional_binding_continuationContext> moreIfLets = conditionClause.condition_list().condition(0).optional_binding_condition().optional_binding_continuation_list().optional_binding_continuation();
for(int i = 0; i < moreIfLets.size(); i++) ifLets.add(moreIfLets.get(i));
}
/*for(int i = 0; i < ifLets.size(); i++) {
String varName = visitor.visitWithoutTerminals(ifLets.get(i) instanceof SwiftParser.Optional_binding_headContext ? ((SwiftParser.Optional_binding_headContext)ifLets.get(i)).pattern() : ((SwiftParser.Optional_binding_continuationContext)ifLets.get(i)).pattern()).trim();
Expression varVal = new Expression((ifLets.get(i) instanceof SwiftParser.Optional_binding_headContext ? ((SwiftParser.Optional_binding_headContext)ifLets.get(i)).initializer() : ((SwiftParser.Optional_binding_continuationContext)ifLets.get(i)).initializer()).expression(), null, visitor);
varNames.add(varName);
varVals.add(varVal.code);
varTypes.add(varVal.type);
}*/
}
示例4: getOriginalCodeText
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
/**
* Get the original program text for the given parser-rule context.
* This is required for preserving whitespaces.
*/
private String getOriginalCodeText(ParserRuleContext ctx) {
int start = ctx.start.getStartIndex();
int stop = ctx.stop.getStopIndex();
Interval interval = new Interval(start, stop);
return ctx.start.getInputStream().getText(interval);
}
示例5: testEquals
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
/**
* Test of equals method, of class TreeNode.
*
* @throws java.io.IOException
*/
@Test
public void testEquals() throws IOException {
Object object = null;
TreeNode instance = new TreeNode(new ParserRuleContext());
boolean expResult = false;
boolean result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
object = new Object();
expResult = false;
result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource(SAMPLE_CLASS_PATH).getFile());
byte[] encoded = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
String code = new String(encoded, Charset.defaultCharset());
Forest forest1 = TreeViewGenerator.generate(code);
Forest forest2 = TreeViewGenerator.generate(code);
expResult = true;
object = forest1.getTree(0).getRoot();
instance = forest2.getTree(0).getRoot();
result = instance.equals(object);
assertEquals("equals method, of class TreeNode's expected result is wrong.", expResult,
result);
}
示例6: Location
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public Location(ParserRuleContext parserRuleContext) {
Token start = parserRuleContext.getStart();
this.start = start.getStartIndex();
Token stop = parserRuleContext.getStop();
end = stop.getStopIndex();
line = start.getLine();
}
示例7: replaceLabelAddress
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
private void replaceLabelAddress(ParserRuleContext ctx, TerminalNode terminalNode) {
if(!secondPass) {
return;
}
String label = terminalNode.getText();
if(!definedBranches.containsKey(label)) {
throw new LabelError("\"" + label + "\" is not defined.");
}
int lineNumber = ctx.start.getLine() - 1;
String temp = new String(code[lineNumber]);
String address = Integer.toString(definedBranches.get(label));
temp = temp.replace(label, address);
code[lineNumber] = temp;
}
示例8: calculateLiteralValue
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public static Long calculateLiteralValue(
String calculation,
Map<String, Long> inputs)
{
try {
ParserRuleContext tree = parseTypeCalculation(calculation);
CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs);
BigInteger result = visitor.visit(tree);
return result.longValueExact();
}
catch (StackOverflowError e) {
throw new ParsingException("Type calculation is too large (stack overflow while parsing)");
}
}
示例9: visit
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
private <T> List<T> visit(List<? extends ParserRuleContext> contexts, Class<T> clazz)
{
return contexts.stream()
.map(this::visit)
.map(clazz::cast)
.collect(toList());
}
示例10: ControlFlowVisitor
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public ControlFlowVisitor(ControlFlowGraph cfg, String propKey, Map<ParserRuleContext, Object> ctxProps) {
preNodes = new ArrayDeque<>();
preEdges = new ArrayDeque<>();
loopBlocks = new ArrayDeque<>();
labeledBlocks = new ArrayList<>();
tryBlocks = new ArrayDeque<>();
casesQueue = new ArrayDeque<>();
classNames = new ArrayDeque<>();
dontPop = false;
this.cfg = cfg;
//
this.propKey = propKey;
contexutalProperties = ctxProps;
}
示例11: parseTypeCalculation
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
private static ParserRuleContext parseTypeCalculation(String calculation)
{
TypeCalculationLexer lexer = new TypeCalculationLexer(new CaseInsensitiveStream(new ANTLRInputStream(calculation)));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
TypeCalculationParser parser = new TypeCalculationParser(tokenStream);
lexer.removeErrorListeners();
lexer.addErrorListener(ERROR_LISTENER);
parser.removeErrorListeners();
parser.addErrorListener(ERROR_LISTENER);
ParserRuleContext tree;
try {
// first, try parsing with potentially faster SLL mode
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
tree = parser.typeCalculation();
}
catch (ParseCancellationException ex) {
// if we fail, parse with LL mode
tokenStream.reset(); // rewind input stream
parser.reset();
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
tree = parser.typeCalculation();
}
return tree;
}
示例12: createAndCopy
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
protected EObject createAndCopy(final EObject eObject, final ParserRuleContext ruleContext) {
final EClass eClass = eObject.eClass();
final EObject newEObject = create(eClass, ruleContext);
final Consumer<EAttribute> copyAttribute = attribute -> newEObject.eSet(attribute, eObject.eGet(attribute));
eClass.getEAllAttributes().forEach(copyAttribute);
return newEObject;
}
示例13: TreeNode
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public TreeNode(ParserRuleContext context) {
this.children = new ArrayList<>(8);
this.context = context;
}
示例14: getContext
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
public ParserRuleContext getContext() {
return this.context;
}
示例15: getErrorContext
import org.antlr.v4.runtime.ParserRuleContext; //导入依赖的package包/类
/**
* @return the error context, can be {@code null}
*/
public ParserRuleContext getErrorContext() {
return ctx;
}