java类org.antlr.v4.runtime.Token的实例源码

CapitulatingErrorStrategy.java 文件源码 项目:rapidminer 阅读 26 收藏 0 点赞 0 评论 0
@Override
protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) {
    // change error message from default implementation
    TokenStream tokens = recognizer.getInputStream();
    String input;
    if (tokens != null) {
        if (e.getStartToken().getType() == Token.EOF) {
            input = "the end";
        } else {
            input = escapeWSAndQuote(tokens.getText(e.getStartToken(), e.getOffendingToken()));
        }
    } else {
        input = escapeWSAndQuote("<unknown input>");
    }
    String msg = "inadmissible input at " + input;
    recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}
CapitulatingErrorStrategy.java 文件源码 项目:rapidminer 阅读 25 收藏 0 点赞 0 评论 0
@Override
protected String getTokenErrorDisplay(Token t) {
    // overwrite standard behavior to use "the end" instead of <EOF>
    if (t == null) {
        return "<no token>";
    }
    String s = getSymbolText(t).replace("<EOF>", "the end");
    if (s == null) {
        if (getSymbolType(t) == Token.EOF) {
            s = "the end";
        } else {
            s = escapeWSAndQuote("<" + getSymbolType(t) + ">");
        }
    }
    return s;
}
EnhancedPainlessLexer.java 文件源码 项目:elasticsearch_my 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Token nextToken() {
    if (stashedNext != null) {
        previous = stashedNext;
        stashedNext = null;
        return previous;
    }
    Token next = super.nextToken();
    if (insertSemicolon(previous, next)) {
        stashedNext = next;
        previous = _factory.create(new Pair<TokenSource, CharStream>(this, _input), PainlessLexer.SEMICOLON, ";",
                Lexer.DEFAULT_TOKEN_CHANNEL, next.getStartIndex(), next.getStopIndex(), next.getLine(), next.getCharPositionInLine());
        return previous;
    } else {
        previous = next;
        return next;
    }
}
EnhancedPainlessLexer.java 文件源码 项目:elasticsearch_my 阅读 22 收藏 0 点赞 0 评论 0
@Override
protected boolean slashIsRegex() {
    Token lastToken = getPreviousToken();
    if (lastToken == null) {
        return true;
    }
    switch (lastToken.getType()) {
    case PainlessLexer.RBRACE:
    case PainlessLexer.RP:
    case PainlessLexer.OCTAL:
    case PainlessLexer.HEX:
    case PainlessLexer.INTEGER:
    case PainlessLexer.DECIMAL:
    case PainlessLexer.ID:
    case PainlessLexer.DOTINTEGER:
    case PainlessLexer.DOTID:
        return false;
    default:
        return true;
    }
}
ParserErrorStrategy.java 文件源码 项目:elasticsearch_my 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void recover(final Parser recognizer, final RecognitionException re) {
    final Token token = re.getOffendingToken();
    String message;

    if (token == null) {
        message = "no parse token found.";
    } else if (re instanceof InputMismatchException) {
        message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
                " was expecting one of [" + re.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
    } else if (re instanceof NoViableAltException) {
        if (token.getType() == PainlessParser.EOF) {
            message = "unexpected end of script.";
        } else {
            message = "invalid sequence of tokens near [" + getTokenErrorDisplay(token) + "].";
        }
    } else {
        message =  "unexpected token near [" + getTokenErrorDisplay(token) + "].";
    }

    Location location = new Location(sourceName, token == null ? -1 : token.getStartIndex());
    throw location.createError(new IllegalArgumentException(message, re));
}
FWPolicyErrorStrategy.java 文件源码 项目:oscm-app 阅读 19 收藏 0 点赞 0 评论 0
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
SwiftSupport.java 文件源码 项目:ts-swift-transpiler 阅读 25 收藏 0 点赞 0 评论 0
/**
 "If an operator has whitespace on the right side only, it is treated as a
 postfix unary operator. As an example, the ++ operator in a++ b is treated
 as a postfix unary operator."
 "If an operator has no whitespace on the left but is followed immediately
 by a dot (.), it is treated as a postfix unary operator. As an example,
 the ++ operator in a++.b is treated as a postfix unary operator (a++ .b
 rather than a ++ .b)."
 */
