tweak token consts.

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8668]
This commit is contained in:
parrt 2011-06-18 15:08:43 -08:00
parent da633613a7
commit 1d6ce54816
4 changed files with 10 additions and 9 deletions

View File

@ -29,18 +29,19 @@ package org.antlr.v4.runtime;
*/
public interface Token {
public static final int INVALID_TYPE = 0;
public static final Token INVALID_TOKEN = new CommonToken(INVALID_TYPE);
public static final int MIN_TOKEN_TYPE = 1;
/** imaginary tree navigation type; traverse "get child" link */
public static final int DOWN = 1;
/** imaginary tree navigation type; finish with a child list */
public static final int UP = 2;
public static final int MIN_TOKEN_TYPE = UP+1;
public static final int MIN_USER_TOKEN_TYPE = UP+1;
public static final int EOF = CharStream.EOF;
public static final int INVALID_TYPE = 0;
public static final Token INVALID_TOKEN = new CommonToken(INVALID_TYPE);
/** All tokens go to the parser (unless skip() is called in that rule)
* on a particular "channel". The parser tunes to a particular channel
* so that whitespace etc... can go to the parser on a "hidden" channel.

View File

@ -104,7 +104,7 @@ public class CodeGenerator {
// make constants for the token names
for (String t : g.tokenNameToTypeMap.keySet()) {
int tokenType = g.tokenNameToTypeMap.get(t);
if ( tokenType>=Token.MIN_TOKEN_TYPE ) {
if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) {
tokens.put(t, Utils.integer(tokenType));
}
}
@ -114,7 +114,7 @@ public class CodeGenerator {
Map<String,Integer> literals = new HashMap<String,Integer>();
for (String literal : g.stringLiteralToTypeMap.keySet()) {
int tokenType = g.stringLiteralToTypeMap.get(literal);
if ( tokenType>=Token.MIN_TOKEN_TYPE ) {
if ( tokenType>=Token.MIN_USER_TOKEN_TYPE) {
literals.put(literal, Utils.integer(tokenType));
}
}

View File

@ -74,7 +74,7 @@ public class Grammar implements AttributeResolver {
* like EPSILON. Char/String literals and token types overlap in the same
* space, however.
*/
int maxTokenType = Token.MIN_TOKEN_TYPE-1;
int maxTokenType = Token.MIN_USER_TOKEN_TYPE -1;
/** Map token like ID (but not literals like "while") to its token type */
public Map<String, Integer> tokenNameToTypeMap = new LinkedHashMap<String, Integer>();
@ -436,7 +436,7 @@ public class Grammar implements AttributeResolver {
if ( isLexer() ) {
return getAllCharValues();
}
return IntervalSet.of(Token.MIN_TOKEN_TYPE, getMaxTokenType());
return IntervalSet.of(Token.MIN_USER_TOKEN_TYPE, getMaxTokenType());
}
/** Return min to max char as defined by the target.

View File

@ -186,7 +186,7 @@ public class TestTokenTypeAssignment extends BaseTest {
for (Iterator iter = tokens.iterator(); iter.hasNext();) {
String tokenName = (String) iter.next();
assertTrue("unexpected token name "+tokenName,
g.getTokenType(tokenName) < Token.MIN_TOKEN_TYPE);
g.getTokenType(tokenName) < Token.MIN_USER_TOKEN_TYPE);
}
// make sure all expected rules are there