PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/pypy/rlib/parsing/regexparse.py

https://bitbucket.org/SeanTater/pypy-bugfix-st
Python | 2004 lines | 1993 code | 4 blank | 7 comment | 20 complexity | f7ca7bdc0e0d30e8f19327a0fd59ed02 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. import py
  2. from pypy.rlib.parsing.parsing import PackratParser, Rule
  3. from pypy.rlib.parsing.tree import Nonterminal
  4. from pypy.rlib.parsing.regex import StringExpression, RangeExpression
  5. from pypy.rlib.parsing.lexer import Lexer, DummyLexer
  6. from pypy.rlib.parsing.deterministic import compress_char_set, DFA
  7. import string
  8. set = py.builtin.set
  9. ESCAPES = {
  10. "a": "\a",
  11. "b": "\b",
  12. "e": "\x1b",
  13. "f": "\f",
  14. "n": "\n",
  15. "r": "\r",
  16. "t": "\t",
  17. "v": "\v",
  18. }
  19. for i in range(256):
  20. # Add the ctrl-x types:
  21. # Rule, according to PCRE:
  22. # if x is a lower case letter, it is converted to upper case.
  23. # Then bit 6 of the character (hex 40) is inverted.
  24. # Thus, \cz => 0x1A, \c{ => 0x3B, \c; => 0x7B.
  25. escaped = "c%s" % chr(i)
  26. ESCAPES[escaped] = chr(ord(chr(i).upper()) ^ 0x40)
  27. def unescape_muncher(string):
  28. """Return a tuple, representing the first character of the string
  29. (appropriately unescaped) and the rest of the string that wasn't
  30. handled."""
  31. if string[0] != '\\':
  32. # Not an escape character
  33. return string[0], string[1:]
  34. if string[1] == 'x':
  35. # Hex char, must have two hex digits
  36. char = chr(int(string[2:4], 16))
  37. return char, string[4:]
  38. if string[1] in '01234567':
  39. # Octal number, up to three digits long
  40. span = 2
  41. span += (span < len(string)) and (string[span] in '01234567')
  42. span += (span < len(string)) and (string[span] in '01234567')
  43. char = chr(int(string[1:span], 8))
  44. return char, string[span:]
  45. if string[1] == 'c':
  46. # Special \cx types
  47. return ESCAPES['c'+string[2]], string[3:]
  48. if string[1] in ESCAPES:
  49. # Special escapes are in ESCAPE
  50. return ESCAPES[string[1]], string[2:]
  51. # Otherwise, it's just the character it's meant to be (e.g., '\.')
  52. return string[1], string[2:]
  53. def unescape(s):
  54. """Unescape a whole string."""
  55. result = []
  56. while s:
  57. char, s = unescape_muncher(s)
  58. result.append(char)
  59. return "".join(result)
  60. syntax = r"""
  61. EOF:
  62. !__any__;
  63. parse:
  64. regex
  65. [EOF];
  66. regex:
  67. r1 = concatenation
  68. '|'
  69. r2 = regex
  70. return {r1 | r2}
  71. | concatenation;
  72. concatenation:
  73. l = repetition*
  74. return {reduce(operator.add, l, regex.StringExpression(""))};
  75. repetition:
  76. r1 = primary
  77. '*'
  78. return {r1.kleene()}
  79. | r1 = primary
  80. '+'
  81. return {r1 + r1.kleene()}
  82. | r1 = primary
  83. '?'
  84. return {regex.StringExpression("") | r1}
  85. | r1 = primary
  86. '{'
  87. n = clippednumrange
  88. '}'
  89. return {r1 * n + r1.kleene()}
  90. | r1 = primary
  91. '{'
  92. n = numrange
  93. '}'
  94. return {r1 * n[0] + reduce(operator.or_, [r1 * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))}
  95. | '{'
  96. return {regex.StringExpression("{")}
  97. | primary;
  98. primary:
  99. ['('] regex [')']
  100. | range
  101. | cc = charclass
  102. return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(cc)])}
  103. | c = char
  104. return {regex.StringExpression(c)}
  105. | '.'
  106. return {regex.RangeExpression(chr(0), chr(255))}
  107. | '-'
  108. return {regex.StringExpression('-')}
  109. | '\'
  110. return {regex.StringExpression('\\')}
  111. | ']'
  112. return {regex.StringExpression(']')};
  113. char:
  114. c = QUOTEDCHAR
  115. return {unescape(c)}
  116. | c = CHAR
  117. return {c};
  118. QUOTEDCHAR:
  119. `(\\x[0-9a-fA-F]{2})|(\\[0-3]?[0-7][0-7])|(\\c.)|(\\[^dswDSW])`;
  120. CHAR:
  121. `[^\*\+\(\)\[\]\{\|\.\-\?\^\\]`;
  122. range:
  123. '['
  124. s = rangeinner
  125. ']'
  126. return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])};
  127. rangeinner:
  128. '^'
  129. s = subrange
  130. return {set([chr(c) for c in range(256)]) - s}
  131. | subrange;
  132. subrange:
  133. ']'
  134. l = rangeelement*
  135. return {reduce(operator.or_, [set(["]"])] + l)}
  136. | l = rangeelement+
  137. return {reduce(operator.or_, l)};
  138. rangeelement:
  139. charclass
  140. | c1 = char
  141. '-'
  142. c2 = char
  143. return {set([chr(i) for i in range(ord(c1), ord(c2) + 1)])}
  144. | '.'
  145. return { set(['.']) }
  146. | '*'
  147. return { set(['*']) }
  148. | '+'
  149. return { set(['+']) }
  150. | '?'
  151. return { set(['?']) }
  152. | '-'
  153. return { set(['-']) }
  154. | '['
  155. return { set(['[']) }
  156. | c = char
  157. return { set([c]) };
  158. numrange:
  159. n1 = NUM
  160. ','
  161. n2 = NUM
  162. return {n1, n2}
  163. | n1 = NUM
  164. return {n1, n1};
  165. clippednumrange:
  166. n1 = NUM
  167. ','
  168. return {n1};
  169. charclass:
  170. '\' 'd'
  171. return { set([chr(c) for c in range(ord('0'), ord('9')+1)]) }
  172. | '\' 's'
  173. return { set(['\t', '\n', '\f', '\r', ' ']) }
  174. | '\' 'w'
  175. return { set([chr(c) for c in range(ord('a'), ord('z')+1)] + [chr(c) for c in range(ord('A'), ord('Z')+1)] + [chr(c) for c in range(ord('0'), ord('9')+1)] + ['_']) }
  176. | '\' 'D'
  177. return { set([chr(c) for c in range(256)]) - set([chr(c) for c in range(ord('0'), ord('9')+1)]) }
  178. | '\' 'S'
  179. return { set([chr(c) for c in range(256)]) - set(['\t', '\n', '\f', '\r', ' ']) }
  180. | '\' 'W'
  181. return { set([chr(c) for c in range(256)]) - set([chr(c) for c in range(ord('a'), ord('z')+1)] + [chr(c) for c in range(ord('A'), ord('Z')+1)] + [chr(c) for c in range(ord('0'), ord('9')+1)] + ['_'])};
  182. NUM:
  183. c = `0|([1-9][0-9]*)`
  184. return {int(c)};
  185. """
  186. def parse_regex(s):
  187. p = RegexParser(s)
  188. r = p.parse()
  189. return r
  190. def make_runner(regex, view=False):
  191. r = parse_regex(regex)
  192. nfa = r.make_automaton()
  193. dfa = nfa.make_deterministic()
  194. if view:
  195. dfa.view()
  196. dfa.optimize()
  197. if view:
  198. dfa.view()
  199. r = dfa.get_runner()
  200. return r
  201. # generated code between this line and its other occurence
  202. from pypy.rlib.parsing.pypackrat import PackratParser, Status
  203. from pypy.rlib.parsing.pypackrat import BacktrackException
  204. from pypy.rlib.parsing import regex
  205. import operator
  206. class Parser(object):
  207. def EOF(self):
  208. return self._EOF().result
  209. def _EOF(self):
  210. _key = self._pos
  211. _status = self._dict_EOF.get(_key, None)
  212. if _status is None:
  213. _status = self._dict_EOF[_key] = Status()
  214. else:
  215. _statusstatus = _status.status
  216. if _statusstatus == _status.NORMAL:
  217. self._pos = _status.pos
  218. return _status
  219. elif _statusstatus == _status.ERROR:
  220. raise BacktrackException(_status.error)
  221. elif (_statusstatus == _status.INPROGRESS or
  222. _statusstatus == _status.LEFTRECURSION):
  223. _status.status = _status.LEFTRECURSION
  224. if _status.result is not None:
  225. self._pos = _status.pos
  226. return _status
  227. else:
  228. raise BacktrackException(None)
  229. elif _statusstatus == _status.SOMESOLUTIONS:
  230. _status.status = _status.INPROGRESS
  231. _startingpos = self._pos
  232. try:
  233. _result = None
  234. _error = None
  235. _choice0 = self._pos
  236. _stored_result1 = _result
  237. try:
  238. _result = self.__any__()
  239. except BacktrackException:
  240. self._pos = _choice0
  241. _result = _stored_result1
  242. else:
  243. raise BacktrackException(None)
  244. if _status.status == _status.LEFTRECURSION:
  245. if _status.result is not None:
  246. if _status.pos >= self._pos:
  247. _status.status = _status.NORMAL
  248. self._pos = _status.pos
  249. return _status
  250. _status.pos = self._pos
  251. _status.status = _status.SOMESOLUTIONS
  252. _status.result = _result
  253. _status.error = _error
  254. self._pos = _startingpos
  255. return self._EOF()
  256. _status.status = _status.NORMAL
  257. _status.pos = self._pos
  258. _status.result = _result
  259. _status.error = _error
  260. return _status
  261. except BacktrackException, _exc:
  262. _status.pos = -1
  263. _status.result = None
  264. _error = _exc.error
  265. _status.error = _error
  266. _status.status = _status.ERROR
  267. raise BacktrackException(_error)
  268. def parse(self):
  269. return self._parse().result
  270. def _parse(self):
  271. _key = self._pos
  272. _status = self._dict_parse.get(_key, None)
  273. if _status is None:
  274. _status = self._dict_parse[_key] = Status()
  275. else:
  276. _statusstatus = _status.status
  277. if _statusstatus == _status.NORMAL:
  278. self._pos = _status.pos
  279. return _status
  280. elif _statusstatus == _status.ERROR:
  281. raise BacktrackException(_status.error)
  282. elif (_statusstatus == _status.INPROGRESS or
  283. _statusstatus == _status.LEFTRECURSION):
  284. _status.status = _status.LEFTRECURSION
  285. if _status.result is not None:
  286. self._pos = _status.pos
  287. return _status
  288. else:
  289. raise BacktrackException(None)
  290. elif _statusstatus == _status.SOMESOLUTIONS:
  291. _status.status = _status.INPROGRESS
  292. _startingpos = self._pos
  293. try:
  294. _result = None
  295. _error = None
  296. _call_status = self._regex()
  297. _result = _call_status.result
  298. _error = _call_status.error
  299. _before_discard0 = _result
  300. _call_status = self._EOF()
  301. _result = _call_status.result
  302. _error = self._combine_errors(_error, _call_status.error)
  303. _result = _before_discard0
  304. if _status.status == _status.LEFTRECURSION:
  305. if _status.result is not None:
  306. if _status.pos >= self._pos:
  307. _status.status = _status.NORMAL
  308. self._pos = _status.pos
  309. return _status
  310. _status.pos = self._pos
  311. _status.status = _status.SOMESOLUTIONS
  312. _status.result = _result
  313. _status.error = _error
  314. self._pos = _startingpos
  315. return self._parse()
  316. _status.status = _status.NORMAL
  317. _status.pos = self._pos
  318. _status.result = _result
  319. _status.error = _error
  320. return _status
  321. except BacktrackException, _exc:
  322. _status.pos = -1
  323. _status.result = None
  324. _error = self._combine_errors(_error, _exc.error)
  325. _status.error = _error
  326. _status.status = _status.ERROR
  327. raise BacktrackException(_error)
  328. def regex(self):
  329. return self._regex().result
  330. def _regex(self):
  331. _key = self._pos
  332. _status = self._dict_regex.get(_key, None)
  333. if _status is None:
  334. _status = self._dict_regex[_key] = Status()
  335. else:
  336. _statusstatus = _status.status
  337. if _statusstatus == _status.NORMAL:
  338. self._pos = _status.pos
  339. return _status
  340. elif _statusstatus == _status.ERROR:
  341. raise BacktrackException(_status.error)
  342. elif (_statusstatus == _status.INPROGRESS or
  343. _statusstatus == _status.LEFTRECURSION):
  344. _status.status = _status.LEFTRECURSION
  345. if _status.result is not None:
  346. self._pos = _status.pos
  347. return _status
  348. else:
  349. raise BacktrackException(None)
  350. elif _statusstatus == _status.SOMESOLUTIONS:
  351. _status.status = _status.INPROGRESS
  352. _startingpos = self._pos
  353. try:
  354. _result = None
  355. _error = None
  356. while 1:
  357. _choice0 = self._pos
  358. try:
  359. _call_status = self._concatenation()
  360. _result = _call_status.result
  361. _error = _call_status.error
  362. r1 = _result
  363. _result = self.__chars__('|')
  364. _call_status = self._regex()
  365. _result = _call_status.result
  366. _error = self._combine_errors(_error, _call_status.error)
  367. r2 = _result
  368. _result = (r1 | r2)
  369. break
  370. except BacktrackException, _exc:
  371. _error = self._combine_errors(_error, _exc.error)
  372. self._pos = _choice0
  373. _choice1 = self._pos
  374. try:
  375. _call_status = self._concatenation()
  376. _result = _call_status.result
  377. _error = self._combine_errors(_error, _call_status.error)
  378. break
  379. except BacktrackException, _exc:
  380. _error = self._combine_errors(_error, _exc.error)
  381. self._pos = _choice1
  382. raise BacktrackException(_error)
  383. _call_status = self._concatenation()
  384. _result = _call_status.result
  385. _error = self._combine_errors(_error, _call_status.error)
  386. break
  387. if _status.status == _status.LEFTRECURSION:
  388. if _status.result is not None:
  389. if _status.pos >= self._pos:
  390. _status.status = _status.NORMAL
  391. self._pos = _status.pos
  392. return _status
  393. _status.pos = self._pos
  394. _status.status = _status.SOMESOLUTIONS
  395. _status.result = _result
  396. _status.error = _error
  397. self._pos = _startingpos
  398. return self._regex()
  399. _status.status = _status.NORMAL
  400. _status.pos = self._pos
  401. _status.result = _result
  402. _status.error = _error
  403. return _status
  404. except BacktrackException, _exc:
  405. _status.pos = -1
  406. _status.result = None
  407. _error = self._combine_errors(_error, _exc.error)
  408. _status.error = _error
  409. _status.status = _status.ERROR
  410. raise BacktrackException(_error)
  411. def concatenation(self):
  412. return self._concatenation().result
  413. def _concatenation(self):
  414. _key = self._pos
  415. _status = self._dict_concatenation.get(_key, None)
  416. if _status is None:
  417. _status = self._dict_concatenation[_key] = Status()
  418. else:
  419. _statusstatus = _status.status
  420. if _statusstatus == _status.NORMAL:
  421. self._pos = _status.pos
  422. return _status
  423. elif _statusstatus == _status.ERROR:
  424. raise BacktrackException(_status.error)
  425. elif (_statusstatus == _status.INPROGRESS or
  426. _statusstatus == _status.LEFTRECURSION):
  427. _status.status = _status.LEFTRECURSION
  428. if _status.result is not None:
  429. self._pos = _status.pos
  430. return _status
  431. else:
  432. raise BacktrackException(None)
  433. elif _statusstatus == _status.SOMESOLUTIONS:
  434. _status.status = _status.INPROGRESS
  435. _startingpos = self._pos
  436. try:
  437. _result = None
  438. _error = None
  439. _all0 = []
  440. while 1:
  441. _choice1 = self._pos
  442. try:
  443. _call_status = self._repetition()
  444. _result = _call_status.result
  445. _error = _call_status.error
  446. _all0.append(_result)
  447. except BacktrackException, _exc:
  448. _error = self._combine_errors(_error, _exc.error)
  449. self._pos = _choice1
  450. break
  451. _result = _all0
  452. l = _result
  453. _result = (reduce(operator.add, l, regex.StringExpression("")))
  454. if _status.status == _status.LEFTRECURSION:
  455. if _status.result is not None:
  456. if _status.pos >= self._pos:
  457. _status.status = _status.NORMAL
  458. self._pos = _status.pos
  459. return _status
  460. _status.pos = self._pos
  461. _status.status = _status.SOMESOLUTIONS
  462. _status.result = _result
  463. _status.error = _error
  464. self._pos = _startingpos
  465. return self._concatenation()
  466. _status.status = _status.NORMAL
  467. _status.pos = self._pos
  468. _status.result = _result
  469. _status.error = _error
  470. return _status
  471. except BacktrackException, _exc:
  472. _status.pos = -1
  473. _status.result = None
  474. _error = self._combine_errors(_error, _exc.error)
  475. _status.error = _error
  476. _status.status = _status.ERROR
  477. raise BacktrackException(_error)
  478. def repetition(self):
  479. return self._repetition().result
  480. def _repetition(self):
  481. _key = self._pos
  482. _status = self._dict_repetition.get(_key, None)
  483. if _status is None:
  484. _status = self._dict_repetition[_key] = Status()
  485. else:
  486. _statusstatus = _status.status
  487. if _statusstatus == _status.NORMAL:
  488. self._pos = _status.pos
  489. return _status
  490. elif _statusstatus == _status.ERROR:
  491. raise BacktrackException(_status.error)
  492. elif (_statusstatus == _status.INPROGRESS or
  493. _statusstatus == _status.LEFTRECURSION):
  494. _status.status = _status.LEFTRECURSION
  495. if _status.result is not None:
  496. self._pos = _status.pos
  497. return _status
  498. else:
  499. raise BacktrackException(None)
  500. elif _statusstatus == _status.SOMESOLUTIONS:
  501. _status.status = _status.INPROGRESS
  502. _startingpos = self._pos
  503. try:
  504. _result = None
  505. _error = None
  506. while 1:
  507. _choice0 = self._pos
  508. try:
  509. _call_status = self._primary()
  510. _result = _call_status.result
  511. _error = _call_status.error
  512. r1 = _result
  513. _result = self.__chars__('*')
  514. _result = (r1.kleene())
  515. break
  516. except BacktrackException, _exc:
  517. _error = self._combine_errors(_error, _exc.error)
  518. self._pos = _choice0
  519. _choice1 = self._pos
  520. try:
  521. _call_status = self._primary()
  522. _result = _call_status.result
  523. _error = self._combine_errors(_error, _call_status.error)
  524. r1 = _result
  525. _result = self.__chars__('+')
  526. _result = (r1 + r1.kleene())
  527. break
  528. except BacktrackException, _exc:
  529. _error = self._combine_errors(_error, _exc.error)
  530. self._pos = _choice1
  531. _choice2 = self._pos
  532. try:
  533. _call_status = self._primary()
  534. _result = _call_status.result
  535. _error = self._combine_errors(_error, _call_status.error)
  536. r1 = _result
  537. _result = self.__chars__('?')
  538. _result = (regex.StringExpression("") | r1)
  539. break
  540. except BacktrackException, _exc:
  541. _error = self._combine_errors(_error, _exc.error)
  542. self._pos = _choice2
  543. _choice3 = self._pos
  544. try:
  545. _call_status = self._primary()
  546. _result = _call_status.result
  547. _error = self._combine_errors(_error, _call_status.error)
  548. r1 = _result
  549. _result = self.__chars__('{')
  550. _call_status = self._clippednumrange()
  551. _result = _call_status.result
  552. _error = self._combine_errors(_error, _call_status.error)
  553. n = _result
  554. _result = self.__chars__('}')
  555. _result = (r1 * n + r1.kleene())
  556. break
  557. except BacktrackException, _exc:
  558. _error = self._combine_errors(_error, _exc.error)
  559. self._pos = _choice3
  560. _choice4 = self._pos
  561. try:
  562. _call_status = self._primary()
  563. _result = _call_status.result
  564. _error = self._combine_errors(_error, _call_status.error)
  565. r1 = _result
  566. _result = self.__chars__('{')
  567. _call_status = self._numrange()
  568. _result = _call_status.result
  569. _error = self._combine_errors(_error, _call_status.error)
  570. n = _result
  571. _result = self.__chars__('}')
  572. _result = (r1 * n[0] + reduce(operator.or_, [r1 * i for i in range(n[1] - n[0] + 1)], regex.StringExpression("")))
  573. break
  574. except BacktrackException, _exc:
  575. _error = self._combine_errors(_error, _exc.error)
  576. self._pos = _choice4
  577. _choice5 = self._pos
  578. try:
  579. _result = self.__chars__('{')
  580. _result = (regex.StringExpression("{"))
  581. break
  582. except BacktrackException, _exc:
  583. _error = self._combine_errors(_error, _exc.error)
  584. self._pos = _choice5
  585. _choice6 = self._pos
  586. try:
  587. _call_status = self._primary()
  588. _result = _call_status.result
  589. _error = self._combine_errors(_error, _call_status.error)
  590. break
  591. except BacktrackException, _exc:
  592. _error = self._combine_errors(_error, _exc.error)
  593. self._pos = _choice6
  594. raise BacktrackException(_error)
  595. _call_status = self._primary()
  596. _result = _call_status.result
  597. _error = self._combine_errors(_error, _call_status.error)
  598. break
  599. if _status.status == _status.LEFTRECURSION:
  600. if _status.result is not None:
  601. if _status.pos >= self._pos:
  602. _status.status = _status.NORMAL
  603. self._pos = _status.pos
  604. return _status
  605. _status.pos = self._pos
  606. _status.status = _status.SOMESOLUTIONS
  607. _status.result = _result
  608. _status.error = _error
  609. self._pos = _startingpos
  610. return self._repetition()
  611. _status.status = _status.NORMAL
  612. _status.pos = self._pos
  613. _status.result = _result
  614. _status.error = _error
  615. return _status
  616. except BacktrackException, _exc:
  617. _status.pos = -1
  618. _status.result = None
  619. _error = self._combine_errors(_error, _exc.error)
  620. _status.error = _error
  621. _status.status = _status.ERROR
  622. raise BacktrackException(_error)
  623. def primary(self):
  624. return self._primary().result
  625. def _primary(self):
  626. _key = self._pos
  627. _status = self._dict_primary.get(_key, None)
  628. if _status is None:
  629. _status = self._dict_primary[_key] = Status()
  630. else:
  631. _statusstatus = _status.status
  632. if _statusstatus == _status.NORMAL:
  633. self._pos = _status.pos
  634. return _status
  635. elif _statusstatus == _status.ERROR:
  636. raise BacktrackException(_status.error)
  637. elif (_statusstatus == _status.INPROGRESS or
  638. _statusstatus == _status.LEFTRECURSION):
  639. _status.status = _status.LEFTRECURSION
  640. if _status.result is not None:
  641. self._pos = _status.pos
  642. return _status
  643. else:
  644. raise BacktrackException(None)
  645. elif _statusstatus == _status.SOMESOLUTIONS:
  646. _status.status = _status.INPROGRESS
  647. _startingpos = self._pos
  648. try:
  649. _result = None
  650. _error = None
  651. while 1:
  652. _choice0 = self._pos
  653. try:
  654. _before_discard1 = _result
  655. _result = self.__chars__('(')
  656. _result = _before_discard1
  657. _call_status = self._regex()
  658. _result = _call_status.result
  659. _error = _call_status.error
  660. _before_discard2 = _result
  661. _result = self.__chars__(')')
  662. _result = _before_discard2
  663. break
  664. except BacktrackException, _exc:
  665. _error = self._combine_errors(_error, _exc.error)
  666. self._pos = _choice0
  667. _choice3 = self._pos
  668. try:
  669. _call_status = self._range()
  670. _result = _call_status.result
  671. _error = self._combine_errors(_error, _call_status.error)
  672. break
  673. except BacktrackException, _exc:
  674. _error = self._combine_errors(_error, _exc.error)
  675. self._pos = _choice3
  676. _choice4 = self._pos
  677. try:
  678. _call_status = self._charclass()
  679. _result = _call_status.result
  680. _error = self._combine_errors(_error, _call_status.error)
  681. cc = _result
  682. _result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(cc)]))
  683. break
  684. except BacktrackException, _exc:
  685. _error = self._combine_errors(_error, _exc.error)
  686. self._pos = _choice4
  687. _choice5 = self._pos
  688. try:
  689. _call_status = self._char()
  690. _result = _call_status.result
  691. _error = self._combine_errors(_error, _call_status.error)
  692. c = _result
  693. _result = (regex.StringExpression(c))
  694. break
  695. except BacktrackException, _exc:
  696. _error = self._combine_errors(_error, _exc.error)
  697. self._pos = _choice5
  698. _choice6 = self._pos
  699. try:
  700. _result = self.__chars__('.')
  701. _result = (regex.RangeExpression(chr(0), chr(255)))
  702. break
  703. except BacktrackException, _exc:
  704. _error = self._combine_errors(_error, _exc.error)
  705. self._pos = _choice6
  706. _choice7 = self._pos
  707. try:
  708. _result = self.__chars__('-')
  709. _result = (regex.StringExpression('-'))
  710. break
  711. except BacktrackException, _exc:
  712. _error = self._combine_errors(_error, _exc.error)
  713. self._pos = _choice7
  714. _choice8 = self._pos
  715. try:
  716. _result = self.__chars__('\\')
  717. _result = (regex.StringExpression('\\'))
  718. break
  719. except BacktrackException, _exc:
  720. _error = self._combine_errors(_error, _exc.error)
  721. self._pos = _choice8
  722. _choice9 = self._pos
  723. try:
  724. _result = self.__chars__(']')
  725. _result = (regex.StringExpression(']'))
  726. break
  727. except BacktrackException, _exc:
  728. _error = self._combine_errors(_error, _exc.error)
  729. self._pos = _choice9
  730. raise BacktrackException(_error)
  731. _result = self.__chars__(']')
  732. _result = (regex.StringExpression(']'))
  733. break
  734. if _status.status == _status.LEFTRECURSION:
  735. if _status.result is not None:
  736. if _status.pos >= self._pos:
  737. _status.status = _status.NORMAL
  738. self._pos = _status.pos
  739. return _status
  740. _status.pos = self._pos
  741. _status.status = _status.SOMESOLUTIONS
  742. _status.result = _result
  743. _status.error = _error
  744. self._pos = _startingpos
  745. return self._primary()
  746. _status.status = _status.NORMAL
  747. _status.pos = self._pos
  748. _status.result = _result
  749. _status.error = _error
  750. return _status
  751. except BacktrackException, _exc:
  752. _status.pos = -1
  753. _status.result = None
  754. _error = self._combine_errors(_error, _exc.error)
  755. _status.error = _error
  756. _status.status = _status.ERROR
  757. raise BacktrackException(_error)
  758. def char(self):
  759. return self._char().result
  760. def _char(self):
  761. _key = self._pos
  762. _status = self._dict_char.get(_key, None)
  763. if _status is None:
  764. _status = self._dict_char[_key] = Status()
  765. else:
  766. _statusstatus = _status.status
  767. if _statusstatus == _status.NORMAL:
  768. self._pos = _status.pos
  769. return _status
  770. elif _statusstatus == _status.ERROR:
  771. raise BacktrackException(_status.error)
  772. elif (_statusstatus == _status.INPROGRESS or
  773. _statusstatus == _status.LEFTRECURSION):
  774. _status.status = _status.LEFTRECURSION
  775. if _status.result is not None:
  776. self._pos = _status.pos
  777. return _status
  778. else:
  779. raise BacktrackException(None)
  780. elif _statusstatus == _status.SOMESOLUTIONS:
  781. _status.status = _status.INPROGRESS
  782. _startingpos = self._pos
  783. try:
  784. _result = None
  785. _error = None
  786. while 1:
  787. _choice0 = self._pos
  788. try:
  789. _call_status = self._QUOTEDCHAR()
  790. _result = _call_status.result
  791. _error = _call_status.error
  792. c = _result
  793. _result = (unescape(c))
  794. break
  795. except BacktrackException, _exc:
  796. _error = self._combine_errors(_error, _exc.error)
  797. self._pos = _choice0
  798. _choice1 = self._pos
  799. try:
  800. _call_status = self._CHAR()
  801. _result = _call_status.result
  802. _error = self._combine_errors(_error, _call_status.error)
  803. c = _result
  804. _result = (c)
  805. break
  806. except BacktrackException, _exc:
  807. _error = self._combine_errors(_error, _exc.error)
  808. self._pos = _choice1
  809. raise BacktrackException(_error)
  810. _call_status = self._CHAR()
  811. _result = _call_status.result
  812. _error = self._combine_errors(_error, _call_status.error)
  813. c = _result
  814. _result = (c)
  815. break
  816. if _status.status == _status.LEFTRECURSION:
  817. if _status.result is not None:
  818. if _status.pos >= self._pos:
  819. _status.status = _status.NORMAL
  820. self._pos = _status.pos
  821. return _status
  822. _status.pos = self._pos
  823. _status.status = _status.SOMESOLUTIONS
  824. _status.result = _result
  825. _status.error = _error
  826. self._pos = _startingpos
  827. return self._char()
  828. _status.status = _status.NORMAL
  829. _status.pos = self._pos
  830. _status.result = _result
  831. _status.error = _error
  832. return _status
  833. except BacktrackException, _exc:
  834. _status.pos = -1
  835. _status.result = None
  836. _error = self._combine_errors(_error, _exc.error)
  837. _status.error = _error
  838. _status.status = _status.ERROR
  839. raise BacktrackException(_error)
  840. def QUOTEDCHAR(self):
  841. return self._QUOTEDCHAR().result
  842. def _QUOTEDCHAR(self):
  843. _key = self._pos
  844. _status = self._dict_QUOTEDCHAR.get(_key, None)
  845. if _status is None:
  846. _status = self._dict_QUOTEDCHAR[_key] = Status()
  847. else:
  848. _statusstatus = _status.status
  849. if _statusstatus == _status.NORMAL:
  850. self._pos = _status.pos
  851. return _status
  852. elif _statusstatus == _status.ERROR:
  853. raise BacktrackException(_status.error)
  854. _startingpos = self._pos
  855. try:
  856. _result = None
  857. _error = None
  858. _result = self._regex1423754537()
  859. assert _status.status != _status.LEFTRECURSION
  860. _status.status = _status.NORMAL
  861. _status.pos = self._pos
  862. _status.result = _result
  863. _status.error = _error
  864. return _status
  865. except BacktrackException, _exc:
  866. _status.pos = -1
  867. _status.result = None
  868. _error = _exc.error
  869. _status.error = _error
  870. _status.status = _status.ERROR
  871. raise BacktrackException(_error)
  872. def CHAR(self):
  873. return self._CHAR().result
  874. def _CHAR(self):
  875. _key = self._pos
  876. _status = self._dict_CHAR.get(_key, None)
  877. if _status is None:
  878. _status = self._dict_CHAR[_key] = Status()
  879. else:
  880. _statusstatus = _status.status
  881. if _statusstatus == _status.NORMAL:
  882. self._pos = _status.pos
  883. return _status
  884. elif _statusstatus == _status.ERROR:
  885. raise BacktrackException(_status.error)
  886. _startingpos = self._pos
  887. try:
  888. _result = None
  889. _error = None
  890. _result = self._regex2132196932()
  891. assert _status.status != _status.LEFTRECURSION
  892. _status.status = _status.NORMAL
  893. _status.pos = self._pos
  894. _status.result = _result
  895. _status.error = _error
  896. return _status
  897. except BacktrackException, _exc:
  898. _status.pos = -1
  899. _status.result = None
  900. _error = _exc.error
  901. _status.error = _error
  902. _status.status = _status.ERROR
  903. raise BacktrackException(_error)
  904. def range(self):
  905. return self._range().result
  906. def _range(self):
  907. _key = self._pos
  908. _status = self._dict_range.get(_key, None)
  909. if _status is None:
  910. _status = self._dict_range[_key] = Status()
  911. else:
  912. _statusstatus = _status.status
  913. if _statusstatus == _status.NORMAL:
  914. self._pos = _status.pos
  915. return _status
  916. elif _statusstatus == _status.ERROR:
  917. raise BacktrackException(_status.error)
  918. elif (_statusstatus == _status.INPROGRESS or
  919. _statusstatus == _status.LEFTRECURSION):
  920. _status.status = _status.LEFTRECURSION
  921. if _status.result is not None:
  922. self._pos = _status.pos
  923. return _status
  924. else:
  925. raise BacktrackException(None)
  926. elif _statusstatus == _status.SOMESOLUTIONS:
  927. _status.status = _status.INPROGRESS
  928. _startingpos = self._pos
  929. try:
  930. _result = None
  931. _error = None
  932. _result = self.__chars__('[')
  933. _call_status = self._rangeinner()
  934. _result = _call_status.result
  935. _error = _call_status.error
  936. s = _result
  937. _result = self.__chars__(']')
  938. _result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)]))
  939. if _status.status == _status.LEFTRECURSION:
  940. if _status.result is not None:
  941. if _status.pos >= self._pos:
  942. _status.status = _status.NORMAL
  943. self._pos = _status.pos
  944. return _status
  945. _status.pos = self._pos
  946. _status.status = _status.SOMESOLUTIONS
  947. _status.result = _result
  948. _status.error = _error
  949. self._pos = _startingpos
  950. return self._range()
  951. _status.status = _status.NORMAL
  952. _status.pos = self._pos
  953. _status.result = _result
  954. _status.error = _error
  955. return _status
  956. except BacktrackException, _exc:
  957. _status.pos = -1
  958. _status.result = None
  959. _error = self._combine_errors(_error, _exc.error)
  960. _status.error = _error
  961. _status.status = _status.ERROR
  962. raise BacktrackException(_error)
  963. def rangeinner(self):
  964. return self._rangeinner().result
  965. def _rangeinner(self):
  966. _key = self._pos
  967. _status = self._dict_rangeinner.get(_key, None)
  968. if _status is None:
  969. _status = self._dict_rangeinner[_key] = Status()
  970. else:
  971. _statusstatus = _status.status
  972. if _statusstatus == _status.NORMAL:
  973. self._pos = _status.pos
  974. return _status
  975. elif _statusstatus == _status.ERROR:
  976. raise BacktrackException(_status.error)
  977. elif (_statusstatus == _status.INPROGRESS or
  978. _statusstatus == _status.LEFTRECURSION):
  979. _status.status = _status.LEFTRECURSION
  980. if _status.result is not None:
  981. self._pos = _status.pos
  982. return _status
  983. else:
  984. raise BacktrackException(None)
  985. elif _statusstatus == _status.SOMESOLUTIONS:
  986. _status.status = _status.INPROGRESS
  987. _startingpos = self._pos
  988. try:
  989. _result = None
  990. _error = None
  991. while 1:
  992. _choice0 = self._pos
  993. try:
  994. _result = self.__chars__('^')
  995. _call_status = self._subrange()
  996. _result = _call_status.result
  997. _error = _call_status.error
  998. s = _result
  999. _result = (set([chr(c) for c in range(256)]) - s)
  1000. break
  1001. except BacktrackException, _exc:
  1002. _error = self._combine_errors(_error, _exc.error)
  1003. self._pos = _choice0
  1004. _choice1 = self._pos
  1005. try:
  1006. _call_status = self._subrange()
  1007. _result = _call_status.result
  1008. _error = self._combine_errors(_error, _call_status.error)
  1009. break
  1010. except BacktrackException, _exc:
  1011. _error = self._combine_errors(_error, _exc.error)
  1012. self._pos = _choice1
  1013. raise BacktrackException(_error)
  1014. _call_status = self._subrange()
  1015. _result = _call_status.result
  1016. _error = self._combine_errors(_error, _call_status.error)
  1017. break
  1018. if _status.status == _status.LEFTRECURSION:
  1019. if _status.result is not None:
  1020. if _status.pos >= self._pos:
  1021. _status.status = _status.NORMAL
  1022. self._pos = _status.pos
  1023. return _status
  1024. _status.pos = self._pos
  1025. _status.status = _status.SOMESOLUTIONS
  1026. _status.result = _result
  1027. _status.error = _error
  1028. self._pos = _startingpos
  1029. return self._rangeinner()
  1030. _status.status = _status.NORMAL
  1031. _status.pos = self._pos
  1032. _status.result = _result
  1033. _status.error = _error
  1034. return _status
  1035. except BacktrackException, _exc:
  1036. _status.pos = -1
  1037. _status.result = None
  1038. _error = self._combine_errors(_error, _exc.error)
  1039. _status.error = _error
  1040. _status.status = _status.ERROR
  1041. raise BacktrackException(_error)
  1042. def subrange(self):
  1043. return self._subrange().result
  1044. def _subrange(self):
  1045. _key = self._pos
  1046. _status = self._dict_subrange.get(_key, None)
  1047. if _status is None:
  1048. _status = self._dict_subrange[_key] = Status()
  1049. else:
  1050. _statusstatus = _status.status
  1051. if _statusstatus == _status.NORMAL:
  1052. self._pos = _status.pos
  1053. return _status
  1054. elif _statusstatus == _status.ERROR:
  1055. raise BacktrackException(_status.error)
  1056. elif (_statusstatus == _status.INPROGRESS or
  1057. _statusstatus == _status.LEFTRECURSION):
  1058. _status.status = _status.LEFTRECURSION
  1059. if _status.result is not None:
  1060. self._pos = _status.pos
  1061. return _status
  1062. else:
  1063. raise BacktrackException(None)
  1064. elif _statusstatus == _status.SOMESOLUTIONS:
  1065. _status.status = _status.INPROGRESS
  1066. _startingpos = self._pos
  1067. try:
  1068. _result = None
  1069. _error = None
  1070. while 1:
  1071. _choice0 = self._pos
  1072. try:
  1073. _result = self.__chars__(']')
  1074. _all1 = []
  1075. while 1:
  1076. _choice2 = self._pos
  1077. try:
  1078. _call_status = self._rangeelement()
  1079. _result = _call_status.result
  1080. _error = _call_status.error
  1081. _all1.append(_result)
  1082. except BacktrackException, _exc:
  1083. _error = self._combine_errors(_error, _exc.error)
  1084. self._pos = _choice2
  1085. break
  1086. _result = _all1
  1087. l = _result
  1088. _result = (reduce(operator.or_, [set(["]"])] + l))
  1089. break
  1090. except BacktrackException, _exc:
  1091. _error = self._combine_errors(_error, _exc.error)
  1092. self._pos = _choice0
  1093. _choice3 = self._pos
  1094. try:
  1095. _all4 = []
  1096. _call_status = self._rangeelement()
  1097. _result = _call_status.result
  1098. _error = self._combine_errors(_error, _call_status.error)
  1099. _all4.append(_result)
  1100. while 1:
  1101. _choice5 = self._pos
  1102. try:
  1103. _call_status = self._rangeelement()
  1104. _result = _call_status.result
  1105. _error = self._combine_errors(_error, _call_status.error)
  1106. _all4.append(_result)
  1107. except BacktrackException, _exc:
  1108. _error = self._combine_errors(_error, _exc.error)
  1109. self._pos = _choice5
  1110. break
  1111. _result = _all4
  1112. l = _result
  1113. _result = (reduce(operator.or_, l))
  1114. break
  1115. except BacktrackException, _exc:
  1116. _error = self._combine_errors(_error, _exc.error)
  1117. self._pos = _choice3
  1118. raise BacktrackException(_error)
  1119. _all6 = []
  1120. _call_status = self._rangeelement()
  1121. _result = _call_status.result
  1122. _error = self._combine_errors(_error, _call_status.error)
  1123. _all6.append(_result)
  1124. while 1:
  1125. _choice7 = self._pos
  1126. try:
  1127. _call_status = self._rangeelement()
  1128. _result = _call_status.result
  1129. _error = self._combine_errors(_error, _call_status.error)
  1130. _all6.append(_result)
  1131. except BacktrackException, _exc:
  1132. _error = self._combine_errors(_error, _exc.error)
  1133. self._pos = _choice7
  1134. break
  1135. _result = _all6
  1136. l = _result
  1137. _result = (reduce(operator.or_, l))
  1138. break
  1139. if _status.status == _status.LEFTRECURSION:
  1140. if _status.result is not None:
  1141. if _status.pos >= self._pos:
  1142. _status.status = _status.NORMAL
  1143. self._pos = _status.pos
  1144. return _status
  1145. _status.pos = self._pos
  1146. _status.status = _status.SOMESOLUTIONS
  1147. _status.result = _result
  1148. _status.error = _error
  1149. self._pos = _startingpos
  1150. return self._subrange()
  1151. _status.status = _status.NORMAL
  1152. _status.pos = self._pos
  1153. _status.result = _result
  1154. _status.error = _error
  1155. return _status
  1156. except BacktrackException, _exc:
  1157. _status.pos = -1
  1158. _status.result = None
  1159. _error = self._combine_errors(_error, _exc.error)
  1160. _status.error = _error
  1161. _status.status = _status.ERROR
  1162. raise BacktrackException(_error)
  1163. def rangeelement(self):
  1164. return self._rangeelement().result
  1165. def _rangeelement(self):
  1166. _key = self._pos
  1167. _status = self._dict_rangeelement.get(_key, None)
  1168. if _status is None:
  1169. _status = self._dict_rangeelement[_key] = Status()
  1170. else:
  1171. _statusstatus = _status.status
  1172. if _statusstatus == _status.NORMAL:
  1173. self._pos = _status.pos
  1174. return _status
  1175. elif _statusstatus == _status.ERROR:
  1176. raise BacktrackException(_status.error)
  1177. elif (_statusstatus == _status.INPROGRESS or
  1178. _statusstatus == _status.LEFTRECURSION):
  1179. _status.status = _status.LEFTRECURSION
  1180. if _status.result is not None:
  1181. self._pos = _status.pos
  1182. return _status
  1183. else:
  1184. raise BacktrackException(None)
  1185. elif _statusstatus == _status.SOMESOLUTIONS:
  1186. _status.status = _status.INPROGRESS
  1187. _startingpos = self._pos
  1188. try:
  1189. _result = None
  1190. _error = None
  1191. while 1:
  1192. _choice0 = self._pos
  1193. try:
  1194. _call_status = self._charclass()
  1195. _result = _call_status.result
  1196. _error = _call_status.error
  1197. break
  1198. except BacktrackException, _exc:
  1199. _error = self._combine_errors(_error, _exc.error)
  1200. self._pos = _choice0
  1201. _choice1 = self._pos
  1202. try:
  1203. _call_status = self._char()
  1204. _result = _call_status.result
  1205. _error = self._combine_errors(_error, _call_status.error)
  1206. c1 = _result
  1207. _result = self.__chars__('-')
  1208. _call_status = self._char()
  1209. _result = _call_status.result
  1210. _error = self._combine_errors(_error, _call_status.error)
  1211. c2 = _result
  1212. _result = (set([chr(i) for i in range(ord(c1), ord(c2) + 1)]))
  1213. break
  1214. except BacktrackException, _exc:
  1215. _error = self._combine_errors(_error, _exc.error)
  1216. self._pos = _choice1
  1217. _choice2 = self._pos
  1218. try:
  1219. _result = self.__chars__('.')
  1220. _result = ( set(['.']) )
  1221. break
  1222. except BacktrackException, _exc:
  1223. _error = self._combine_errors(_error, _exc.error)
  1224. self._pos = _choice2
  1225. _choice3 = self._pos
  1226. try:
  1227. _result = self.__chars__('*')
  1228. _result = ( set(['*']) )
  1229. break
  1230. except BacktrackException, _exc:
  1231. _error = self._combine_errors(_error, _exc.error)
  1232. self._pos = _choice3
  1233. _choice4 = self._pos
  1234. try:
  1235. _result = self.__chars__('+')
  1236. _result = ( set(['+']) )
  1237. break
  1238. except BacktrackException, _exc:
  1239. _error = self._combine_errors(_error, _exc.error)
  1240. self._pos = _choice4
  1241. _choice5 = self._pos
  1242. try:
  1243. _result = self.__chars__('?')
  1244. _result = ( set(['?']) )
  1245. break

Large files files are truncated, but you can click here to view the full file