public static boolean isPostfixOp(TokenStream tokens) {
    int stop = getLastOpTokenIndex(tokens);
    if ( stop==-1 ) return false;

    int start = tokens.index();
    Token prevToken = tokens.get(start-1); // includes hidden-channel tokens
    Token nextToken = tokens.get(stop+1);
    boolean prevIsWS = isLeftOperatorWS(prevToken);
    boolean nextIsWS = isRightOperatorWS(nextToken);
    boolean result =
        !prevIsWS && nextIsWS ||
        !prevIsWS && nextToken.getType()==SwiftParser.DOT;
    String text = tokens.getText(Interval.of(start, stop));
    //System.out.println("isPostfixOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
    return result;
}
AbstractConstructor.java 文件源码 项目:rest-modeling-framework 阅读 25 收藏 0 点赞 0 评论 0
@Override
public Object visitTypedElementTuple(RAMLParser.TypedElementTupleContext typedeElementTuple) {
    final Token type = typedeElementTuple.type;
    final String name = typedeElementTuple.name.getText();

    final EObject propertyType = Strings.isNullOrEmpty(type.getText()) ?
            scope.getEObjectByName(BuiltinType.STRING.getName()) :
            typeExpressionConstructor.parse(type.getText(), scope);
    final boolean isRequired = !name.endsWith("?");
    scope.setValue(TYPED_ELEMENT__REQUIRED, isRequired, typedeElementTuple.getStart());
    final String parsedName = isRequired ? name : name.substring(0, name.length() - 1);

    scope.setValue(IDENTIFIABLE_ELEMENT__NAME, parsedName, typedeElementTuple.getStart());
    scope.setValue(TYPED_ELEMENT__TYPE, propertyType, typedeElementTuple.getStart());

    return scope.eObject();
}
TypeDeclarationResolver.java 文件源码 项目:rest-modeling-framework 阅读 15 收藏 0 点赞 0 评论 0
private EObject resolveType(final ParserRuleContext ruleContext, final EObject superType) {
    final EObject resolvedType;

    if (superType.eIsProxy()) {
        resolvedType = null;
    } else {
        resolvedType = create(superType.eClass(), ruleContext);
        EcoreUtil.replace(unresolved, resolvedType);

        final Token nameToken = ruleContext.getStart();
        final String name = nameToken.getText();
        final Scope typeScope = scope.with(resolvedType, TYPE_CONTAINER__TYPES);

        typeScope.with(IDENTIFIABLE_ELEMENT__NAME)
                .setValue(name, nameToken);

        typeScope.with(unresolved.eClass().getEStructuralFeature("type"))
                .setValue(superType, nameToken);
    }

    return resolvedType;
}
FWPolicyErrorStrategy.java 文件源码 项目:oscm 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Make sure we don't attempt to recover inline; if the parser successfully
 * recovers, it won't throw an exception.
 */
@Override
public Token recoverInline(Parser recognizer) throws RecognitionException {
    InputMismatchException e = new InputMismatchException(recognizer);

    String policies = recognizer.getInputStream().getText();
    StringTokenizer tk = new StringTokenizer(policies, ";");
    String policy = "";
    int idx = 0;
    while (tk.hasMoreElements()) {
        policy = (String) tk.nextElement();
        idx += policy.length();
        if (idx >= e.getOffendingToken().getStartIndex()) {
            break;
        }
    }

    String message = Messages.get(Messages.DEFAULT_LOCALE,
            "error_invalid_firewallconfig", new Object[] {
                    e.getOffendingToken().getText(), policy });
    throw new RuntimeException(message);
}
GrammarPredicates.java 文件源码 项目:beaker-notebook-archive 阅读 17 收藏 0 点赞 0 评论 0
public static boolean isClassName(TokenStream _input) {
  try {
    int i=1;
    Token token = _input.LT(i);
    while (token!=null && i < _input.size() && _input.LT(i+1).getType() == GroovyParser.DOT) {
      i = i + 2;
      token = _input.LT(i);
    }
    if(token==null)
      return false;
    // TODO here
    return Character.isUpperCase(Character.codePointAt(token.getText(), 0));
  } catch(Exception e) {
    e.printStackTrace();
  }

  return false;
}
StatementSplitter.java 文件源码 项目:rainbow 阅读 23 收藏 0 点赞 0 评论 0
public StatementSplitter(String sql, Set<String> delimiters)
{
    TokenSource tokens = getLexer(sql, delimiters);
    ImmutableList.Builder<Statement> list = ImmutableList.builder();
    StringBuilder sb = new StringBuilder();
    while (true) {
        Token token = tokens.nextToken();
        if (token.getType() == Token.EOF) {
            break;
        }
        if (token.getType() == SqlBaseParser.DELIMITER) {
            String statement = sb.toString().trim();
            if (!statement.isEmpty()) {
                list.add(new Statement(statement, token.getText()));
            }
            sb = new StringBuilder();
        }
        else {
            sb.append(token.getText());
        }
    }
    this.completeStatements = list.build();
    this.partialStatement = sb.toString().trim();
}
StatementSplitter.java 文件源码 项目:rainbow 阅读 27 收藏 0 点赞 0 评论 0
public static String squeezeStatement(String sql)
{
    TokenSource tokens = getLexer(sql, ImmutableSet.of());
    StringBuilder sb = new StringBuilder();
    while (true) {
        Token token = tokens.nextToken();
        if (token.getType() == Token.EOF) {
            break;
        }
        if (token.getType() == SqlBaseLexer.WS) {
            sb.append(' ');
        }
        else {
            sb.append(token.getText());
        }
    }
    return sb.toString().trim();
}
SqlParser.java 文件源码 项目:rainbow 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void exitNonReserved(SqlBaseParser.NonReservedContext context)
{
    // we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal.
    // Otherwise, ANTLR gets confused an fires spurious notifications.
    if (!(context.getChild(0) instanceof TerminalNode)) {
        int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex();
        throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule));
    }

    // replace nonReserved words with IDENT tokens
    context.getParent().removeLastChild();

    Token token = (Token) context.getChild(0).getPayload();
    context.getParent().addChild(new CommonToken(
            new Pair<>(token.getTokenSource(), token.getInputStream()),
            SqlBaseLexer.IDENTIFIER,
            token.getChannel(),
            token.getStartIndex(),
            token.getStopIndex()));
}
AstBuilder.java 文件源码 项目:rainbow 阅读 20 收藏 0 点赞 0 评论 0
private static ArithmeticBinaryExpression.Type getArithmeticBinaryOperator(Token operator)
{
    switch (operator.getType()) {
        case SqlBaseLexer.PLUS:
            return ArithmeticBinaryExpression.Type.ADD;
        case SqlBaseLexer.MINUS:
            return ArithmeticBinaryExpression.Type.SUBTRACT;
        case SqlBaseLexer.ASTERISK:
            return ArithmeticBinaryExpression.Type.MULTIPLY;
        case SqlBaseLexer.SLASH:
            return ArithmeticBinaryExpression.Type.DIVIDE;
        case SqlBaseLexer.PERCENT:
            return ArithmeticBinaryExpression.Type.MODULUS;
    }

    throw new UnsupportedOperationException("Unsupported operator: " + operator.getText());
}
AstBuilder.java 文件源码 项目:rainbow 阅读 18 收藏 0 点赞 0 评论 0
private static ComparisonExpressionType getComparisonOperator(Token symbol)
{
    switch (symbol.getType()) {
        case SqlBaseLexer.EQ:
            return ComparisonExpressionType.EQUAL;
        case SqlBaseLexer.NEQ:
            return ComparisonExpressionType.NOT_EQUAL;
        case SqlBaseLexer.LT:
            return ComparisonExpressionType.LESS_THAN;
        case SqlBaseLexer.LTE:
            return ComparisonExpressionType.LESS_THAN_OR_EQUAL;
        case SqlBaseLexer.GT:
            return ComparisonExpressionType.GREATER_THAN;
        case SqlBaseLexer.GTE:
            return ComparisonExpressionType.GREATER_THAN_OR_EQUAL;
    }

    throw new IllegalArgumentException("Unsupported operator: " + symbol.getText());
}
AstBuilder.java 文件源码 项目:rainbow 阅读 19 收藏 0 点赞 0 评论 0
private static CurrentTime.Type getDateTimeFunctionType(Token token)
{
    switch (token.getType()) {
        case SqlBaseLexer.CURRENT_DATE:
            return CurrentTime.Type.DATE;
        case SqlBaseLexer.CURRENT_TIME:
            return CurrentTime.Type.TIME;
        case SqlBaseLexer.CURRENT_TIMESTAMP:
            return CurrentTime.Type.TIMESTAMP;
        case SqlBaseLexer.LOCALTIME:
            return CurrentTime.Type.LOCALTIME;
        case SqlBaseLexer.LOCALTIMESTAMP:
            return CurrentTime.Type.LOCALTIMESTAMP;
    }

    throw new IllegalArgumentException("Unsupported special function: " + token.getText());
}
AstBuilder.java 文件源码 项目:rainbow 阅读 23 收藏 0 点赞 0 评论 0
private static IntervalLiteral.IntervalField getIntervalFieldType(Token token)
{
    switch (token.getType()) {
        case SqlBaseLexer.YEAR:
            return IntervalLiteral.IntervalField.YEAR;
        case SqlBaseLexer.MONTH:
            return IntervalLiteral.IntervalField.MONTH;
        case SqlBaseLexer.DAY:
            return IntervalLiteral.IntervalField.DAY;
        case SqlBaseLexer.HOUR:
            return IntervalLiteral.IntervalField.HOUR;
        case SqlBaseLexer.MINUTE:
            return IntervalLiteral.IntervalField.MINUTE;
        case SqlBaseLexer.SECOND:
            return IntervalLiteral.IntervalField.SECOND;
    }

    throw new IllegalArgumentException("Unsupported interval field: " + token.getText());
}
ANTLRAssistBehavior.java 文件源码 项目:gitplex-mit 阅读 20 收藏 0 点赞 0 评论 0
@Override
protected int getAnchor(String content) {
    List<Token> tokens = codeAssist.getGrammar().lex(content);
    if (tokens.isEmpty()) {
        return 0;
    } else {
        Token lastToken = tokens.get(tokens.size()-1);
        String contentAfterLastToken = content.substring(lastToken.getStopIndex()+1);
        if (contentAfterLastToken.length() > 0) {
            contentAfterLastToken = StringUtils.trimStart(contentAfterLastToken);
            return content.length() - contentAfterLastToken.length();
        } else {
            return lastToken.getStartIndex();
        }
    }
}
ParserErrorListener.java 文件源码 项目:OperatieBRP 阅读 26 收藏 0 点赞 0 评论 0
@Override
public void syntaxError(final org.antlr.v4.runtime.Recognizer<?, ?> recognizer,
                        final java.lang.Object offendingSymbol,
                        final int line, final int charPositionInLine, final java.lang.String msg,
                        final org.antlr.v4.runtime.RecognitionException e) {
    final Token antlrToken = (Token) offendingSymbol;

    if (offendingSymbol == null) {
        //in het geval van lexer fouten, bijv. token recognition error at: '*' voor de expressie **bla**
        throw new ExpressieParseException(msg);
    } else {
        throw new ExpressieParseException(
                String.format("%s \"%s\" op positie: %d", ParserFoutCode.SYNTAX_ERROR, msg, antlrToken.getStartIndex())
        );
    }
}
Utilities.java 文件源码 项目:Tarski 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Cloning expression to create new same expression.
 */
