parserforxmlschema.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 510 行 · 第 1/2 页
JAVA
510 行
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.impl.xpath.regex;import java.util.Hashtable;import java.util.Locale;/** * A regular expression parser for the XML Shema. * * @author TAMURA Kent <kent@trl.ibm.co.jp> * @version $Id: ParserForXMLSchema.java,v 1.5 2003/03/24 23:37:55 sandygao Exp $ */class ParserForXMLSchema extends RegexParser { public ParserForXMLSchema() { //this.setLocale(Locale.getDefault()); } public ParserForXMLSchema(Locale locale) { //this.setLocale(locale); } Token processCaret() throws ParseException { this.next(); return Token.createChar('^'); } Token processDollar() throws ParseException { this.next(); return Token.createChar('$'); } Token processLookahead() throws ParseException { throw ex("parser.process.1", this.offset); } Token processNegativelookahead() throws ParseException { throw ex("parser.process.1", this.offset); } Token processLookbehind() throws ParseException { throw ex("parser.process.1", this.offset); } Token processNegativelookbehind() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_A() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_Z() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_z() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_b() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_B() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_lt() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_gt() throws ParseException { throw ex("parser.process.1", this.offset); } Token processStar(Token tok) throws ParseException { this.next(); return Token.createClosure(tok); } Token processPlus(Token tok) throws ParseException { // X+ -> XX* this.next(); return Token.createConcat(tok, Token.createClosure(tok)); } Token processQuestion(Token tok) throws ParseException { // X? -> X| this.next(); Token par = Token.createUnion(); par.addChild(tok); par.addChild(Token.createEmpty()); return par; } boolean checkQuestion(int off) { return false; } Token processParen() throws ParseException { this.next(); Token tok = Token.createParen(this.parseRegex(), 0); if (this.read() != super.T_RPAREN) throw ex("parser.factor.1", this.offset-1); this.next(); // Skips ')' return tok; } Token processParen2() throws ParseException { throw ex("parser.process.1", this.offset); } Token processCondition() throws ParseException { throw ex("parser.process.1", this.offset); } Token processModifiers() throws ParseException { throw ex("parser.process.1", this.offset); } Token processIndependent() throws ParseException { throw ex("parser.process.1", this.offset); } Token processBacksolidus_c() throws ParseException { this.next(); return this.getTokenForShorthand('c'); } Token processBacksolidus_C() throws ParseException { this.next(); return this.getTokenForShorthand('C'); } Token processBacksolidus_i() throws ParseException { this.next(); return this.getTokenForShorthand('i'); } Token processBacksolidus_I() throws ParseException { this.next(); return this.getTokenForShorthand('I'); } Token processBacksolidus_g() throws ParseException { throw this.ex("parser.process.1", this.offset-2); } Token processBacksolidus_X() throws ParseException { throw ex("parser.process.1", this.offset-2); } Token processBackreference() throws ParseException { throw ex("parser.process.1", this.offset-4); } int processCIinCharacterClass(RangeToken tok, int c) { tok.mergeRanges(this.getTokenForShorthand(c)); return -1; } /** * Parses a character-class-expression, not a character-class-escape. * * c-c-expression ::= '[' c-group ']' * c-group ::= positive-c-group | negative-c-group | c-c-subtraction * positive-c-group ::= (c-range | c-c-escape)+ * negative-c-group ::= '^' positive-c-group * c-c-subtraction ::= (positive-c-group | negative-c-group) subtraction * subtraction ::= '-' c-c-expression * c-range ::= single-range | from-to-range * single-range ::= multi-c-escape | category-c-escape | block-c-escape | <any XML char> * cc-normal-c ::= <any character except [, ], \> * from-to-range ::= cc-normal-c '-' cc-normal-c * * @param useNrage Ignored. * @return This returns no NrageToken. */ protected RangeToken parseCharacterClass(boolean useNrange) throws ParseException { this.setContext(S_INBRACKETS); this.next(); // '[' boolean nrange = false; RangeToken base = null; RangeToken tok; if (this.read() == T_CHAR && this.chardata == '^') { nrange = true; this.next(); // '^' base = Token.createRange(); base.addRange(0, Token.UTF16_MAX); tok = Token.createRange(); } else { tok = Token.createRange(); } int type; boolean firstloop = true; while ((type = this.read()) != T_EOF) { // Don't use 'cotinue' for this loop. // single-range | from-to-range | subtraction if (type == T_CHAR && this.chardata == ']' && !firstloop) { if (nrange) { base.subtractRanges(tok); tok = base; } break; } int c = this.chardata; boolean end = false; if (type == T_BACKSOLIDUS) { switch (c) { case 'd': case 'D': case 'w': case 'W': case 's': case 'S': tok.mergeRanges(this.getTokenForShorthand(c)); end = true; break; case 'i': case 'I': case 'c': case 'C': c = this.processCIinCharacterClass(tok, c); if (c < 0) end = true; break; case 'p': case 'P': int pstart = this.offset; RangeToken tok2 = this.processBacksolidus_pP(c); if (tok2 == null) throw this.ex("parser.atom.5", pstart); tok.mergeRanges(tok2);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?