GME  13
ParserForXMLSchema.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: ParserForXMLSchema.cpp 678879 2008-07-22 20:05:05Z amassari $
00020  */
00021 
00022 // ---------------------------------------------------------------------------
00023 //  Includes
00024 // ---------------------------------------------------------------------------
00025 #include <xercesc/util/regx/ParserForXMLSchema.hpp>
00026 #include <xercesc/util/regx/TokenFactory.hpp>
00027 #include <xercesc/util/regx/RangeToken.hpp>
00028 #include <xercesc/util/regx/TokenInc.hpp>
00029 #include <xercesc/util/regx/RegxDefs.hpp>
00030 #include <xercesc/util/ParseException.hpp>
00031 #include <xercesc/util/RuntimeException.hpp>
00032 #include <xercesc/util/PlatformUtils.hpp>
00033 
00034 XERCES_CPP_NAMESPACE_BEGIN
00035 
00036 // ---------------------------------------------------------------------------
00037 //  ParserForXMLSchema: Constructors and Destructors
00038 // ---------------------------------------------------------------------------
00039 ParserForXMLSchema::ParserForXMLSchema(MemoryManager* const manager)
00040     : RegxParser(manager)
00041 {
00042 
00043 }
00044 
00045 ParserForXMLSchema::~ParserForXMLSchema() {
00046 
00047 }
00048 
00049 // ---------------------------------------------------------------------------
00050 //  ParserForXMLSchema: Parsing/Processing methods
00051 // ---------------------------------------------------------------------------
00052 Token* ParserForXMLSchema::processCaret() {
00053 
00054     // XML Schema treats "^" like any other char
00055     processNext();
00056     return getTokenFactory()->createChar(chCaret);
00057 }
00058 
00059 Token* ParserForXMLSchema::processDollar() {
00060 
00061     // XML Schema treats "$" like any other char
00062     processNext();
00063     return getTokenFactory()->createChar(chDollarSign);
00064 }
00065 
00066 Token* ParserForXMLSchema::processPlus(Token* const tok) {
00067 
00068     // XML Schema doesn't support reluctant quantifiers
00069     processNext();
00070     return getTokenFactory()->createConcat(tok,
00071                                getTokenFactory()->createClosure(tok));
00072 }
00073 
00074 Token* ParserForXMLSchema::processStar(Token* const tok) {
00075 
00076     // XML Schema doesn't support reluctant quantifiers
00077     processNext();
00078     return getTokenFactory()->createClosure(tok);
00079 }
00080 
00081 Token* ParserForXMLSchema::processQuestion(Token* const tok) {
00082 
00083     // XML Schema doesn't support reluctant quantifiers
00084     processNext();
00085 
00086     TokenFactory* tokFactory = getTokenFactory();
00087     Token* retTok = tokFactory->createUnion();
00088     retTok->addChild(tok, tokFactory);
00089     retTok->addChild(tokFactory->createToken(Token::T_EMPTY), tokFactory);
00090     return retTok;
00091 }
00092 
00093 Token* ParserForXMLSchema::processParen() {
00094 
00095     // XML Schema doesn't support back references
00096     processNext();
00097     Token* retTok = getTokenFactory()->createParenthesis(parseRegx(true), 0);
00098 
00099     if (getState() != REGX_T_RPAREN) {
00100         ThrowXMLwithMemMgr(ParseException, XMLExcepts::Parser_Factor1, getMemoryManager());
00101     }
00102 
00103     processNext();
00104     return retTok;
00105 }
00106 
00107 Token* ParserForXMLSchema::processBackReference() {
00108 
00109     // XML Schema doesn't support back references
00110     ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, getMemoryManager());
00111     return 0; // for compilers that complain about no return value
00112 }
00113 
00114 // ---------------------------------------------------------------------------
00115 //  ParserForXMLSchema: Helper methods
00116 // ---------------------------------------------------------------------------
00117 bool ParserForXMLSchema::checkQuestion(const XMLSize_t ) {
00118 
00119     // XML Schema doesn't support reluctant quantifiers
00120     return false;
00121 }
00122 
00123 
00124 XMLInt32 ParserForXMLSchema::decodeEscaped() {
00125 
00126     // XML Schema doesn't support an escaped "$"
00127     if (getState() != REGX_T_BACKSOLIDUS)
00128         ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager());
00129 
00130     XMLInt32 ch = getCharData();
00131 
00132     switch (ch) {
00133     case chLatin_n:
00134         ch = chLF;
00135         break;
00136     case chLatin_r:
00137         ch = chCR;
00138         break;
00139     case chLatin_t:
00140         ch = chHTab;
00141         break;
00142     case chBackSlash:
00143     case chPipe:
00144     case chPeriod:
00145     case chCaret:
00146     case chDash:
00147     case chQuestion:
00148     case chAsterisk:
00149     case chPlus:
00150     case chOpenCurly:
00151     case chCloseCurly:
00152     case chOpenParen:
00153     case chCloseParen:
00154     case chOpenSquare:
00155     case chCloseSquare:
00156         break;
00157     default:
00158         {
00159         XMLCh chString[] = {chBackSlash, ch, chNull};        
00160         ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager());
00161         }
00162     }
00163 
00164     return ch;
00165 }
00166 
00167 XERCES_CPP_NAMESPACE_END
00168