@Override public void initialize(Token tok) { super.initialize(tok); lineNo = tok.getLine(); // expect columns to start @ 0 columnNo = tok.getColumn() - 1; }
private void error(String msg) throws TokenStreamException, SemanticException { Token token = LT(0); throw new SemanticException( msg, token.getFilename(), token.getLine(), token.getColumn() ); }
@Override public void initialize(Token tok) { super.initialize(tok); filename = tok.getFilename(); line = tok.getLine(); column = tok.getColumn(); String text = tok.getText(); textLength = StringHelper.isEmpty(text) ? 0 : text.length(); }
/** * Create block comment from token. * @param token * Token object. * @return DetailAST with BLOCK_COMMENT type. */ public static DetailAST createBlockCommentNode(Token token) { final DetailAST blockComment = new DetailAST(); blockComment.initialize(TokenTypes.BLOCK_COMMENT_BEGIN, BLOCK_MULTIPLE_COMMENT_BEGIN); // column counting begins from 0 blockComment.setColumnNo(token.getColumn() - 1); blockComment.setLineNo(token.getLine()); final DetailAST blockCommentContent = new DetailAST(); blockCommentContent.setType(TokenTypes.COMMENT_CONTENT); // column counting begins from 0 // plus length of '/*' blockCommentContent.setColumnNo(token.getColumn() - 1 + 2); blockCommentContent.setLineNo(token.getLine()); blockCommentContent.setText(token.getText()); final DetailAST blockCommentClose = new DetailAST(); blockCommentClose.initialize(TokenTypes.BLOCK_COMMENT_END, BLOCK_MULTIPLE_COMMENT_END); final Map.Entry<Integer, Integer> linesColumns = countLinesColumns( token.getText(), token.getLine(), token.getColumn()); blockCommentClose.setLineNo(linesColumns.getKey()); blockCommentClose.setColumnNo(linesColumns.getValue()); blockComment.addChild(blockCommentContent); blockComment.addChild(blockCommentClose); return blockComment; }
/** * Create single-line comment from token. * @param token to create the AST * @return DetailAST with SINGLE_LINE_COMMENT type */ private static DetailAST createSlCommentNode(Token token) { final DetailAST slComment = new DetailAST(); slComment.setType(TokenTypes.SINGLE_LINE_COMMENT); slComment.setText("//"); // column counting begins from 0 slComment.setColumnNo(token.getColumn() - 1); slComment.setLineNo(token.getLine()); final DetailAST slCommentContent = new DetailAST(); slCommentContent.setType(TokenTypes.COMMENT_CONTENT); // column counting begins from 0 // plus length of '//' slCommentContent.setColumnNo(token.getColumn() - 1 + 2); slCommentContent.setLineNo(token.getLine()); slCommentContent.setText(token.getText()); slComment.addChild(slCommentContent); return slComment; }
/** Generate a #line or // line depending on options */ public void genLineNo(Token t) { if (t != null) genLineNo(t.getLine()); } /** Generate a #line or // line depending on options */
void track(String element, Token token) throws SemanticException { if(elementMap.containsKey(element)) { throw new SemanticException( element + " appears twice.", token.getFilename(), token.getLine() , token.getColumn() ); } elementMap.put(element, new Integer(1)); } boolean contains(String element)
@Override public void initialize(Token tok) { super.initialize(tok); lineNo = tok.getLine(); // expect columns to start @ 0 columnNo = tok.getColumn() - 1; }
public MismatchedTokenException(String[] tokenNames_, Token token_, int expecting_, boolean matchNot, String fileName_) { super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn()); tokenNames = tokenNames_; token = token_; tokenText = token_.getText(); mismatchType = matchNot ? NOT_TOKEN : TOKEN; expecting = expecting_; }
public void initialize(Token tok) { super.initialize(tok); line = tok.getLine(); column = tok.getColumn(); }
public MismatchedTokenException(String[] tokenNames_, Token token_, int lower, int upper_, boolean matchNot, String fileName_) { super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn()); tokenNames = tokenNames_; token = token_; tokenText = token_.getText(); mismatchType = matchNot ? NOT_RANGE : RANGE; expecting = lower; upper = upper_; }
public ActionElement(Grammar g, Token t) { super(g); actionText = t.getText(); line = t.getLine(); column = t.getColumn(); }
public void add(int type, antlr.Token tok) { if (tok == null) { System.out.println("tok == null ERROR!"); return; } struct.addToken(new CSharpToken(type, currentFile, tok.getLine(), tok.getColumn(), tok.getText().length())); // System.out.println("type: " + CSharpToken.type2string(type) + // " text: '"+tok.getText()+"'"); }
public SemanticException createSemanticException(String message, Token element) { return new SemanticException( message, element.getFilename(), element.getLine(), element.getColumn() ); }
/** Get the type string out of an argument-action token. * The type of an action is assumed to precede a trailing identifier * Specific code-generators may want to override this * if the language has unusual declaration syntax. * @param t The action token * @return A string containing the text of the type */ protected String extractTypeOfAction(Token t) { return extractTypeOfAction(t.getText(), t.getLine(), t.getColumn()); }
public void initialize(Token tok) { super.initialize(tok); filename = tok.getFilename(); line = tok.getLine(); column = tok.getColumn(); String text = tok.getText(); textLength = StringHelper.isEmpty(text) ? 0 : text.length(); }
private void error(String msg) throws TokenStreamException, SemanticException { Token token = LT(0); throw new SemanticException( msg, token.getFilename(), token.getLine(), token.getColumn() ); }
private void error(String msg) throws TokenStreamException, SemanticException { Token token = LT(0); throw new SemanticException( msg, token.getFilename(), token.getLine(), token.getColumn() ); } }
/** * Clones the token */ public Token cloneToken(Token t) { CommonToken clone = new CommonToken(t.getType(),t.getText()); clone.setLine(t.getLine()); clone.setColumn(t.getColumn()); return clone; }
public void refReturnAction(Token returnAction) { if (grammar instanceof LexerGrammar) { String name = CodeGenerator.encodeLexerRuleName(((RuleBlock)context().block).getRuleName()); RuleSymbol rs = (RuleSymbol)grammar.getSymbol(name); if (rs.access.equals("public")) { tool.warning("public Lexical rules cannot specify return type", grammar.getFilename(), returnAction.getLine(), returnAction.getColumn()); return; } } ((RuleBlock)context().block).returnAction = returnAction.getText(); }