📄 lexer.java
字号:
} // fall through on purpose default : if (-1 == startSubstring) { startSubstring = i; isNum = Character.isDigit(c); } else if (isNum) { isNum = Character.isDigit(c); } } } if (startSubstring != -1) { isNum = false; isStartOfPat = mapPatternElemPos(nesting, isStartOfPat, isAttrName); if ((-1 != posOfNSSep) || ((m_namespaceContext != null) && (m_namespaceContext.handlesNullPrefixes()))) { posOfNSSep = mapNSTokens(pat, startSubstring, posOfNSSep, nChars); } else { addToTokenQueue(pat.substring(startSubstring, nChars)); } } if (0 == m_compiler.getTokenQueueSize()) { m_processor.error(XPATHErrorResources.ER_EMPTY_EXPRESSION, null); //"Empty expression!"); } else if (null != targetStrings) { recordTokenString(targetStrings); } m_processor.m_queueMark = 0; } /** * Record the current position on the token queue as long as * this is a top-level element. Must be called before the * next token is added to the m_tokenQueue. * * @param nesting The nesting count for the pattern element. * @param isStart true if this is the start of a pattern. * @param isAttrName true if we have determined that this is an attribute name. * * @return true if this is the start of a pattern. */ private boolean mapPatternElemPos(int nesting, boolean isStart, boolean isAttrName) { if (0 == nesting) { if(m_patternMapSize >= m_patternMap.length) { int patternMap[] = m_patternMap; int len = m_patternMap.length; m_patternMap = new int[m_patternMapSize + 100]; System.arraycopy(patternMap, 0, m_patternMap, 0, len); } if (!isStart) { m_patternMap[m_patternMapSize - 1] -= TARGETEXTRA; } m_patternMap[m_patternMapSize] = (m_compiler.getTokenQueueSize() - (isAttrName ? 1 : 0)) + TARGETEXTRA; m_patternMapSize++; isStart = false; } return isStart; } /** * Given a map pos, return the corresponding token queue pos. * * @param i The index in the m_patternMap. * * @return the token queue position. */ private int getTokenQueuePosFromMap(int i) { int pos = m_patternMap[i]; return (pos >= TARGETEXTRA) ? (pos - TARGETEXTRA) : pos; } /** * Reset token queue mark and m_token to a * given position. * @param mark The new position. */ private final void resetTokenMark(int mark) { int qsz = m_compiler.getTokenQueueSize(); m_processor.m_queueMark = (mark > 0) ? ((mark <= qsz) ? mark - 1 : mark) : 0; if (m_processor.m_queueMark < qsz) { m_processor.m_token = (String) m_compiler.getTokenQueue().elementAt(m_processor.m_queueMark++); m_processor.m_tokenChar = m_processor.m_token.charAt(0); } else { m_processor.m_token = null; m_processor.m_tokenChar = 0; } } /** * Given a string, return the corresponding keyword token. * * @param key The keyword. * * @return An opcode value. */ final int getKeywordToken(String key) { int tok; try { Integer itok = (Integer) Keywords.getKeyWord(key); tok = (null != itok) ? itok.intValue() : 0; } catch (NullPointerException npe) { tok = 0; } catch (ClassCastException cce) { tok = 0; } return tok; } /** * Record the current token in the passed vector. * * @param targetStrings Vector of string. */ private void recordTokenString(Vector targetStrings) { int tokPos = getTokenQueuePosFromMap(m_patternMapSize - 1); resetTokenMark(tokPos + 1); if (m_processor.lookahead('(', 1)) { int tok = getKeywordToken(m_processor.m_token); switch (tok) { case OpCodes.NODETYPE_COMMENT : targetStrings.addElement(PsuedoNames.PSEUDONAME_COMMENT); break; case OpCodes.NODETYPE_TEXT : targetStrings.addElement(PsuedoNames.PSEUDONAME_TEXT); break; case OpCodes.NODETYPE_NODE : targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY); break; case OpCodes.NODETYPE_ROOT : targetStrings.addElement(PsuedoNames.PSEUDONAME_ROOT); break; case OpCodes.NODETYPE_ANYELEMENT : targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY); break; case OpCodes.NODETYPE_PI : targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY); break; default : targetStrings.addElement(PsuedoNames.PSEUDONAME_ANY); } } else { if (m_processor.tokenIs('@')) { tokPos++; resetTokenMark(tokPos + 1); } if (m_processor.lookahead(':', 1)) { tokPos += 2; } targetStrings.addElement(m_compiler.getTokenQueue().elementAt(tokPos)); } } /** * Add a token to the token queue. * * * @param s The token. */ private final void addToTokenQueue(String s) { m_compiler.getTokenQueue().addElement(s); } /** * When a seperator token is found, see if there's a element name or * the like to map. * * @param pat The XPath name string. * @param startSubstring The start of the name string. * @param posOfNSSep The position of the namespace seperator (':'). * @param posOfScan The end of the name index. * * @throws javax.xml.transform.TransformerException * * @return -1 always. */ private int mapNSTokens(String pat, int startSubstring, int posOfNSSep, int posOfScan) throws javax.xml.transform.TransformerException { String prefix = ""; if ((startSubstring >= 0) && (posOfNSSep >= 0)) { prefix = pat.substring(startSubstring, posOfNSSep); } String uName; if ((null != m_namespaceContext) &&!prefix.equals("*") &&!prefix.equals("xmlns")) { try { if (prefix.length() > 0) uName = ((PrefixResolver) m_namespaceContext).getNamespaceForPrefix( prefix); else { // Assume last was wildcard. This is not legal according // to the draft. Set the below to true to make namespace // wildcards work. if (false) { addToTokenQueue(":"); String s = pat.substring(posOfNSSep + 1, posOfScan); if (s.length() > 0) addToTokenQueue(s); return -1; } else { uName = ((PrefixResolver) m_namespaceContext).getNamespaceForPrefix( prefix); } } } catch (ClassCastException cce) { uName = m_namespaceContext.getNamespaceForPrefix(prefix); } } else { uName = prefix; } if ((null != uName) && (uName.length() > 0)) { addToTokenQueue(uName); addToTokenQueue(":"); String s = pat.substring(posOfNSSep + 1, posOfScan); if (s.length() > 0) addToTokenQueue(s); } else { // To older XPath code it doesn't matter if // error() is called or errorForDOM3(). m_processor.errorForDOM3(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE, new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";/** old code commented out 17-Sep-2004// error("Could not locate namespace for prefix: "+prefix);// m_processor.error(XPATHErrorResources.ER_PREFIX_MUST_RESOLVE,// new String[] {prefix}); //"Prefix must resolve to a namespace: {0}";*/ /*** Old code commented out 10-Jan-2001 addToTokenQueue(prefix); addToTokenQueue(":"); String s = pat.substring(posOfNSSep + 1, posOfScan); if (s.length() > 0) addToTokenQueue(s); ***/ } return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -