source: icXML/icXML-devel/src/xercesc/util/regx/ParserForXMLSchema.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 5.1 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: ParserForXMLSchema.cpp 678879 2008-07-22 20:05:05Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/util/regx/ParserForXMLSchema.hpp>
26#include <xercesc/util/regx/TokenFactory.hpp>
27#include <xercesc/util/regx/RangeToken.hpp>
28#include <xercesc/util/regx/TokenInc.hpp>
29#include <xercesc/util/regx/RegxDefs.hpp>
30#include <xercesc/util/ParseException.hpp>
31#include <xercesc/util/RuntimeException.hpp>
32#include <icxercesc/util/PlatformUtils.hpp>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36// ---------------------------------------------------------------------------
37//  ParserForXMLSchema: Constructors and Destructors
38// ---------------------------------------------------------------------------
39ParserForXMLSchema::ParserForXMLSchema(MemoryManager* const manager)
40    : RegxParser(manager)
41{
42
43}
44
45ParserForXMLSchema::~ParserForXMLSchema() {
46
47}
48
49// ---------------------------------------------------------------------------
50//  ParserForXMLSchema: Parsing/Processing methods
51// ---------------------------------------------------------------------------
52Token* ParserForXMLSchema::processCaret() {
53
54    // XML Schema treats "^" like any other char
55    processNext();
56    return getTokenFactory()->createChar(chCaret);
57}
58
59Token* ParserForXMLSchema::processDollar() {
60
61    // XML Schema treats "$" like any other char
62    processNext();
63    return getTokenFactory()->createChar(chDollarSign);
64}
65
66Token* ParserForXMLSchema::processPlus(Token* const tok) {
67
68    // XML Schema doesn't support reluctant quantifiers
69    processNext();
70    return getTokenFactory()->createConcat(tok,
71                               getTokenFactory()->createClosure(tok));
72}
73
74Token* ParserForXMLSchema::processStar(Token* const tok) {
75
76    // XML Schema doesn't support reluctant quantifiers
77    processNext();
78    return getTokenFactory()->createClosure(tok);
79}
80
81Token* ParserForXMLSchema::processQuestion(Token* const tok) {
82
83    // XML Schema doesn't support reluctant quantifiers
84    processNext();
85
86    TokenFactory* tokFactory = getTokenFactory();
87    Token* retTok = tokFactory->createUnion();
88    retTok->addChild(tok, tokFactory);
89    retTok->addChild(tokFactory->createToken(Token::T_EMPTY), tokFactory);
90    return retTok;
91}
92
93Token* ParserForXMLSchema::processParen() {
94
95    // XML Schema doesn't support back references
96    processNext();
97    Token* retTok = getTokenFactory()->createParenthesis(parseRegx(true), 0);
98
99    if (getState() != REGX_T_RPAREN) {
100        ThrowXMLwithMemMgr(ParseException, XMLExcepts::Parser_Factor1, getMemoryManager());
101    }
102
103    processNext();
104    return retTok;
105}
106
107Token* ParserForXMLSchema::processBackReference() {
108
109    // XML Schema doesn't support back references
110    ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, getMemoryManager());
111    return 0; // for compilers that complain about no return value
112}
113
114// ---------------------------------------------------------------------------
115//  ParserForXMLSchema: Helper methods
116// ---------------------------------------------------------------------------
117bool ParserForXMLSchema::checkQuestion(const XMLSize_t ) {
118
119    // XML Schema doesn't support reluctant quantifiers
120    return false;
121}
122
123
124XMLInt32 ParserForXMLSchema::decodeEscaped() {
125
126    // XML Schema doesn't support an escaped "$"
127    if (getState() != REGX_T_BACKSOLIDUS)
128        ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager());
129
130    XMLInt32 ch = getCharData();
131
132    switch (ch) {
133    case chLatin_n:
134        ch = chLF;
135        break;
136    case chLatin_r:
137        ch = chCR;
138        break;
139    case chLatin_t:
140        ch = chHTab;
141        break;
142    case chBackSlash:
143    case chPipe:
144    case chPeriod:
145    case chCaret:
146    case chDash:
147    case chQuestion:
148    case chAsterisk:
149    case chPlus:
150    case chOpenCurly:
151    case chCloseCurly:
152    case chOpenParen:
153    case chCloseParen:
154    case chOpenSquare:
155    case chCloseSquare:
156        break;
157    default:
158        {
159        XMLCh chString[] = {chBackSlash, ch, chNull};       
160        ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager());
161        }
162    }
163
164    return ch;
165}
166
167XERCES_CPP_NAMESPACE_END
168
169/**
170  * End of file ParserForXMLSchema.cpp
171  */
Note: See TracBrowser for help on using the repository browser.