PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ATF2/control-software/epics-3.14.8/extensions/src/ChannelArchiver/ThirdParty/xerces-c-src2_4_0/src/xercesc/util/regx/ParserForXMLSchema.cpp

http://atf2flightsim.googlecode.com/
C++ | 576 lines | 334 code | 111 blank | 131 comment | 69 complexity | e5561f4f32992cfbe1fa6b75a66e300e MD5 | raw file
Possible License(s): BSD-2-Clause, LGPL-2.0, IPL-1.0, BSD-3-Clause
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2001 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution,
  20. * if any, must include the following acknowledgment:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowledgment may appear in the software itself,
  24. * if and wherever such third-party acknowledgments normally appear.
  25. *
  26. * 4. The names "Xerces" and "Apache Software Foundation" must
  27. * not be used to endorse or promote products derived from this
  28. * software without prior written permission. For written
  29. * permission, please contact apache\@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache",
  32. * nor may "Apache" appear in their name, without prior written
  33. * permission of the Apache Software Foundation.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation, and was
  51. * originally based on software copyright (c) 2001, International
  52. * Business Machines, Inc., http://www.ibm.com . For more information
  53. * on the Apache Software Foundation, please see
  54. * <http://www.apache.org/>.
  55. */
  56. /*
  57. * $Log: ParserForXMLSchema.cpp,v $
  58. * Revision 1.1.1.1 2009/03/14 06:42:33 whitegr
  59. * epics channel archiver
  60. *
  61. * Revision 1.6 2003/05/15 18:42:54 knoaman
  62. * Partial implementation of the configurable memory manager.
  63. *
  64. * Revision 1.5 2003/03/18 19:38:28 knoaman
  65. * Schema Errata E2-18 + misc. regex fixes.
  66. *
  67. * Revision 1.4 2003/01/13 19:02:23 knoaman
  68. * [Bug 14390] C++ Indentifier collision with Python.
  69. *
  70. * Revision 1.3 2002/11/04 15:17:00 tng
  71. * C++ Namespace Support.
  72. *
  73. * Revision 1.2 2002/03/18 19:29:53 knoaman
  74. * Change constant names to eliminate possible conflict with user defined ones.
  75. *
  76. * Revision 1.1.1.1 2002/02/01 22:22:29 peiyongz
  77. * sane_include
  78. *
  79. * Revision 1.6 2001/09/20 13:11:42 knoaman
  80. * Regx + misc. fixes
  81. *
  82. * Revision 1.5 2001/06/01 14:15:37 knoaman
  83. * Add a return value to satisfy compilers that complain about
  84. * no return value, although that code will not be executed.
  85. *
  86. * Revision 1.4 2001/05/11 21:50:56 knoaman
  87. * Schema updates and fixes.
  88. *
  89. * Revision 1.3 2001/05/11 13:26:44 tng
  90. * Copyright update.
  91. *
  92. * Revision 1.2 2001/05/03 18:17:30 knoaman
  93. * Some design changes:
  94. * o Changed the TokenFactory from a single static instance, to a
  95. * normal class. Each RegularExpression object will have its own
  96. * instance of TokenFactory, and that instance will be passed to
  97. * other classes that need to use a TokenFactory to create Token
  98. * objects (with the exception of RangeTokenMap).
  99. * o Added a new class RangeTokenMap to map a the different ranges
  100. * in a given category to a specific RangeFactory object. In the old
  101. * design RangeFactory had dual functionality (act as a Map, and as
  102. * a factory for creating RangeToken(s)). The RangeTokenMap will
  103. * have its own copy of the TokenFactory. There will be only one
  104. * instance of the RangeTokenMap class, and that instance will be
  105. * lazily deleted when XPlatformUtils::Terminate is called.
  106. *
  107. * Revision 1.1 2001/03/02 19:26:43 knoaman
  108. * Schema: Regular expression handling part II
  109. *
  110. */
  111. // ---------------------------------------------------------------------------
  112. // Includes
  113. // ---------------------------------------------------------------------------
  114. #include <xercesc/util/regx/ParserForXMLSchema.hpp>
  115. #include <xercesc/util/regx/TokenFactory.hpp>
  116. #include <xercesc/util/regx/RangeToken.hpp>
  117. #include <xercesc/util/regx/TokenInc.hpp>
  118. #include <xercesc/util/regx/RegxDefs.hpp>
  119. #include <xercesc/util/ParseException.hpp>
  120. #include <xercesc/util/RuntimeException.hpp>
  121. #include <xercesc/util/PlatformUtils.hpp>
  122. XERCES_CPP_NAMESPACE_BEGIN
  123. // ---------------------------------------------------------------------------
  124. // ParserForXMLSchema: Constructors and Destructors
  125. // ---------------------------------------------------------------------------
  126. ParserForXMLSchema::ParserForXMLSchema(MemoryManager* const manager)
  127. : RegxParser(manager)
  128. {
  129. }
  130. ParserForXMLSchema::~ParserForXMLSchema() {
  131. }
  132. // ---------------------------------------------------------------------------
  133. // ParserForXMLSchema: Parsing/Processing methods
  134. // ---------------------------------------------------------------------------
  135. Token* ParserForXMLSchema::processCaret() {
  136. processNext();
  137. return getTokenFactory()->createChar(chCaret);
  138. }
  139. Token* ParserForXMLSchema::processDollar() {
  140. processNext();
  141. return getTokenFactory()->createChar(chDollarSign);
  142. }
  143. Token* ParserForXMLSchema::processPlus(Token* const tok) {
  144. processNext();
  145. return getTokenFactory()->createConcat(tok,
  146. getTokenFactory()->createClosure(tok));
  147. }
  148. Token* ParserForXMLSchema::processStar(Token* const tok) {
  149. processNext();
  150. return getTokenFactory()->createClosure(tok);
  151. }
  152. Token* ParserForXMLSchema::processQuestion(Token* const tok) {
  153. processNext();
  154. TokenFactory* tokFactory = getTokenFactory();
  155. Token* retTok = tokFactory->createUnion();
  156. retTok->addChild(tok, tokFactory);
  157. retTok->addChild(tokFactory->createToken(Token::T_EMPTY), tokFactory);
  158. return retTok;
  159. }
  160. Token* ParserForXMLSchema::processParen() {
  161. processNext();
  162. Token* retTok = getTokenFactory()->createParenthesis(parseRegx(true), 0);
  163. if (getState() != REGX_T_RPAREN) {
  164. ThrowXML(ParseException, XMLExcepts::Parser_Factor1);
  165. }
  166. processNext();
  167. return retTok;
  168. }
  169. RangeToken* ParserForXMLSchema::parseCharacterClass(const bool useNRange) {
  170. setParseContext(S_INBRACKETS);
  171. processNext();
  172. RangeToken* base = 0;
  173. RangeToken* tok = 0;
  174. bool isNRange = false;
  175. if (getState() == REGX_T_CHAR && getCharData() == chCaret) {
  176. isNRange = true;
  177. processNext();
  178. base = getTokenFactory()->createRange();
  179. base->addRange(0, Token::UTF16_MAX);
  180. tok = getTokenFactory()->createRange();
  181. }
  182. else {
  183. tok= getTokenFactory()->createRange();
  184. }
  185. int type;
  186. bool firstLoop = true;
  187. while ( (type = getState()) != REGX_T_EOF) {
  188. // single range | from-to-range | subtraction
  189. if (type == REGX_T_CHAR && getCharData() == chCloseSquare && !firstLoop) {
  190. if (isNRange) {
  191. base->subtractRanges(tok);
  192. tok = base;
  193. }
  194. break;
  195. }
  196. XMLInt32 ch = getCharData();
  197. bool end = false;
  198. if (type == REGX_T_BACKSOLIDUS) {
  199. switch(ch) {
  200. case chLatin_d:
  201. case chLatin_D:
  202. case chLatin_w:
  203. case chLatin_W:
  204. case chLatin_s:
  205. case chLatin_S:
  206. {
  207. tok->mergeRanges(getTokenForShorthand(ch));
  208. end = true;
  209. }
  210. break;
  211. case chLatin_i:
  212. case chLatin_I:
  213. case chLatin_c:
  214. case chLatin_C:
  215. {
  216. ch = processCInCharacterClass(tok, ch);
  217. if (ch < 0) {
  218. end = true;
  219. }
  220. }
  221. break;
  222. case chLatin_p:
  223. case chLatin_P:
  224. {
  225. int start = getOffset();
  226. RangeToken* tok2 = processBacksolidus_pP(ch);
  227. if (tok2 == 0) {
  228. ThrowXML(ParseException,XMLExcepts::Parser_Atom5);
  229. }
  230. tok->mergeRanges(tok2);
  231. end = true;
  232. }
  233. break;
  234. default:
  235. ch = decodeEscaped();
  236. }
  237. } // end if REGX_T_BACKSOLIDUS
  238. else if (type == REGX_T_XMLSCHEMA_CC_SUBTRACTION && !firstLoop) {
  239. if (isNRange) {
  240. base->subtractRanges(tok);
  241. tok = base;
  242. }
  243. RangeToken* rangeTok = parseCharacterClass(false);
  244. tok->subtractRanges(rangeTok);
  245. if (getState() != REGX_T_CHAR || getCharData() != chCloseSquare) {
  246. ThrowXML(ParseException,XMLExcepts::Parser_CC5);
  247. }
  248. break;
  249. } // end if REGX_T_XMLSCHEMA...
  250. processNext();
  251. if (!end) {
  252. if (type == REGX_T_CHAR
  253. && (ch == chOpenSquare
  254. || ch == chCloseSquare
  255. || ch == chDash)) {
  256. // '[', ']', '-' not allowed and should be esacaped
  257. XMLCh chStr[] = { ch, chNull };
  258. ThrowXML2(ParseException,XMLExcepts::Parser_CC6, chStr, chStr);
  259. }
  260. if (getState() != REGX_T_CHAR || getCharData() != chDash) {
  261. tok->addRange(ch, ch);
  262. }
  263. else {
  264. processNext();
  265. if ((type = getState()) == REGX_T_EOF)
  266. ThrowXML(ParseException,XMLExcepts::Parser_CC2);
  267. if ((type == REGX_T_CHAR && getCharData() == chCloseSquare)
  268. || type == REGX_T_XMLSCHEMA_CC_SUBTRACTION) {
  269. static const XMLCh dashStr[] = { chDash, chNull};
  270. ThrowXML2(ParseException, XMLExcepts::Parser_CC6, dashStr, dashStr);
  271. }
  272. else {
  273. XMLInt32 rangeEnd = getCharData();
  274. XMLCh rangeEndStr[] = { rangeEnd, chNull };
  275. if (type == REGX_T_CHAR) {
  276. if (rangeEnd == chOpenSquare
  277. || rangeEnd == chCloseSquare
  278. || rangeEnd == chDash)
  279. // '[', ']', '-' not allowed and should be esacaped
  280. ThrowXML2(ParseException, XMLExcepts::Parser_CC6, rangeEndStr, rangeEndStr);
  281. }
  282. else if (type == REGX_T_BACKSOLIDUS) {
  283. rangeEnd = decodeEscaped();
  284. }
  285. processNext();
  286. if (ch > rangeEnd) {
  287. XMLCh chStr[] = { ch, chNull };
  288. ThrowXML2(ParseException,XMLExcepts::Parser_Ope3, rangeEndStr, chStr);
  289. }
  290. tok->addRange(ch, rangeEnd);
  291. }
  292. }
  293. }
  294. firstLoop = false;
  295. }
  296. if (getState() == REGX_T_EOF)
  297. ThrowXML(ParseException,XMLExcepts::Parser_CC2);
  298. tok->sortRanges();
  299. tok->compactRanges();
  300. setParseContext(S_NORMAL);
  301. processNext();
  302. return tok;
  303. }
  304. XMLInt32 ParserForXMLSchema::processCInCharacterClass(RangeToken* const tok,
  305. const XMLInt32 ch)
  306. {
  307. tok->mergeRanges(getTokenForShorthand(ch));
  308. return -1;
  309. }
  310. Token* ParserForXMLSchema::processLook(const unsigned short tokType) {
  311. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  312. return 0; // for compilers that complain about no return value
  313. }
  314. Token* ParserForXMLSchema::processBacksolidus_A() {
  315. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  316. return 0; // for compilers that complain about no return value
  317. }
  318. Token* ParserForXMLSchema::processBacksolidus_B() {
  319. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  320. return 0; // for compilers that complain about no return value
  321. }
  322. Token* ParserForXMLSchema::processBacksolidus_b() {
  323. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  324. return 0; // for compilers that complain about no return value
  325. }
  326. Token* ParserForXMLSchema::processBacksolidus_C() {
  327. processNext();
  328. return getTokenForShorthand(chLatin_C);
  329. }
  330. Token* ParserForXMLSchema::processBacksolidus_c() {
  331. processNext();
  332. return getTokenForShorthand(chLatin_c);
  333. }
  334. Token* ParserForXMLSchema::processBacksolidus_g() {
  335. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  336. return 0; // for compilers that complain about no return value
  337. }
  338. Token* ParserForXMLSchema::processBacksolidus_gt() {
  339. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  340. return 0; // for compilers that complain about no return value
  341. }
  342. Token* ParserForXMLSchema::processBacksolidus_I() {
  343. processNext();
  344. return getTokenForShorthand(chLatin_I);
  345. }
  346. Token* ParserForXMLSchema::processBacksolidus_i() {
  347. processNext();
  348. return getTokenForShorthand(chLatin_i);
  349. }
  350. Token* ParserForXMLSchema::processBacksolidus_lt() {
  351. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  352. return 0; // for compilers that complain about no return value
  353. }
  354. Token* ParserForXMLSchema::processBacksolidus_X() {
  355. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  356. return 0; // for compilers that complain about no return value
  357. }
  358. Token* ParserForXMLSchema::processBacksolidus_Z() {
  359. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  360. return 0; // for compilers that complain about no return value
  361. }
  362. Token* ParserForXMLSchema::processBacksolidus_z() {
  363. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  364. return 0; // for compilers that complain about no return value
  365. }
  366. Token* ParserForXMLSchema::processBackReference() {
  367. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  368. return 0; // for compilers that complain about no return value
  369. }
  370. Token* ParserForXMLSchema::processCondition() {
  371. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  372. return 0; // for compilers that complain about no return value
  373. }
  374. Token* ParserForXMLSchema::processIndependent() {
  375. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  376. return 0; // for compilers that complain about no return value
  377. }
  378. Token* ParserForXMLSchema::processModifiers() {
  379. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  380. return 0; // for compilers that complain about no return value
  381. }
  382. Token* ParserForXMLSchema::processParen2() {
  383. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  384. return 0; // for compilers that complain about no return value
  385. }
  386. RangeToken* ParserForXMLSchema::parseSetOperations() {
  387. ThrowXML(RuntimeException, XMLExcepts::Regex_NotSupported);
  388. return 0; // for compilers that complain about no return value
  389. }
  390. // ---------------------------------------------------------------------------
  391. // ParserForXMLSchema: Getter methods
  392. // ---------------------------------------------------------------------------
  393. Token* ParserForXMLSchema::getTokenForShorthand(const XMLInt32 ch) {
  394. switch(ch) {
  395. case chLatin_d:
  396. return getTokenFactory()->getRange(fgXMLDigit);
  397. case chLatin_D:
  398. return getTokenFactory()->getRange(fgXMLDigit, true);
  399. case chLatin_w:
  400. return getTokenFactory()->getRange(fgXMLWord);
  401. case chLatin_W:
  402. return getTokenFactory()->getRange(fgXMLWord, true);
  403. case chLatin_s:
  404. return getTokenFactory()->getRange(fgXMLSpace);
  405. case chLatin_S:
  406. return getTokenFactory()->getRange(fgXMLSpace, true);
  407. case chLatin_c:
  408. return getTokenFactory()->getRange(fgXMLNameChar);
  409. case chLatin_C:
  410. return getTokenFactory()->getRange(fgXMLNameChar, true);
  411. case chLatin_i:
  412. return getTokenFactory()->getRange(fgXMLInitialNameChar);
  413. case chLatin_I:
  414. return getTokenFactory()->getRange(fgXMLInitialNameChar, true);
  415. }
  416. return 0;
  417. }
  418. // ---------------------------------------------------------------------------
  419. // ParserForXMLSchema: Helper methods
  420. // ---------------------------------------------------------------------------
  421. bool ParserForXMLSchema::checkQuestion(const int off) {
  422. return false;
  423. }
  424. XMLInt32 ParserForXMLSchema::decodeEscaped() {
  425. if (getState() != REGX_T_BACKSOLIDUS)
  426. ThrowXML(ParseException,XMLExcepts::Parser_Next1);;
  427. XMLInt32 ch = getCharData();
  428. switch (ch) {
  429. case chLatin_n:
  430. ch = chLF;
  431. break;
  432. case chLatin_r:
  433. ch = chCR;
  434. break;
  435. case chLatin_t:
  436. ch = chHTab;
  437. break;
  438. case chBackSlash:
  439. case chPipe:
  440. case chPeriod:
  441. case chCaret:
  442. case chDash:
  443. case chQuestion:
  444. case chAsterisk:
  445. case chPlus:
  446. case chOpenCurly:
  447. case chCloseCurly:
  448. case chOpenParen:
  449. case chCloseParen:
  450. case chOpenSquare:
  451. case chCloseSquare:
  452. break;
  453. default:
  454. {
  455. XMLCh chString[] = {chBackSlash, ch, chNull};
  456. chString[1] = ch;
  457. ThrowXML1(ParseException,XMLExcepts::Parser_Process2, chString);
  458. }
  459. }
  460. return ch;
  461. }
  462. XERCES_CPP_NAMESPACE_END
  463. /**
  464. * End of file ParserForXMLSchema.cpp
  465. */