@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; }
@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_, BitSet set_, boolean matchNot, String fileName_) { super("Mismatched Token", fileName_, token_.getLine(), token_.getColumn()); tokenNames = tokenNames_; token = token_; tokenText = token_.getText(); mismatchType = matchNot ? NOT_SET : SET; set = set_; }
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() ); }
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(); }
@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(); }
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() ); } }
private void error(String msg) throws TokenStreamException, SemanticException { Token token = LT(0); throw new SemanticException( msg, token.getFilename(), token.getLine(), token.getColumn() ); } }
public void setOption(Token option, Token value) { if (option.getText().equals("AST")) { setASTNodeType(value.getText()); } else { grammar.antlrTool.error("Invalid element option:" + option.getText(), grammar.getFilename(), option.getLine(), option.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 initialize(Token t) { setType(t.getType()); setText(t.getText()); setLine(t.getLine()); setColumn(t.getColumn()); }
public void beginTree(Token tok) throws SemanticException { if (!(grammar instanceof TreeWalkerGrammar)) { tool.error("Trees only allowed in TreeParser", grammar.getFilename(), tok.getLine(), tok.getColumn()); throw new SemanticException("Trees only allowed in TreeParser"); } super.beginTree(tok); blocks.push(new TreeBlockContext()); context().block = new TreeElement(grammar, tok); context().altNum = 0; // reset alternative number }