@Override public String toString() { StringBuilder s = new StringBuilder(); s.append("[").append(this.kind.toString()); if (this.kind.hasPayload()) { s.append(":").append(this.data); } s.append("]"); s.append("(").append(this.startPos).append(",").append(this.endPos).append(")"); return s.toString(); }
private void pushOneCharOrTwoCharToken(TokenKind kind, int pos, char[] data) { this.tokens.add(new Token(kind, data, pos, pos + kind.getLength())); }
@Override public String toString() { return (name() + (this.tokenChars.length !=0 ? "(" + new String(this.tokenChars) +")" : "")); }
private Token eatToken(TokenKind expectedKind) { Token t = nextToken(); if (t == null) { int pos = this.expressionString.length(); throw internalException(pos, SpelMessage.OOD); } if (t.kind != expectedKind) { throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase()); } return t; }
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 boolean peekToken(TokenKind desiredTokenKind, boolean consumeIfMatched) { Token t = peekToken(); if (t == null) { return false; } if (t.kind == desiredTokenKind) { if (consumeIfMatched) { this.tokenStreamPointer++; } return true; } if (desiredTokenKind == TokenKind.IDENTIFIER) { // Might be one of the textual forms of the operators (e.g. NE for != ) - // in which case we can treat it as an identifier. The list is represented here: // Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum. if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() && t.data != null) { // if t.data were null, we'd know it wasn't the textual form, it was the symbol form return true; } } return false; }
private Token eatToken(TokenKind expectedKind) { Token t = nextToken(); if (t == null) { int pos = this.expressionString.length(); throw internalException(pos, SpelMessage.OOD); } if (t.kind != expectedKind) { throw internalException(t.startPos, SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(), t.getKind().toString().toLowerCase()); } return t; }
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 boolean peekToken(TokenKind desiredTokenKind, boolean consumeIfMatched) { Token t = peekToken(); if (t == null) { return false; } if (t.kind == desiredTokenKind) { if (consumeIfMatched) { this.tokenStreamPointer++; } return true; } if (desiredTokenKind == TokenKind.IDENTIFIER) { // Might be one of the textual forms of the operators (e.g. NE for != ) - // in which case we can treat it as an identifier. The list is represented here: // Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum. if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() && t.data != null) { // if t.data were null, we'd know it wasn't the textual form, it was the symbol form return true; } } return false; }
public String toString(@Nullable Token t) { if (t == null) { return ""; } if (t.getKind().hasPayload()) { return t.stringValue(); } return t.kind.toString().toLowerCase(); }
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), node.startPos, node.endPos)); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { throw internalException( this.expressionString.length(), SpelMessage.OOD); } throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } return new QualifiedIdentifier(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition(), qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
@Override public String toString() { return (name() + (this.tokenChars.length !=0 ? "(" + new String(this.tokenChars) +")" : "")); }
private void pushOneCharOrTwoCharToken(TokenKind kind, int pos, char[] data) { this.tokens.add(new Token(kind, data, pos, pos + kind.getLength())); }
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 boolean peekToken(TokenKind desiredTokenKind, boolean consumeIfMatched) { Token t = peekToken(); if (t == null) { return false; } if (t.kind == desiredTokenKind) { if (consumeIfMatched) { this.tokenStreamPointer++; } return true; } if (desiredTokenKind == TokenKind.IDENTIFIER) { // Might be one of the textual forms of the operators (e.g. NE for != ) - // in which case we can treat it as an identifier. The list is represented here: // Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum. if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() && t.data != null) { // if t.data were null, we'd know it wasn't the textual form, it was the symbol form return true; } } return false; }
@Override public String toString() { StringBuilder s = new StringBuilder(); s.append("[").append(this.kind.toString()); if (this.kind.hasPayload()) { s.append(":").append(this.data); } s.append("]"); s.append("(").append(this.startPos).append(",").append(this.endPos).append(")"); return s.toString(); }
/** * Eat an identifier, possibly qualified (meaning that it is dotted). * TODO AndyC Could create complete identifiers (a.b.c) here rather than a sequence of them? (a, b, c) */ private SpelNodeImpl eatPossiblyQualifiedId() { Deque<SpelNodeImpl> qualifiedIdPieces = new ArrayDeque<>(); Token node = peekToken(); while (isValidQualifiedId(node)) { nextToken(); if (node.kind != TokenKind.DOT) { qualifiedIdPieces.add(new Identifier(node.stringValue(), toPos(node))); } node = peekToken(); } if (qualifiedIdPieces.isEmpty()) { if (node == null) { throw internalException( this.expressionString.length(), SpelMessage.OOD); } throw internalException(node.startPos, SpelMessage.NOT_EXPECTED_TOKEN, "qualified ID", node.getKind().toString().toLowerCase()); } int pos = toPos(qualifiedIdPieces.getFirst().getStartPosition(), qualifiedIdPieces.getLast().getEndPosition()); return new QualifiedIdentifier(pos, qualifiedIdPieces.toArray(new SpelNodeImpl[0])); }
@Override public String toString() { return (name() + (this.tokenChars.length !=0 ? "(" + new String(this.tokenChars) +")" : "")); }
private void pushOneCharOrTwoCharToken(TokenKind kind, int pos, char[] data) { this.tokens.add(new Token(kind, data, pos, pos + kind.getLength())); }
public String toString(@Nullable Token t) { if (t == null) { return ""; } if (t.getKind().hasPayload()) { return t.stringValue(); } return t.kind.toString().toLowerCase(); }