本文整理汇总了Java中org.antlr.runtime.Token.getText方法的典型用法代码示例。如果您正苦于以下问题:Java Token.getText方法的具体用法?Java Token.getText怎么用?Java Token.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.runtime.Token
的用法示例。
在下文中一共展示了Token.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isSemicolonEquivalent
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/**
* Returns true if the given token is considered to be semicolon equivalent.
*/
static boolean isSemicolonEquivalent(Token lt) {
if (lt.getType() == InternalN4JSParser.RULE_EOL) {
return true;
}
if (lt.getType() == InternalN4JSParser.RULE_ML_COMMENT) {
String tokenText = lt.getText();
for (int i = 2; i < tokenText.length() - 2; i++) {
char c = tokenText.charAt(i);
if (c == '\n' || c == '\r') {
return true;
}
}
}
return false;
}
示例2: defineRegion
import org.antlr.runtime.Token; //导入方法依赖的package包/类
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;
}
示例3: defineRegion
import org.antlr.runtime.Token; //导入方法依赖的package包/类
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;
}
示例4: defineRegion
import org.antlr.runtime.Token; //导入方法依赖的package包/类
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;
}
示例5: basic_unreserved_keyword
import org.antlr.runtime.Token; //导入方法依赖的package包/类
public final String basic_unreserved_keyword() throws RecognitionException {
String str = null;
Token k=null;
try {
// Parser.g:1628:5: (k= ( K_KEYS | K_AS | K_CLUSTERING | K_COMPACT | K_STORAGE | K_TYPE | K_VALUES | K_MAP | K_LIST | K_FILTERING | K_PERMISSION | K_PERMISSIONS | K_KEYSPACES | K_ALL | K_USER | K_USERS | K_ROLE | K_ROLES | K_SUPERUSER | K_NOSUPERUSER | K_LOGIN | K_NOLOGIN | K_OPTIONS | K_PASSWORD | K_EXISTS | K_CUSTOM | K_TRIGGER | K_CONTAINS | K_STATIC | K_FROZEN | K_TUPLE | K_FUNCTION | K_FUNCTIONS | K_AGGREGATE | K_SFUNC | K_STYPE | K_FINALFUNC | K_INITCOND | K_RETURNS | K_LANGUAGE | K_CALLED | K_INPUT | K_LIKE | K_PER | K_PARTITION | K_GROUP ) )
// Parser.g:1628:7: k= ( K_KEYS | K_AS | K_CLUSTERING | K_COMPACT | K_STORAGE | K_TYPE | K_VALUES | K_MAP | K_LIST | K_FILTERING | K_PERMISSION | K_PERMISSIONS | K_KEYSPACES | K_ALL | K_USER | K_USERS | K_ROLE | K_ROLES | K_SUPERUSER | K_NOSUPERUSER | K_LOGIN | K_NOLOGIN | K_OPTIONS | K_PASSWORD | K_EXISTS | K_CUSTOM | K_TRIGGER | K_CONTAINS | K_STATIC | K_FROZEN | K_TUPLE | K_FUNCTION | K_FUNCTIONS | K_AGGREGATE | K_SFUNC | K_STYPE | K_FINALFUNC | K_INITCOND | K_RETURNS | K_LANGUAGE | K_CALLED | K_INPUT | K_LIKE | K_PER | K_PARTITION | K_GROUP )
{
k=input.LT(1);
if ( (input.LA(1) >= K_AGGREGATE && input.LA(1) <= K_ALL)||input.LA(1)==K_AS||input.LA(1)==K_CALLED||input.LA(1)==K_CLUSTERING||(input.LA(1) >= K_COMPACT && input.LA(1) <= K_CONTAINS)||input.LA(1)==K_CUSTOM||(input.LA(1) >= K_EXISTS && input.LA(1) <= K_FINALFUNC)||input.LA(1)==K_FROZEN||(input.LA(1) >= K_FUNCTION && input.LA(1) <= K_FUNCTIONS)||input.LA(1)==K_GROUP||(input.LA(1) >= K_INITCOND && input.LA(1) <= K_INPUT)||input.LA(1)==K_KEYS||(input.LA(1) >= K_KEYSPACES && input.LA(1) <= K_LIKE)||(input.LA(1) >= K_LIST && input.LA(1) <= K_MAP)||input.LA(1)==K_NOLOGIN||input.LA(1)==K_NOSUPERUSER||input.LA(1)==K_OPTIONS||(input.LA(1) >= K_PARTITION && input.LA(1) <= K_PERMISSIONS)||input.LA(1)==K_RETURNS||(input.LA(1) >= K_ROLE && input.LA(1) <= K_ROLES)||input.LA(1)==K_SFUNC||(input.LA(1) >= K_STATIC && input.LA(1) <= K_SUPERUSER)||input.LA(1)==K_TRIGGER||(input.LA(1) >= K_TUPLE && input.LA(1) <= K_TYPE)||(input.LA(1) >= K_USER && input.LA(1) <= K_USERS)||input.LA(1)==K_VALUES ) {
input.consume();
state.errorRecovery=false;
}
else {
MismatchedSetException mse = new MismatchedSetException(null,input);
throw mse;
}
str = (k!=null?k.getText():null);
}
}
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
finally {
// do for sure before leaving
}
return str;
}
示例6: toPrefixToken
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/**
* 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());
}
示例7: ParametrizedNode
import org.antlr.runtime.Token; //导入方法依赖的package包/类
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);
}
}
示例8: defineTemplateAlias
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/** 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;
}
示例9: importTemplates
import org.antlr.runtime.Token; //导入方法依赖的package包/类
@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);
}
示例10: setAttr
import org.antlr.runtime.Token; //导入方法依赖的package包/类
@Override
public void setAttr(String expr, Token x, Token rhs) {
gen.g.tool.log("action-translator", "setAttr "+x+" "+rhs);
List<ActionChunk> rhsChunks = translateActionChunk(factory,rf,rhs.getText(),node);
SetAttr s = new SetAttr(nodeContext, x.getText(), rhsChunks);
chunks.add(s);
}
示例11: defineTemplateAlias
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/** 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;
}
示例12: importTemplates
import org.antlr.runtime.Token; //导入方法依赖的package包/类
@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);
}
示例13: unreserved_keyword
import org.antlr.runtime.Token; //导入方法依赖的package包/类
public final String unreserved_keyword() throws RecognitionException {
String str = null;
Token k=null;
String u =null;
try {
// Parser.g:1618:5: (u= unreserved_function_keyword |k= ( K_TTL | K_COUNT | K_WRITETIME | K_KEY | K_CAST | K_JSON | K_DISTINCT ) )
int alt210=2;
int LA210_0 = input.LA(1);
if ( ((LA210_0 >= K_AGGREGATE && LA210_0 <= K_ALL)||LA210_0==K_AS||LA210_0==K_ASCII||(LA210_0 >= K_BIGINT && LA210_0 <= K_BOOLEAN)||LA210_0==K_CALLED||LA210_0==K_CLUSTERING||(LA210_0 >= K_COMPACT && LA210_0 <= K_CONTAINS)||LA210_0==K_COUNTER||(LA210_0 >= K_CUSTOM && LA210_0 <= K_DECIMAL)||LA210_0==K_DOUBLE||LA210_0==K_DURATION||(LA210_0 >= K_EXISTS && LA210_0 <= K_FLOAT)||LA210_0==K_FROZEN||(LA210_0 >= K_FUNCTION && LA210_0 <= K_FUNCTIONS)||LA210_0==K_GROUP||LA210_0==K_INET||(LA210_0 >= K_INITCOND && LA210_0 <= K_INPUT)||LA210_0==K_INT||LA210_0==K_KEYS||(LA210_0 >= K_KEYSPACES && LA210_0 <= K_LIKE)||(LA210_0 >= K_LIST && LA210_0 <= K_MAP)||LA210_0==K_NOLOGIN||LA210_0==K_NOSUPERUSER||LA210_0==K_OPTIONS||(LA210_0 >= K_PARTITION && LA210_0 <= K_PERMISSIONS)||LA210_0==K_RETURNS||(LA210_0 >= K_ROLE && LA210_0 <= K_ROLES)||(LA210_0 >= K_SFUNC && LA210_0 <= K_TINYINT)||LA210_0==K_TRIGGER||(LA210_0 >= K_TUPLE && LA210_0 <= K_TYPE)||(LA210_0 >= K_USER && LA210_0 <= K_USERS)||(LA210_0 >= K_UUID && LA210_0 <= K_VARINT)) ) {
alt210=1;
}
else if ( (LA210_0==K_CAST||LA210_0==K_COUNT||LA210_0==K_DISTINCT||(LA210_0 >= K_JSON && LA210_0 <= K_KEY)||LA210_0==K_TTL||LA210_0==K_WRITETIME) ) {
alt210=2;
}
else {
NoViableAltException nvae =
new NoViableAltException("", 210, 0, input);
throw nvae;
}
switch (alt210) {
case 1 :
// Parser.g:1618:7: u= unreserved_function_keyword
{
pushFollow(FOLLOW_unreserved_function_keyword_in_unreserved_keyword12108);
u=unreserved_function_keyword();
state._fsp--;
str = u;
}
break;
case 2 :
// Parser.g:1619:7: k= ( K_TTL | K_COUNT | K_WRITETIME | K_KEY | K_CAST | K_JSON | K_DISTINCT )
{
k=input.LT(1);
if ( input.LA(1)==K_CAST||input.LA(1)==K_COUNT||input.LA(1)==K_DISTINCT||(input.LA(1) >= K_JSON && input.LA(1) <= K_KEY)||input.LA(1)==K_TTL||input.LA(1)==K_WRITETIME ) {
input.consume();
state.errorRecovery=false;
}
else {
MismatchedSetException mse = new MismatchedSetException(null,input);
throw mse;
}
str = (k!=null?k.getText():null);
}
break;
}
}
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}
finally {
// do for sure before leaving
}
return str;
}
示例14: recover
import org.antlr.runtime.Token; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例15: importTemplates
import org.antlr.runtime.Token; //导入方法依赖的package包/类
@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);
}