public static ExprContext cloneExprContext(final ExprContext expr) {

  final ExprContext clone = createContextType(expr);

  clone.copyFrom(expr);

  for (final ParseTree child : expr.children) {
    if (child instanceof TerminalNode) {
      clone.addChild(new TerminalNodeImpl(((TerminalNode) child).getSymbol()));
    } else if (child instanceof ExprContext) {
      final ExprContext cloneChild = cloneExprContext((ExprContext) child);
      clone.addChild(cloneChild);
      setLeftRight(clone, cloneChild);
    } else if (child instanceof Token) {
      clone.addChild(new CommonToken((Token) child));
    }
  }
  return clone;
}
Antlr4Utils.java 文件源码 项目:sonar-tsql-plugin 阅读 20 收藏 0 点赞 0 评论 0
public static void print(final ParseTree node, final int level, CommonTokenStream stream) {
    final Interval sourceInterval = node.getSourceInterval();

    final Token firstToken = stream.get(sourceInterval.a);

    int line = firstToken.getLine();
    int charStart = firstToken.getCharPositionInLine();

    int endLine = line;
    int endChar = charStart + firstToken.getText().length();

    String data = "@(" + line + ":" + charStart + "," + endLine + ":" + endChar + ") with text: "
            + firstToken.getText();
    final int tmp = level + 1;
    final StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.repeat("\t", level));
    sb.append(node.getClass().getSimpleName() + ": " + data + " :" + node.getText());
    System.out.println(sb.toString());
    final int n = node.getChildCount();
    for (int i = 0; i < n; i++) {

        final ParseTree c = node.getChild(i);
        print(c, tmp, stream);

    }
}
AstBuilder.java 文件源码 项目:kalang 阅读 22 收藏 0 点赞 0 评论 0
@Override
public AstNode visitPostIfStmt(KalangParser.PostIfStmtContext ctx) {
    ExprNode leftExpr = visitExpression(ctx.expression(0));
    if (!(leftExpr instanceof AssignExpr)) {
        diagnosisReporter.report(Diagnosis.Kind.ERROR, "AssignExpr required", ctx);
    }
    AssignExpr assignExpr = (AssignExpr) leftExpr;
    AssignableExpr to = assignExpr.getTo();
    ExprNode from = assignExpr.getFrom();
    ExprNode cond = visitExpression(ctx.expression(1));
    Token op = ctx.op;
    if (op != null) {
        String opStr = op.getText();
        BinaryExpr be = createBinaryExpr(to, cond, opStr);
        cond = be;
    }
    AssignExpr as = new AssignExpr(to, from);
    IfStmt is = new IfStmt(cond);
    is.getTrueBody().statements.add(new ExprStmt(as));
    mapAst(is,ctx);
    return is;
}
Trainer.java 文件源码 项目:codebuff 阅读 21 收藏 0 点赞 0 评论 0
public static int getInjectWSCategory(CodeBuffTokenStream tokens, int i) {
    int precedingNL = getPrecedingNL(tokens, i); // how many lines to inject

    Token curToken = tokens.get(i);
    Token prevToken = tokens.getPreviousRealToken(i);

    int ws = 0;
    if ( precedingNL==0 ) {
        ws = curToken.getCharPositionInLine() -
            (prevToken.getCharPositionInLine()+prevToken.getText().length());
    }

    int injectNL_WS = CAT_NO_WS;
    if ( precedingNL>0 ) {
        injectNL_WS = nlcat(precedingNL);
    }
    else if ( ws>0 ) {
        injectNL_WS = wscat(ws);
    }

    return injectNL_WS;
}
AntrlFileTest.java 文件源码 项目:sonar-tsql-plugin 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void compareWithAntrl() {
    String s = "select " + "*" + "from dbo.test";
    AntrlResult result = Antlr4Utils.getFull(s);
    SourceLinesProvider p = new SourceLinesProvider();
    SourceLine[] lines = p.getLines(new StringBufferInputStream(s), Charset.defaultCharset());
    FillerRequest file = new FillerRequest(null, null, result.getTree(), lines);
    for (Token t : result.getStream().getTokens()) {
        if (t.getType() == Token.EOF) {
            continue;
        }
        int[] start = file.getLineAndColumn(t.getStartIndex());
        int[] end = file.getLineAndColumn(t.getStopIndex());
        Assert.assertNotNull(start);
        Assert.assertNotNull(end);
        Assert.assertEquals(t.getLine(), start[0]);
        System.out.println(t.getText() + Arrays.toString(start) + " " + t.getCharPositionInLine() + " "
                + t.getLine() + " " + Arrays.toString(end));
        Assert.assertEquals(t.getCharPositionInLine(), start[1]);
    }
}
SwiftSupport.java 文件源码 项目:swift-js-transpiler 阅读 18 收藏 0 点赞 0 评论 0
/**
 "If an operator has whitespace on the right side only, it is treated as a
 postfix unary operator. As an example, the ++ operator in a++ b is treated
 as a postfix unary operator."
 "If an operator has no whitespace on the left but is followed immediately
 by a dot (.), it is treated as a postfix unary operator. As an example,
 the ++ operator in a++.b is treated as a postfix unary operator (a++ .b
 rather than a ++ .b)."
 */
