private Token leftBracket() { Token token = new Token( TokenTypes.LEFT_BRACKET, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
String getTokenText() { return this.parseText.substring( getTokenBegin(), getTokenEnd() ); }
public String toString() { return ("[ (" + tokenType + ") (" + getTokenText() + ")"); } }
Token(int tokenType, String parseText, int tokenBegin, int tokenEnd) { setTokenType( tokenType ); setParseText( parseText ); setTokenBegin( tokenBegin ); setTokenEnd( tokenEnd ); }
token = new Token( TokenTypes.EOF, getXPath(), this.currentPosition, token = new Token( TokenTypes.ERROR, getXPath(), this.currentPosition, while (token.getTokenType() == TokenTypes.SKIP ); switch ( token.getTokenType() )
private XPathSyntaxException createSyntaxException(String message) { String xpath = this.lexer.getXPath(); int position = LT(1).getTokenBegin(); return new XPathSyntaxException( xpath, position, message ); }
private int LA(int position) { return LT(position).getTokenType(); }
private void throwInvalidAxis(String invalidAxis) throws SAXPathException { String xpath = this.lexer.getXPath(); int position = LT(1).getTokenBegin(); String message = "Expected valid axis name instead of [" + invalidAxis + "]"; throw new XPathSyntaxException( xpath, position, message ); } }
private Token match(int tokenType) throws XPathSyntaxException { LT(1); Token token = (Token) tokens.get( 0 ); if ( token.getTokenType() == tokenType ) { tokens.remove(0); return token; } XPathSyntaxException ex = createSyntaxException( "Expected: " + TokenTypes.getTokenText( tokenType ) ); throw ex; }
private Token rightBracket() { Token token = new Token( TokenTypes.RIGHT_BRACKET, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
private boolean isNodeTypeName(Token name) { String text = name.getTokenText(); if ( "node".equals( text ) || "comment".equals( text ) || "text".equals( text ) || "processing-instruction".equals( text ) ) { return true; } return false; }
private Token comma() { Token token = new Token( TokenTypes.COMMA, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
private void literal() throws SAXPathException { Token token = match( TokenTypes.LITERAL ); getXPathHandler().literal( token.getTokenText() ); }
private Token minus() { Token token = new Token( TokenTypes.MINUS, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
private void variableReference() throws SAXPathException { match( TokenTypes.DOLLAR ); String prefix = null; String variableName = null; if ( LA(2) == TokenTypes.COLON ) { prefix = match( TokenTypes.IDENTIFIER ).getTokenText(); match( TokenTypes.COLON ); } else { prefix = ""; } variableName = match( TokenTypes.IDENTIFIER ).getTokenText(); getXPathHandler().variableReference( prefix, variableName ); }
private Token colon() { Token token = new Token( TokenTypes.COLON, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
private int axisSpecifier() throws SAXPathException { int axis = 0; switch ( LA(1) ) { case TokenTypes.AT: { match( TokenTypes.AT ); axis = Axis.ATTRIBUTE; break; } case TokenTypes.IDENTIFIER: { Token token = LT( 1 ); axis = Axis.lookup( token.getTokenText() ); if ( axis == Axis.INVALID_AXIS ) { throwInvalidAxis( token.getTokenText() ); } match( TokenTypes.IDENTIFIER ); match( TokenTypes.DOUBLE_COLON ); break; } } return axis; }
private Token leftParen() { Token token = new Token( TokenTypes.LEFT_PAREN, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }
private void functionCall() throws SAXPathException { String prefix = null; String functionName = null; if ( LA(2) == TokenTypes.COLON ) { prefix = match( TokenTypes.IDENTIFIER ).getTokenText(); match( TokenTypes.COLON ); } else { prefix = ""; } functionName = match( TokenTypes.IDENTIFIER ).getTokenText(); getXPathHandler().startFunction( prefix, functionName ); match ( TokenTypes.LEFT_PAREN ); arguments(); match ( TokenTypes.RIGHT_PAREN ); getXPathHandler().endFunction(); }
private Token equals() { Token token = new Token( TokenTypes.EQUALS, getXPath(), this.currentPosition, this.currentPosition+1 ); consume(); return token; }