Java Code Examples for org.antlr.runtime.Token#getText()
The following examples show how to use
org.antlr.runtime.Token#getText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 6 votes |
public CompiledST defineRegion(String enclosingTemplateName, Token regionT, String template, Token templateToken) { String name = regionT.getText(); template = Misc.trimOneStartingNewline(template); template = Misc.trimOneTrailingNewline(template); CompiledST code = compile(getFileName(), enclosingTemplateName, null, template, templateToken); String mangled = getMangledRegionName(enclosingTemplateName, name); if ( lookupTemplate(mangled)==null ) { errMgr.compileTimeError(ErrorType.NO_SUCH_REGION, templateToken, regionT, enclosingTemplateName, name); return new CompiledST(); } code.name = mangled; code.isRegion = true; code.regionDefType = ST.RegionType.EXPLICIT; code.templateDefStartToken = regionT; rawDefineTemplate(mangled, code, regionT); code.defineArgDefaultValueTemplates(this); code.defineImplicitlyDefinedTemplates(this); return code; }
Example 2
Source File: DRL5Parser.java From kogito-runtimes with Apache License 2.0 | 6 votes |
/** * fromWindow := WINDOW ID * * @param pattern * @throws RecognitionException */ private void fromWindow( PatternDescrBuilder< ? > pattern ) throws RecognitionException { String window = ""; match( input, DRL5Lexer.ID, DroolsSoftKeywords.WINDOW, null, DroolsEditorType.KEYWORD ); if ( state.failed ) return; Token id = match( input, DRL5Lexer.ID, null, null, DroolsEditorType.IDENTIFIER ); if ( state.failed ) return; window = id.getText(); if ( state.backtracking == 0 ) { pattern.from().window( window ); if ( input.LA( 1 ) != DRL5Lexer.EOF ) { helper.emit( Location.LOCATION_LHS_BEGIN_OF_CONDITION ); } } }
Example 3
Source File: AbstractIndentationTokenSource.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
/** * The token was previously determined as potentially to-be-splitted thus we * emit additional indentation or dedenting tokens. */ protected void doSplitTokenImpl(Token token, ITokenAcceptor result) { String text = token.getText(); int indentation = computeIndentation(text); if (indentation == -1 || indentation == currentIndentation) { // no change of indentation level detected simply process the token result.accept(token); } else if (indentation > currentIndentation) { // indentation level increased splitIntoBeginToken(token, indentation, result); } else if (indentation < currentIndentation) { // indentation level decreased int charCount = computeIndentationRelevantCharCount(text); if (charCount > 0) { // emit whitespace including newline splitWithText(token, text.substring(0, charCount), result); } // emit end tokens at the beginning of the line decreaseIndentation(indentation, result); if (charCount != text.length()) { handleRemainingText(token, text.substring(charCount), indentation, result); } } else { throw new IllegalStateException(String.valueOf(indentation)); } }
Example 4
Source File: NodeModelTokenSource.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Produce an Antlr token for the prefix of the given leaf that overlaps the requested region * * @see #endOffset */ private Token toPrefixToken(ILeafNode leaf) { Lexer lexer = new InternalN4JSLexer(); String text = leaf.getText(); String prefix = text.substring(0, endOffset - leaf.getTotalOffset()); ANTLRStringStream stream = new ANTLRStringStream(prefix); lexer.setCharStream(stream); Token nextToken = lexer.nextToken(); // copy to get rid of the reference to the stream again return new CommonToken(nextToken.getType(), nextToken.getText()); }
Example 5
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Make name and alias for target. Replace any previous definition of name. */ public CompiledST defineTemplateAlias(Token aliasT, Token targetT) { String alias = aliasT.getText(); String target = targetT.getText(); CompiledST targetCode = rawGetTemplate("/"+target); if ( targetCode==null ) { errMgr.compileTimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target); return null; } rawDefineTemplate("/"+alias, targetCode, aliasT); return targetCode; }
Example 6
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Make name and alias for target. Replace any previous definition of name. */ public CompiledST defineTemplateAlias(Token aliasT, Token targetT) { String alias = aliasT.getText(); String target = targetT.getText(); CompiledST targetCode = rawGetTemplate("/"+target); if ( targetCode==null ) { errMgr.compileTimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target); return null; } rawDefineTemplate("/"+alias, targetCode, aliasT); return targetCode; }
Example 7
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+"import " + fileNameToken.getText() + " in STGroupDir " + this.getName(); throw new UnsupportedOperationException(msg); }
Example 8
Source File: ParserHelper.java From kogito-runtimes with Apache License 2.0 | 5 votes |
void setEnd( DescrBuilder< ? , ? > db ) { Token last = input.LT( -1 ); if ( db != null && last != null ) { int endLocation = last.getText() != null ? last.getCharPositionInLine() + last.getText().length() - 1 : last.getCharPositionInLine(); db.endCharacter( ((CommonToken) last).getStopIndex() + 1 ).endLocation( last.getLine(), endLocation ); } }
Example 9
Source File: CFBinaryExpression.java From openbd-core with GNU General Public License v3.0 | 5 votes |
public CFBinaryExpression( Token t, CFExpression left, CFExpression right ) { super(t); _kind = t.getType(); operatorImage = t.getText(); if ( _kind == CFMLLexer.ANDOPERATOR ) { _kind = CFMLLexer.AND; } else if ( _kind == CFMLLexer.OROPERATOR ) { _kind = CFMLLexer.OR; } else if ( _kind == CFMLLexer.MODOPERATOR ) { _kind = CFMLLexer.MOD; } _left = left; _right = right; }
Example 10
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Make name and alias for target. Replace any previous definition of name. */ public CompiledST defineTemplateAlias(Token aliasT, Token targetT) { String alias = aliasT.getText(); String target = targetT.getText(); CompiledST targetCode = rawGetTemplate("/"+target); if ( targetCode==null ) { errMgr.compileTimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target); return null; } rawDefineTemplate("/"+alias, targetCode, aliasT); return targetCode; }
Example 11
Source File: ParametrizedNode.java From netbeans with Apache License 2.0 | 5 votes |
public ParametrizedNode(Token token, int splitIndex) { super(token); final String string = token.getText(); if (string != null) { setName(string.substring(0, splitIndex)); setValue(new OptionValue.SimpleString(string.substring(splitIndex))); delimiter = ""; setValid(true); } else { setName(""); setValid(false); } }
Example 12
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+ "import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }
Example 13
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Make name and alias for target. Replace any previous definition of name. */ public CompiledST defineTemplateAlias(Token aliasT, Token targetT) { String alias = aliasT.getText(); String target = targetT.getText(); CompiledST targetCode = rawGetTemplate("/"+target); if ( targetCode==null ) { errMgr.compileTimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target); return null; } rawDefineTemplate("/"+alias, targetCode, aliasT); return targetCode; }
Example 14
Source File: STGroup.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
/** Make name and alias for target. Replace any previous definition of name. */ public CompiledST defineTemplateAlias(Token aliasT, Token targetT) { String alias = aliasT.getText(); String target = targetT.getText(); CompiledST targetCode = rawGetTemplate("/"+target); if ( targetCode==null ) { errMgr.compileTimeError(ErrorType.ALIAS_TARGET_UNDEFINED, null, aliasT, alias, target); return null; } rawDefineTemplate("/"+alias, targetCode, aliasT); return targetCode; }
Example 15
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+"import " + fileNameToken.getText() + " in STGroupDir " + this.getName(); throw new UnsupportedOperationException(msg); }
Example 16
Source File: STLexer.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
protected Token inside() { while ( true ) { switch ( c ) { case ' ' : case '\t' : case '\n' : case '\r' : consume(); return SKIP; case '.' : consume(); if ( input.LA(1)=='.' && input.LA(2)=='.' ) { consume(); match('.'); return newToken(ELLIPSIS); } return newToken(DOT); case ',' : consume(); return newToken(COMMA); case ':' : consume(); return newToken(COLON); case ';' : consume(); return newToken(SEMI); case '(' : consume(); return newToken(LPAREN); case ')' : consume(); return newToken(RPAREN); case '[' : consume(); return newToken(LBRACK); case ']' : consume(); return newToken(RBRACK); case '=' : consume(); return newToken(EQUALS); case '!' : consume(); return newToken(BANG); case '@' : consume(); if ( c=='e' && input.LA(2)=='n' && input.LA(3)=='d' ) { consume(); consume(); consume(); return newToken(REGION_END); } return newToken(AT); case '"' : return mSTRING(); case '&' : consume(); match('&'); return newToken(AND); // && case '|' : consume(); match('|'); return newToken(OR); // || case '{' : return subTemplate(); default: if ( c==delimiterStopChar ) { consume(); scanningInsideExpr = false; return newToken(RDELIM); } if ( isIDStartLetter(c) ) { Token id = mID(); String name = id.getText(); if ( name.equals("if") ) return newToken(IF); else if ( name.equals("endif") ) return newToken(ENDIF); else if ( name.equals("else") ) return newToken(ELSE); else if ( name.equals("elseif") ) return newToken(ELSEIF); else if ( name.equals("super") ) return newToken(SUPER); else if ( name.equals("true") ) return newToken(TRUE); else if ( name.equals("false") ) return newToken(FALSE); return id; } RecognitionException re = new NoViableAltException("", 0, 0, input); re.line = startLine; re.charPositionInLine = startCharPositionInLine; errMgr.lexerError(input.getSourceName(), "invalid character '"+str(c)+"'", templateToken, re); if ( c==EOF ) { return newToken(EOF_TYPE); } consume(); } } }
Example 17
Source File: SemicolonInjectionHelper.java From n4js with Eclipse Public License 1.0 | 4 votes |
/** * Recover from an error found on the input stream. This is for {@link NoViableAltException} and * {@link MismatchedTokenException}. If you enable single token insertion and deletion, this will usually not handle * mismatched symbol exceptions but there could be a mismatched token that the * {@link Parser#match(IntStream, int, BitSet) match} routine could not recover from. */ public static void recover(IntStream inputStream, RecognitionException re, Callback callback) { RecognizerSharedState state = callback.getState(); if (re instanceof MismatchedTokenException) { // We expected a specific token // if that is not a semicolon, ASI is pointless, perform normal recovery int expecting = ((MismatchedTokenException) re).expecting; if (expecting != InternalN4JSParser.Semicolon) { callback.discardError(); // delete ASI message, a previously added ASI may fix too much! cf. // IDEBUG-215 callback.recoverBase(inputStream, re); return; } } // System.out.println("Line: " + re.line + ":" + re.index); int unexpectedTokenType = re.token.getType(); if (!followedBySemicolon(state, callback.getRecoverySets(), re.index) || isOffendingToken(unexpectedTokenType)) { callback.recoverBase(inputStream, re); } else { int la = inputStream.LA(1); TokenStream casted = (TokenStream) inputStream; if (!isOffendingToken(la)) { // Start on the position before the current token and scan backwards off channel tokens until the // previous on channel token. for (int ix = re.token.getTokenIndex() - 1; ix > 0; ix--) { Token lt = casted.get(ix); if (lt.getChannel() == Token.DEFAULT_CHANNEL) { // On channel token found: stop scanning. callback.recoverBase(inputStream, re); return; } else if (lt.getType() == InternalN4JSParser.RULE_EOL) { // We found our EOL: everything's good, no need to do additional recovering // rule start. if (!callback.allowASI(re)) { callback.recoverBase(inputStream, re); return; } if (!findCommaBeforeEOL(casted, ix)) { callback.addASIMessage(); return; } } else if (lt.getType() == InternalN4JSParser.RULE_ML_COMMENT) { String tokenText = lt.getText(); if (!findCommaBeforeEOL(casted, ix) && (tokenText.indexOf('\n', 2) >= 2 || tokenText.indexOf('\r', 2) >= 2)) { callback.addASIMessage(); return; } } } callback.recoverBase(inputStream, re); } } }
Example 18
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+"import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }
Example 19
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+"import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }
Example 20
Source File: STGroupDir.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void importTemplates(Token fileNameToken) { String msg = "import illegal in group files embedded in STGroupDirs; "+"import "+fileNameToken.getText()+" in STGroupDir "+this.getName(); throw new UnsupportedOperationException(msg); }