當前位置: 首頁>>代碼示例>>Java>>正文


Java ParserRuleContext類代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:ListenerUtil.java

示例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<>();
}
 
開發者ID:ghaffarian,項目名稱:progex,代碼行數:18,代碼來源:JavaDDGBuilder.java

示例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);
    }*/
}
 
開發者ID:marcelganczak,項目名稱:ts-swift-transpiler,代碼行數:19,代碼來源:ControlFlow.java

示例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);
}
 
開發者ID:ghaffarian,項目名稱:progex,代碼行數:11,代碼來源:JavaDDGBuilder.java

示例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);
}
 
開發者ID:miyagilabs,項目名稱:Blindfold,代碼行數:36,代碼來源:TreeNodeTest.java

示例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();
}
 
開發者ID:rockscript,項目名稱:rockscript,代碼行數:8,代碼來源:Location.java

示例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;
}
 
開發者ID:kasirgalabs,項目名稱:ETUmulator,代碼行數:15,代碼來源:Linker.java

示例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)");
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:15,代碼來源:TypeCalculation.java

示例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());
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:8,代碼來源:AstBuilder.java

示例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;
}
 
開發者ID:ghaffarian,項目名稱:progex,代碼行數:15,代碼來源:JavaCFGBuilder.java

示例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;
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:29,代碼來源:TypeCalculation.java

示例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;
}
 
開發者ID:vrapio,項目名稱:rest-modeling-framework,代碼行數:9,代碼來源:AbstractConstructor.java

示例13: TreeNode

import org.antlr.v4.runtime.ParserRuleContext; //導入依賴的package包/類
public TreeNode(ParserRuleContext context) {
    this.children = new ArrayList<>(8);
    this.context = context;
}
 
開發者ID:miyagilabs,項目名稱:Blindfold,代碼行數:5,代碼來源:TreeNode.java

示例14: getContext

import org.antlr.v4.runtime.ParserRuleContext; //導入依賴的package包/類
public ParserRuleContext getContext() {
    return this.context;
}
 
開發者ID:miyagilabs,項目名稱:Blindfold,代碼行數:4,代碼來源:TreeNode.java

示例15: getErrorContext

import org.antlr.v4.runtime.ParserRuleContext; //導入依賴的package包/類
/**
 * @return the error context, can be {@code null}
 */
public ParserRuleContext getErrorContext() {
	return ctx;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:7,代碼來源:ExpressionParsingException.java


注:本文中的org.antlr.v4.runtime.ParserRuleContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。