public static boolean isPostfixOp(TokenStream tokens) {
    int stop = getLastOpTokenIndex(tokens);
    if ( stop==-1 ) return false;

    int start = tokens.index();
    Token prevToken = tokens.get(start-1); // includes hidden-channel tokens
    Token nextToken = tokens.get(stop+1);
    boolean prevIsWS = isLeftOperatorWS(prevToken);
    boolean nextIsWS = isRightOperatorWS(nextToken);
    boolean result =
        !prevIsWS && nextIsWS ||
        !prevIsWS && nextToken.getType()==SwiftParser.DOT;
    String text = tokens.getText(Interval.of(start, stop));
    //System.out.println("isPostfixOp: '"+prevToken+"','"+text+"','"+nextToken+"' is "+result);
    return result;
}
CoqSyntaxException.java 文件源码 项目:exterminator 阅读 20 收藏 0 点赞 0 评论 0
private static String makeMessage(CoqFTParser parser, Token offendingToken,
        int line, int charPositionInLine, String msg) {
    StringBuilder sb = new StringBuilder();
    sb.append("ANTLR SYNTAX ERROR\n");

    sb.append("Offending line:\n");
    sb.append(underlineError(parser, offendingToken, line,
            charPositionInLine)).append("\n\n");

    sb.append("Rule stack:\n");
    List<String> stack = parser.getRuleInvocationStack();
    Collections.reverse(stack);
    sb.append(stack).append("\n\n");

    sb.append("Message:\n");
    sb.append("line ").append(line).append(":");
    sb.append(charPositionInLine).append(" ").append(msg);

    if(DEBUG_SHOW_FULL_TEXT) {
        sb.append("\n\nFull text:\n");
        CommonTokenStream tokens = (CommonTokenStream)parser.getInputStream();
        sb.append(tokens.getTokenSource().getInputStream().toString());
    }

    return sb.toString();
}
IdentifyOversizeLists.java 文件源码 项目:codebuff 阅读 19 收藏 0 点赞 0 评论 0
public void visitNonSingletonWithSeparator(ParserRuleContext ctx,
                                           List<? extends ParserRuleContext> siblings,
                                           Token separator)
{
    boolean oversize = isOversizeList(ctx, siblings, separator);
    Map<Token, Pair<Boolean, Integer>> tokenInfo =
        getInfoAboutListTokens(ctx, tokens, tokenToNodeMap, siblings, oversize);

    // copy sibling list info for associated tokens into overall list
    // but don't overwrite existing so that most general (largest construct)
    // list information is use/retained (i.e., not overwritten).
    for (Token t : tokenInfo.keySet()) {
        if ( !tokenToListInfo.containsKey(t) ) {
            tokenToListInfo.put(t, tokenInfo.get(t));
        }
    }
}
Sbvr2FolVisitor.java 文件源码 项目:ShapeChange 阅读 17 收藏 0 点赞 0 评论 0
@Override
public Expression visitNameExpr(NameExprContext ctx) {

    List<String> names = new ArrayList<String>();

    for (Token t : ctx.values) {
        String s = t.getText();
        // strip leading and trailing "'"
        names.add(s.substring(1, s.length() - 1));
    }

    if (names.size() == 1) {

        StringLiteral sl = new StringLiteral();
        sl.setValue(names.get(0));
        return sl;

    } else {

        StringLiteralList sll = new StringLiteralList();
        sll.setValues(names);

        return sll;
    }
}
DenterHelper.java 文件源码 项目:newton 阅读 20 收藏 0 点赞 0 评论 0
private void initIfFirstRun() {
  if (indentations.isEmpty()) {
    indentations.push(0);
    // First invocation. Look for the first non-NL. Enqueue it, and possibly an indentation if that non-NL
    // token doesn't start at char 0.
    Token firstRealToken;
    do {
      firstRealToken = pullToken();
    }
    while(firstRealToken.getType() == nlToken);

    if (firstRealToken.getCharPositionInLine() > 0) {
      indentations.push(firstRealToken.getCharPositionInLine());
      dentsBuffer.add(createToken(indentToken, firstRealToken));
    }
    dentsBuffer.add(firstRealToken);
  }
}


问题


面经


文章

微信
公众号

扫码关注公众号