public Token asBetweenToken() { return new Token(TokenKind.BETWEEN, this.startPos, this.endPos); }
public Token asInstanceOfToken() { return new Token(TokenKind.INSTANCEOF, this.startPos, this.endPos); }
public Token asMatchesToken() { return new Token(TokenKind.MATCHES, this.startPos, this.endPos); }
/** * Push a token of just one character in length. */ private void pushCharToken(TokenKind kind) { this.tokens.add(new Token(kind, this.pos, this.pos + 1)); this.pos++; }
/** * Push a token of two characters in length. */ private void pushPairToken(TokenKind kind) { this.tokens.add(new Token(kind, this.pos, this.pos + 2)); this.pos += 2; }
public Token asInstanceOfToken() { return new Token(TokenKind.INSTANCEOF, this.startPos, this.endPos); }
public Token asBetweenToken() { return new Token(TokenKind.BETWEEN, this.startPos, this.endPos); }
private void pushOneCharOrTwoCharToken(TokenKind kind, int pos, char[] data) { this.tokens.add(new Token(kind, data, pos, pos + kind.getLength())); }
private void pushHexIntToken(char[] data, boolean isLong, int start, int end) { if (data.length == 0) { if (isLong) { raiseParseException(start, SpelMessage.NOT_A_LONG, this.expressionString.substring(start, end + 1)); } else { raiseParseException(start, SpelMessage.NOT_AN_INTEGER, this.expressionString.substring(start, end)); } } if (isLong) { this.tokens.add(new Token(TokenKind.LITERAL_HEXLONG, data, start, end)); } else { this.tokens.add(new Token(TokenKind.LITERAL_HEXINT, data, start, end)); } }
/** * Push a token of just one character in length. */ private void pushCharToken(TokenKind kind) { this.tokens.add(new Token(kind, this.pos, this.pos + 1)); this.pos++; }
/** * Push a token of two characters in length. */ private void pushPairToken(TokenKind kind) { this.tokens.add(new Token(kind, this.pos, this.pos + 2)); this.pos += 2; }
private void lexIdentifier() { int start = this.pos; do { this.pos++; } while (isIdentifier(this.charsToProcess[this.pos])); char[] subarray = subarray(start, this.pos); // Check if this is the alternative (textual) representation of an operator (see // alternativeOperatorNames) if ((this.pos - start) == 2 || (this.pos - start) == 3) { String asString = new String(subarray).toUpperCase(); int idx = Arrays.binarySearch(ALTERNATIVE_OPERATOR_NAMES, asString); if (idx >= 0) { pushOneCharOrTwoCharToken(TokenKind.valueOf(asString), start, subarray); return; } } this.tokens.add(new Token(TokenKind.IDENTIFIER, subarray, start, this.pos)); }
private void pushHexIntToken(char[] data, boolean isLong, int start, int end) { if (data.length == 0) { if (isLong) { raiseParseException(start, SpelMessage.NOT_A_LONG, this.expressionString.substring(start, end + 1)); } else { raiseParseException(start, SpelMessage.NOT_AN_INTEGER, this.expressionString.substring(start, end)); } } if (isLong) { this.tokens.add(new Token(TokenKind.LITERAL_HEXLONG, data, start, end)); } else { this.tokens.add(new Token(TokenKind.LITERAL_HEXINT, data, start, end)); } }
private void lexDoubleQuotedStringLiteral() { int start = this.pos; boolean terminated = false; while (!terminated) { this.pos++; char ch = this.charsToProcess[this.pos]; if (ch == '"') { // may not be the end if the char after is also a " if (this.charsToProcess[this.pos + 1] == '"') { this.pos++; // skip over that too, and continue } else { terminated = true; } } if (isExhausted()) { raiseParseException(start, SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING); } } this.pos++; this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos)); }
private void lexQuotedStringLiteral() { int start = this.pos; boolean terminated = false; while (!terminated) { this.pos++; char ch = this.charsToProcess[this.pos]; if (ch == '\'') { // may not be the end if the char after is also a ' if (this.charsToProcess[this.pos + 1] == '\'') { this.pos++; // skip over that too, and continue } else { terminated = true; } } if (isExhausted()) { raiseParseException(start, SpelMessage.NON_TERMINATING_QUOTED_STRING); } } this.pos++; this.tokens.add(new Token(TokenKind.LITERAL_STRING, subarray(start, this.pos), start, this.pos)); }
@Test public void token() { Token token = new Token(TokenKind.NOT, 0, 3); assertEquals(TokenKind.NOT, token.kind); assertEquals(0, token.startPos); assertEquals(3, token.endPos); assertEquals("[NOT(!)](0,3)", token.toString()); token = new Token(TokenKind.LITERAL_STRING, "abc".toCharArray(), 0, 3); assertEquals(TokenKind.LITERAL_STRING, token.kind); assertEquals(0, token.startPos); assertEquals(3, token.endPos); assertEquals("[LITERAL_STRING:abc](0,3)", token.toString()); }