public static Rule alwaysFalse(String name) { return builder().name(name).when(new BooleanExpression(new CommonToken(-1), false)).then(Collections.emptyList()).build(); }
/** * This method is used to get the first non-tight HTML tag encountered while parsing javadoc. * This shall eventually be reflected by the {@link ParseStatus} object returned by * {@link #parseJavadocAsDetailNode(DetailAST)} method via the instance member * {@link ParseStatus#firstNonTightHtmlTag}, and checks not supposed to process non-tight HTML * or the ones which are supposed to log violation for non-tight javadocs can utilize that. * * @param javadocParser The ANTLR recognizer instance which has been used to parse the javadoc * @return First non-tight HTML tag if one exists; null otherwise */ private Token getFirstNonTightHtmlTag(JavadocParser javadocParser) { final CommonToken offendingToken; final ParserRuleContext nonTightTagStartContext = javadocParser.nonTightTagStartContext; if (nonTightTagStartContext == null) { offendingToken = null; } else { final Token token = ((TerminalNode) nonTightTagStartContext.getChild(1)) .getSymbol(); offendingToken = new CommonToken(token); offendingToken.setLine(offendingToken.getLine() + errorListener.offset); } return offendingToken; }
@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())); } }
@Override public CommonToken create(int type, String text) { return new CommonToken(type, text); } }
if ( _input.LA(1)=='/' ) { consume(); t = new CommonToken(ANYWHERE, "//"); t = new CommonToken(ROOT, "/"); t = new CommonToken(WILDCARD, "*"); break; case '!': consume(); t = new CommonToken(BANG, "!"); break; case '\'': String s = matchString(); t = new CommonToken(STRING, s); break; case CharStream.EOF : return new CommonToken(EOF, "<EOF>"); default: if ( isNameStartChar(_input.LA(1)) ) { String id = matchID(); if ( Character.isUpperCase(id.charAt(0)) ) t = new CommonToken(TOKEN_REF, id); else t = new CommonToken(RULE_REF, id);
/** Replace any subtree siblings of root that are completely to left * or right of lookahead range with a CommonToken(Token.INVALID_TYPE,"...") * node. The source interval for t is not altered to suit smaller range! * * WARNING: destructive to t. * * @since 4.5.1 */ public static void stripChildrenOutOfRange(ParserRuleContext t, ParserRuleContext root, int startIndex, int stopIndex) { if ( t==null ) return; for (int i = 0; i < t.getChildCount(); i++) { ParseTree child = t.getChild(i); Interval range = child.getSourceInterval(); if ( child instanceof ParserRuleContext && (range.b < startIndex || range.a > stopIndex) ) { if ( isAncestorOf(child, root) ) { // replace only if subtree doesn't have displayed root CommonToken abbrev = new CommonToken(Token.INVALID_TYPE, "..."); t.children.set(i, new TerminalNodeImpl(abbrev)); } } } }
@Override public Token nextToken() { if (!queue.isEmpty()) { return queue.poll(); } Token next = super.nextToken(); if (next.getType() != Word) { return next; } Token next2 = super.nextToken(); if (next2.getType() == Punctuation && next2.getText().equals(".")) { String abbrev = next.getText() + "."; if (abbreviations != null && abbreviations.contains(abbrev)) { CommonToken commonToken = new CommonToken(Abbreviation, abbrev); commonToken.setStartIndex(next.getStartIndex()); commonToken.setStopIndex(next2.getStopIndex()); commonToken.setTokenIndex(next.getTokenIndex()); commonToken.setCharPositionInLine(next.getCharPositionInLine()); commonToken.setLine(next.getLine()); return commonToken; } } queue.offer(next2); return next; }
@Override public CommonToken create(Pair<TokenSource, CharStream> source, int type, String text, int channel, int start, int stop, int line, int charPositionInLine) { CommonToken t = new CommonToken(source, type, channel, start, stop); t.setLine(line); t.setCharPositionInLine(charPositionInLine); if ( text!=null ) { t.setText(text); } else if ( copyText && source.b != null ) { t.setText(source.b.getText(Interval.of(start,stop))); } return t; }
@Override public CommonToken create(int type, String text) { return new CommonToken(type, text); } }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
private CommonToken commonToken(int type, String text) { int stop = this.getCharIndex() - 1; int start = text.isEmpty() ? stop : stop - text.length() + 1; return new CommonToken(this._tokenFactorySourcePair, type, DEFAULT_TOKEN_CHANNEL, start, stop); }
public void indicateNoStartRuleInParseTreePane() { setParseTree(Arrays.asList(new String[0]), new TerminalNodeImpl(new CommonToken(Token.INVALID_TYPE, "No start rule is selected"))); }
public void indicateInvalidGrammarInParseTreePane() { setParseTree(Arrays.asList(new String[0]), new TerminalNodeImpl(new CommonToken(Token.INVALID_TYPE, "Issues with parser and/or lexer grammar(s) prevent preview; see ANTLR 'Tool Output' pane"))); }
public static List<CommonToken> copy(CommonTokenStream tokens) { List<CommonToken> copy = new ArrayList<>(); tokens.fill(); for (Token t : tokens.getTokens()) { copy.add(new CommonToken(t)); } return copy; }
public CodeBuffTokenStream(CommonTokenStream stream) { super(stream.getTokenSource()); this.fetchedEOF = false; for (Token t : stream.getTokens()) { tokens.add(new CommonToken(t)); } reset(); }
private static void reinitializeObject(final Type objectType, final StaticScope objectsScope) { final CommonToken objectToken = new CommonToken(0); objectToken.setLine(157239); final ClassDeclaration objectClass = new ClassDeclaration("Object", objectsScope, null, objectToken); globalScope_.declareClass(objectClass); objectClass.setType(objectType); objectsScope.setDeclaration(objectClass); typeDeclarationList_.add(objectClass); }