| 1 |
from __future__ import print_function |
| 2 |
|
| 3 |
import py |
| 4 |
from rpython.rlib.parsing.parsing import PackratParser, Rule |
| 5 |
from rpython.rlib.parsing.tree import Nonterminal |
| 6 |
from rpython.rlib.parsing.regex import StringExpression, RangeExpression |
| 7 |
from rpython.rlib.parsing.lexer import Lexer, DummyLexer |
| 8 |
from rpython.rlib.parsing.deterministic import compress_char_set, DFA |
| 9 |
import string |
| 10 |
|
| 11 |
set = py.builtin.set |
| 12 |
|
| 13 |
ESCAPES = { |
| 14 |
"a": "\a", |
| 15 |
"b": "\b", |
| 16 |
"e": "\x1b", |
| 17 |
"f": "\f", |
| 18 |
"n": "\n", |
| 19 |
"r": "\r", |
| 20 |
"t": "\t", |
| 21 |
"v": "\v", |
| 22 |
} |
| 23 |
|
| 24 |
for i in range(256): |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
escaped = "c%s" % chr(i) |
| 31 |
ESCAPES[escaped] = chr(ord(chr(i).upper()) ^ 0x40) |
| 32 |
|
| 33 |
def unescape_muncher(string): |
| 34 |
"""Return a tuple, representing the first character of the string |
| 35 |
(appropriately unescaped) and the rest of the string that wasn't |
| 36 |
handled.""" |
| 37 |
if string[0] != '\\': |
| 38 |
|
| 39 |
return string[0], string[1:] |
| 40 |
if string[1] == 'x': |
| 41 |
|
| 42 |
char = chr(int(string[2:4], 16)) |
| 43 |
return char, string[4:] |
| 44 |
if string[1] in '01234567': |
| 45 |
|
| 46 |
span = 2 |
| 47 |
span += (span < len(string)) and (string[span] in '01234567') |
| 48 |
span += (span < len(string)) and (string[span] in '01234567') |
| 49 |
char = chr(int(string[1:span], 8)) |
| 50 |
return char, string[span:] |
| 51 |
if string[1] == 'c': |
| 52 |
|
| 53 |
return ESCAPES['c'+string[2]], string[3:] |
| 54 |
if string[1] in ESCAPES: |
| 55 |
|
| 56 |
return ESCAPES[string[1]], string[2:] |
| 57 |
|
| 58 |
return string[1], string[2:] |
| 59 |
|
| 60 |
|
| 61 |
def unescape(s): |
| 62 |
"""Unescape a whole string.""" |
| 63 |
result = [] |
| 64 |
while s: |
| 65 |
char, s = unescape_muncher(s) |
| 66 |
result.append(char) |
| 67 |
return "".join(result) |
| 68 |
|
| 69 |
syntax = r""" |
| 70 |
EOF: |
| 71 |
!__any__; |
| 72 |
|
| 73 |
parse: |
| 74 |
regex |
| 75 |
[EOF]; |
| 76 |
|
| 77 |
regex: |
| 78 |
r1 = concatenation |
| 79 |
'|' |
| 80 |
r2 = regex |
| 81 |
return {r1 | r2} |
| 82 |
| concatenation; |
| 83 |
|
| 84 |
concatenation: |
| 85 |
l = repetition* |
| 86 |
return {reduce(operator.add, l, regex.StringExpression(""))}; |
| 87 |
|
| 88 |
repetition: |
| 89 |
r1 = primary |
| 90 |
'*' |
| 91 |
return {r1.kleene()} |
| 92 |
| r1 = primary |
| 93 |
'+' |
| 94 |
return {r1 + r1.kleene()} |
| 95 |
| r1 = primary |
| 96 |
'?' |
| 97 |
return {regex.StringExpression("") | r1} |
| 98 |
| r1 = primary |
| 99 |
'{' |
| 100 |
n = clippednumrange |
| 101 |
'}' |
| 102 |
return {r1 * n + r1.kleene()} |
| 103 |
| r1 = primary |
| 104 |
'{' |
| 105 |
n = numrange |
| 106 |
'}' |
| 107 |
return {r1 * n[0] + reduce(operator.or_, [r1 * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))} |
| 108 |
| '{' |
| 109 |
return {regex.StringExpression("{")} |
| 110 |
| primary; |
| 111 |
|
| 112 |
primary: |
| 113 |
['('] regex [')'] |
| 114 |
| range |
| 115 |
| cc = charclass |
| 116 |
return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(cc)])} |
| 117 |
| c = char |
| 118 |
return {regex.StringExpression(c)} |
| 119 |
| '.' |
| 120 |
return {regex.RangeExpression(chr(0), chr(255))} |
| 121 |
| '-' |
| 122 |
return {regex.StringExpression('-')} |
| 123 |
| '\' |
| 124 |
return {regex.StringExpression('\\')} |
| 125 |
| ']' |
| 126 |
return {regex.StringExpression(']')}; |
| 127 |
|
| 128 |
char: |
| 129 |
c = QUOTEDCHAR |
| 130 |
return {unescape(c)} |
| 131 |
| c = CHAR |
| 132 |
return {c}; |
| 133 |
|
| 134 |
QUOTEDCHAR: |
| 135 |
`(\\x[0-9a-fA-F]{2})|(\\[0-3]?[0-7][0-7])|(\\c.)|(\\[^dswDSW])`; |
| 136 |
|
| 137 |
CHAR: |
| 138 |
`[^\*\+\(\)\[\]\{\|\.\-\?\^\\]`; |
| 139 |
|
| 140 |
range: |
| 141 |
'[' |
| 142 |
s = rangeinner |
| 143 |
']' |
| 144 |
return {reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])}; |
| 145 |
|
| 146 |
rangeinner: |
| 147 |
'^' |
| 148 |
s = subrange |
| 149 |
return {set([chr(c) for c in range(256)]) - s} |
| 150 |
| subrange; |
| 151 |
|
| 152 |
subrange: |
| 153 |
']' |
| 154 |
l = rangeelement* |
| 155 |
return {reduce(operator.or_, [set(["]"])] + l)} |
| 156 |
| l = rangeelement+ |
| 157 |
return {reduce(operator.or_, l)}; |
| 158 |
|
| 159 |
rangeelement: |
| 160 |
charclass |
| 161 |
| c1 = char |
| 162 |
'-' |
| 163 |
c2 = char |
| 164 |
return {set([chr(i) for i in range(ord(c1), ord(c2) + 1)])} |
| 165 |
| '.' |
| 166 |
return { set(['.']) } |
| 167 |
| '*' |
| 168 |
return { set(['*']) } |
| 169 |
| '+' |
| 170 |
return { set(['+']) } |
| 171 |
| '?' |
| 172 |
return { set(['?']) } |
| 173 |
| '-' |
| 174 |
return { set(['-']) } |
| 175 |
| '[' |
| 176 |
return { set(['[']) } |
| 177 |
| c = char |
| 178 |
return { set([c]) }; |
| 179 |
|
| 180 |
numrange: |
| 181 |
n1 = NUM |
| 182 |
',' |
| 183 |
n2 = NUM |
| 184 |
return {n1, n2} |
| 185 |
| n1 = NUM |
| 186 |
return {n1, n1}; |
| 187 |
|
| 188 |
clippednumrange: |
| 189 |
n1 = NUM |
| 190 |
',' |
| 191 |
return {n1}; |
| 192 |
|
| 193 |
charclass: |
| 194 |
'\' 'd' |
| 195 |
return { set([chr(c) for c in range(ord('0'), ord('9')+1)]) } |
| 196 |
| '\' 's' |
| 197 |
return { set(['\t', '\n', '\f', '\r', ' ']) } |
| 198 |
| '\' 'w' |
| 199 |
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)] + ['_']) } |
| 200 |
| '\' 'D' |
| 201 |
return { set([chr(c) for c in range(256)]) - set([chr(c) for c in range(ord('0'), ord('9')+1)]) } |
| 202 |
| '\' 'S' |
| 203 |
return { set([chr(c) for c in range(256)]) - set(['\t', '\n', '\f', '\r', ' ']) } |
| 204 |
| '\' 'W' |
| 205 |
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)] + ['_'])}; |
| 206 |
|
| 207 |
NUM: |
| 208 |
c = `0|([1-9][0-9]*)` |
| 209 |
return {int(c)}; |
| 210 |
""" |
| 211 |
|
| 212 |
|
| 213 |
def parse_regex(s): |
| 214 |
p = RegexParser(s) |
| 215 |
r = p.parse() |
| 216 |
return r |
| 217 |
|
| 218 |
def make_runner(regex, view=False): |
| 219 |
r = parse_regex(regex) |
| 220 |
nfa = r.make_automaton() |
| 221 |
dfa = nfa.make_deterministic() |
| 222 |
if view: |
| 223 |
dfa.view() |
| 224 |
dfa.optimize() |
| 225 |
if view: |
| 226 |
dfa.view() |
| 227 |
r = dfa.get_runner() |
| 228 |
return r |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
from rpython.rlib.parsing.pypackrat import PackratParser, Status |
| 246 |
from rpython.rlib.parsing.pypackrat import BacktrackException |
| 247 |
from rpython.rlib.parsing import regex |
| 248 |
import operator |
| 249 |
class Parser(object): |
| 250 |
def EOF(self): |
| 251 |
return self._EOF().result |
| 252 |
def _EOF(self): |
| 253 |
_key = self._pos |
| 254 |
_status = self._dict_EOF.get(_key, None) |
| 255 |
if _status is None: |
| 256 |
_status = self._dict_EOF[_key] = Status() |
| 257 |
else: |
| 258 |
_statusstatus = _status.status |
| 259 |
if _statusstatus == _status.NORMAL: |
| 260 |
self._pos = _status.pos |
| 261 |
return _status |
| 262 |
elif _statusstatus == _status.ERROR: |
| 263 |
raise BacktrackException(_status.error) |
| 264 |
elif (_statusstatus == _status.INPROGRESS or |
| 265 |
_statusstatus == _status.LEFTRECURSION): |
| 266 |
_status.status = _status.LEFTRECURSION |
| 267 |
if _status.result is not None: |
| 268 |
self._pos = _status.pos |
| 269 |
return _status |
| 270 |
else: |
| 271 |
raise BacktrackException(None) |
| 272 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 273 |
_status.status = _status.INPROGRESS |
| 274 |
_startingpos = self._pos |
| 275 |
try: |
| 276 |
_result = None |
| 277 |
_error = None |
| 278 |
_choice0 = self._pos |
| 279 |
_stored_result1 = _result |
| 280 |
try: |
| 281 |
_result = self.__any__() |
| 282 |
except BacktrackException: |
| 283 |
self._pos = _choice0 |
| 284 |
_result = _stored_result1 |
| 285 |
else: |
| 286 |
raise BacktrackException(None) |
| 287 |
if _status.status == _status.LEFTRECURSION: |
| 288 |
if _status.result is not None: |
| 289 |
if _status.pos >= self._pos: |
| 290 |
_status.status = _status.NORMAL |
| 291 |
self._pos = _status.pos |
| 292 |
return _status |
| 293 |
_status.pos = self._pos |
| 294 |
_status.status = _status.SOMESOLUTIONS |
| 295 |
_status.result = _result |
| 296 |
_status.error = _error |
| 297 |
self._pos = _startingpos |
| 298 |
return self._EOF() |
| 299 |
_status.status = _status.NORMAL |
| 300 |
_status.pos = self._pos |
| 301 |
_status.result = _result |
| 302 |
_status.error = _error |
| 303 |
return _status |
| 304 |
except BacktrackException as _exc: |
| 305 |
_status.pos = -1 |
| 306 |
_status.result = None |
| 307 |
_error = _exc.error |
| 308 |
_status.error = _error |
| 309 |
_status.status = _status.ERROR |
| 310 |
raise BacktrackException(_error) |
| 311 |
def parse(self): |
| 312 |
return self._parse().result |
| 313 |
def _parse(self): |
| 314 |
_key = self._pos |
| 315 |
_status = self._dict_parse.get(_key, None) |
| 316 |
if _status is None: |
| 317 |
_status = self._dict_parse[_key] = Status() |
| 318 |
else: |
| 319 |
_statusstatus = _status.status |
| 320 |
if _statusstatus == _status.NORMAL: |
| 321 |
self._pos = _status.pos |
| 322 |
return _status |
| 323 |
elif _statusstatus == _status.ERROR: |
| 324 |
raise BacktrackException(_status.error) |
| 325 |
elif (_statusstatus == _status.INPROGRESS or |
| 326 |
_statusstatus == _status.LEFTRECURSION): |
| 327 |
_status.status = _status.LEFTRECURSION |
| 328 |
if _status.result is not None: |
| 329 |
self._pos = _status.pos |
| 330 |
return _status |
| 331 |
else: |
| 332 |
raise BacktrackException(None) |
| 333 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 334 |
_status.status = _status.INPROGRESS |
| 335 |
_startingpos = self._pos |
| 336 |
try: |
| 337 |
_result = None |
| 338 |
_error = None |
| 339 |
_call_status = self._regex() |
| 340 |
_result = _call_status.result |
| 341 |
_error = _call_status.error |
| 342 |
_before_discard0 = _result |
| 343 |
_call_status = self._EOF() |
| 344 |
_result = _call_status.result |
| 345 |
_error = self._combine_errors(_error, _call_status.error) |
| 346 |
_result = _before_discard0 |
| 347 |
if _status.status == _status.LEFTRECURSION: |
| 348 |
if _status.result is not None: |
| 349 |
if _status.pos >= self._pos: |
| 350 |
_status.status = _status.NORMAL |
| 351 |
self._pos = _status.pos |
| 352 |
return _status |
| 353 |
_status.pos = self._pos |
| 354 |
_status.status = _status.SOMESOLUTIONS |
| 355 |
_status.result = _result |
| 356 |
_status.error = _error |
| 357 |
self._pos = _startingpos |
| 358 |
return self._parse() |
| 359 |
_status.status = _status.NORMAL |
| 360 |
_status.pos = self._pos |
| 361 |
_status.result = _result |
| 362 |
_status.error = _error |
| 363 |
return _status |
| 364 |
except BacktrackException as _exc: |
| 365 |
_status.pos = -1 |
| 366 |
_status.result = None |
| 367 |
_error = self._combine_errors(_error, _exc.error) |
| 368 |
_status.error = _error |
| 369 |
_status.status = _status.ERROR |
| 370 |
raise BacktrackException(_error) |
| 371 |
def regex(self): |
| 372 |
return self._regex().result |
| 373 |
def _regex(self): |
| 374 |
_key = self._pos |
| 375 |
_status = self._dict_regex.get(_key, None) |
| 376 |
if _status is None: |
| 377 |
_status = self._dict_regex[_key] = Status() |
| 378 |
else: |
| 379 |
_statusstatus = _status.status |
| 380 |
if _statusstatus == _status.NORMAL: |
| 381 |
self._pos = _status.pos |
| 382 |
return _status |
| 383 |
elif _statusstatus == _status.ERROR: |
| 384 |
raise BacktrackException(_status.error) |
| 385 |
elif (_statusstatus == _status.INPROGRESS or |
| 386 |
_statusstatus == _status.LEFTRECURSION): |
| 387 |
_status.status = _status.LEFTRECURSION |
| 388 |
if _status.result is not None: |
| 389 |
self._pos = _status.pos |
| 390 |
return _status |
| 391 |
else: |
| 392 |
raise BacktrackException(None) |
| 393 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 394 |
_status.status = _status.INPROGRESS |
| 395 |
_startingpos = self._pos |
| 396 |
try: |
| 397 |
_result = None |
| 398 |
_error = None |
| 399 |
while 1: |
| 400 |
_choice0 = self._pos |
| 401 |
try: |
| 402 |
_call_status = self._concatenation() |
| 403 |
_result = _call_status.result |
| 404 |
_error = _call_status.error |
| 405 |
r1 = _result |
| 406 |
_result = self.__chars__('|') |
| 407 |
_call_status = self._regex() |
| 408 |
_result = _call_status.result |
| 409 |
_error = self._combine_errors(_error, _call_status.error) |
| 410 |
r2 = _result |
| 411 |
_result = (r1 | r2) |
| 412 |
break |
| 413 |
except BacktrackException as _exc: |
| 414 |
_error = self._combine_errors(_error, _exc.error) |
| 415 |
self._pos = _choice0 |
| 416 |
_choice1 = self._pos |
| 417 |
try: |
| 418 |
_call_status = self._concatenation() |
| 419 |
_result = _call_status.result |
| 420 |
_error = self._combine_errors(_error, _call_status.error) |
| 421 |
break |
| 422 |
except BacktrackException as _exc: |
| 423 |
_error = self._combine_errors(_error, _exc.error) |
| 424 |
self._pos = _choice1 |
| 425 |
raise BacktrackException(_error) |
| 426 |
_call_status = self._concatenation() |
| 427 |
_result = _call_status.result |
| 428 |
_error = self._combine_errors(_error, _call_status.error) |
| 429 |
break |
| 430 |
if _status.status == _status.LEFTRECURSION: |
| 431 |
if _status.result is not None: |
| 432 |
if _status.pos >= self._pos: |
| 433 |
_status.status = _status.NORMAL |
| 434 |
self._pos = _status.pos |
| 435 |
return _status |
| 436 |
_status.pos = self._pos |
| 437 |
_status.status = _status.SOMESOLUTIONS |
| 438 |
_status.result = _result |
| 439 |
_status.error = _error |
| 440 |
self._pos = _startingpos |
| 441 |
return self._regex() |
| 442 |
_status.status = _status.NORMAL |
| 443 |
_status.pos = self._pos |
| 444 |
_status.result = _result |
| 445 |
_status.error = _error |
| 446 |
return _status |
| 447 |
except BacktrackException as _exc: |
| 448 |
_status.pos = -1 |
| 449 |
_status.result = None |
| 450 |
_error = self._combine_errors(_error, _exc.error) |
| 451 |
_status.error = _error |
| 452 |
_status.status = _status.ERROR |
| 453 |
raise BacktrackException(_error) |
| 454 |
def concatenation(self): |
| 455 |
return self._concatenation().result |
| 456 |
def _concatenation(self): |
| 457 |
_key = self._pos |
| 458 |
_status = self._dict_concatenation.get(_key, None) |
| 459 |
if _status is None: |
| 460 |
_status = self._dict_concatenation[_key] = Status() |
| 461 |
else: |
| 462 |
_statusstatus = _status.status |
| 463 |
if _statusstatus == _status.NORMAL: |
| 464 |
self._pos = _status.pos |
| 465 |
return _status |
| 466 |
elif _statusstatus == _status.ERROR: |
| 467 |
raise BacktrackException(_status.error) |
| 468 |
elif (_statusstatus == _status.INPROGRESS or |
| 469 |
_statusstatus == _status.LEFTRECURSION): |
| 470 |
_status.status = _status.LEFTRECURSION |
| 471 |
if _status.result is not None: |
| 472 |
self._pos = _status.pos |
| 473 |
return _status |
| 474 |
else: |
| 475 |
raise BacktrackException(None) |
| 476 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 477 |
_status.status = _status.INPROGRESS |
| 478 |
_startingpos = self._pos |
| 479 |
try: |
| 480 |
_result = None |
| 481 |
_error = None |
| 482 |
_all0 = [] |
| 483 |
while 1: |
| 484 |
_choice1 = self._pos |
| 485 |
try: |
| 486 |
_call_status = self._repetition() |
| 487 |
_result = _call_status.result |
| 488 |
_error = _call_status.error |
| 489 |
_all0.append(_result) |
| 490 |
except BacktrackException as _exc: |
| 491 |
_error = self._combine_errors(_error, _exc.error) |
| 492 |
self._pos = _choice1 |
| 493 |
break |
| 494 |
_result = _all0 |
| 495 |
l = _result |
| 496 |
_result = (reduce(operator.add, l, regex.StringExpression(""))) |
| 497 |
if _status.status == _status.LEFTRECURSION: |
| 498 |
if _status.result is not None: |
| 499 |
if _status.pos >= self._pos: |
| 500 |
_status.status = _status.NORMAL |
| 501 |
self._pos = _status.pos |
| 502 |
return _status |
| 503 |
_status.pos = self._pos |
| 504 |
_status.status = _status.SOMESOLUTIONS |
| 505 |
_status.result = _result |
| 506 |
_status.error = _error |
| 507 |
self._pos = _startingpos |
| 508 |
return self._concatenation() |
| 509 |
_status.status = _status.NORMAL |
| 510 |
_status.pos = self._pos |
| 511 |
_status.result = _result |
| 512 |
_status.error = _error |
| 513 |
return _status |
| 514 |
except BacktrackException as _exc: |
| 515 |
_status.pos = -1 |
| 516 |
_status.result = None |
| 517 |
_error = self._combine_errors(_error, _exc.error) |
| 518 |
_status.error = _error |
| 519 |
_status.status = _status.ERROR |
| 520 |
raise BacktrackException(_error) |
| 521 |
def repetition(self): |
| 522 |
return self._repetition().result |
| 523 |
def _repetition(self): |
| 524 |
_key = self._pos |
| 525 |
_status = self._dict_repetition.get(_key, None) |
| 526 |
if _status is None: |
| 527 |
_status = self._dict_repetition[_key] = Status() |
| 528 |
else: |
| 529 |
_statusstatus = _status.status |
| 530 |
if _statusstatus == _status.NORMAL: |
| 531 |
self._pos = _status.pos |
| 532 |
return _status |
| 533 |
elif _statusstatus == _status.ERROR: |
| 534 |
raise BacktrackException(_status.error) |
| 535 |
elif (_statusstatus == _status.INPROGRESS or |
| 536 |
_statusstatus == _status.LEFTRECURSION): |
| 537 |
_status.status = _status.LEFTRECURSION |
| 538 |
if _status.result is not None: |
| 539 |
self._pos = _status.pos |
| 540 |
return _status |
| 541 |
else: |
| 542 |
raise BacktrackException(None) |
| 543 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 544 |
_status.status = _status.INPROGRESS |
| 545 |
_startingpos = self._pos |
| 546 |
try: |
| 547 |
_result = None |
| 548 |
_error = None |
| 549 |
while 1: |
| 550 |
_choice0 = self._pos |
| 551 |
try: |
| 552 |
_call_status = self._primary() |
| 553 |
_result = _call_status.result |
| 554 |
_error = _call_status.error |
| 555 |
r1 = _result |
| 556 |
_result = self.__chars__('*') |
| 557 |
_result = (r1.kleene()) |
| 558 |
break |
| 559 |
except BacktrackException as _exc: |
| 560 |
_error = self._combine_errors(_error, _exc.error) |
| 561 |
self._pos = _choice0 |
| 562 |
_choice1 = self._pos |
| 563 |
try: |
| 564 |
_call_status = self._primary() |
| 565 |
_result = _call_status.result |
| 566 |
_error = self._combine_errors(_error, _call_status.error) |
| 567 |
r1 = _result |
| 568 |
_result = self.__chars__('+') |
| 569 |
_result = (r1 + r1.kleene()) |
| 570 |
break |
| 571 |
except BacktrackException as _exc: |
| 572 |
_error = self._combine_errors(_error, _exc.error) |
| 573 |
self._pos = _choice1 |
| 574 |
_choice2 = self._pos |
| 575 |
try: |
| 576 |
_call_status = self._primary() |
| 577 |
_result = _call_status.result |
| 578 |
_error = self._combine_errors(_error, _call_status.error) |
| 579 |
r1 = _result |
| 580 |
_result = self.__chars__('?') |
| 581 |
_result = (regex.StringExpression("") | r1) |
| 582 |
break |
| 583 |
except BacktrackException as _exc: |
| 584 |
_error = self._combine_errors(_error, _exc.error) |
| 585 |
self._pos = _choice2 |
| 586 |
_choice3 = self._pos |
| 587 |
try: |
| 588 |
_call_status = self._primary() |
| 589 |
_result = _call_status.result |
| 590 |
_error = self._combine_errors(_error, _call_status.error) |
| 591 |
r1 = _result |
| 592 |
_result = self.__chars__('{') |
| 593 |
_call_status = self._clippednumrange() |
| 594 |
_result = _call_status.result |
| 595 |
_error = self._combine_errors(_error, _call_status.error) |
| 596 |
n = _result |
| 597 |
_result = self.__chars__('}') |
| 598 |
_result = (r1 * n + r1.kleene()) |
| 599 |
break |
| 600 |
except BacktrackException as _exc: |
| 601 |
_error = self._combine_errors(_error, _exc.error) |
| 602 |
self._pos = _choice3 |
| 603 |
_choice4 = self._pos |
| 604 |
try: |
| 605 |
_call_status = self._primary() |
| 606 |
_result = _call_status.result |
| 607 |
_error = self._combine_errors(_error, _call_status.error) |
| 608 |
r1 = _result |
| 609 |
_result = self.__chars__('{') |
| 610 |
_call_status = self._numrange() |
| 611 |
_result = _call_status.result |
| 612 |
_error = self._combine_errors(_error, _call_status.error) |
| 613 |
n = _result |
| 614 |
_result = self.__chars__('}') |
| 615 |
_result = (r1 * n[0] + reduce(operator.or_, [r1 * i for i in range(n[1] - n[0] + 1)], regex.StringExpression(""))) |
| 616 |
break |
| 617 |
except BacktrackException as _exc: |
| 618 |
_error = self._combine_errors(_error, _exc.error) |
| 619 |
self._pos = _choice4 |
| 620 |
_choice5 = self._pos |
| 621 |
try: |
| 622 |
_result = self.__chars__('{') |
| 623 |
_result = (regex.StringExpression("{")) |
| 624 |
break |
| 625 |
except BacktrackException as _exc: |
| 626 |
_error = self._combine_errors(_error, _exc.error) |
| 627 |
self._pos = _choice5 |
| 628 |
_choice6 = self._pos |
| 629 |
try: |
| 630 |
_call_status = self._primary() |
| 631 |
_result = _call_status.result |
| 632 |
_error = self._combine_errors(_error, _call_status.error) |
| 633 |
break |
| 634 |
except BacktrackException as _exc: |
| 635 |
_error = self._combine_errors(_error, _exc.error) |
| 636 |
self._pos = _choice6 |
| 637 |
raise BacktrackException(_error) |
| 638 |
_call_status = self._primary() |
| 639 |
_result = _call_status.result |
| 640 |
_error = self._combine_errors(_error, _call_status.error) |
| 641 |
break |
| 642 |
if _status.status == _status.LEFTRECURSION: |
| 643 |
if _status.result is not None: |
| 644 |
if _status.pos >= self._pos: |
| 645 |
_status.status = _status.NORMAL |
| 646 |
self._pos = _status.pos |
| 647 |
return _status |
| 648 |
_status.pos = self._pos |
| 649 |
_status.status = _status.SOMESOLUTIONS |
| 650 |
_status.result = _result |
| 651 |
_status.error = _error |
| 652 |
self._pos = _startingpos |
| 653 |
return self._repetition() |
| 654 |
_status.status = _status.NORMAL |
| 655 |
_status.pos = self._pos |
| 656 |
_status.result = _result |
| 657 |
_status.error = _error |
| 658 |
return _status |
| 659 |
except BacktrackException as _exc: |
| 660 |
_status.pos = -1 |
| 661 |
_status.result = None |
| 662 |
_error = self._combine_errors(_error, _exc.error) |
| 663 |
_status.error = _error |
| 664 |
_status.status = _status.ERROR |
| 665 |
raise BacktrackException(_error) |
| 666 |
def primary(self): |
| 667 |
return self._primary().result |
| 668 |
def _primary(self): |
| 669 |
_key = self._pos |
| 670 |
_status = self._dict_primary.get(_key, None) |
| 671 |
if _status is None: |
| 672 |
_status = self._dict_primary[_key] = Status() |
| 673 |
else: |
| 674 |
_statusstatus = _status.status |
| 675 |
if _statusstatus == _status.NORMAL: |
| 676 |
self._pos = _status.pos |
| 677 |
return _status |
| 678 |
elif _statusstatus == _status.ERROR: |
| 679 |
raise BacktrackException(_status.error) |
| 680 |
elif (_statusstatus == _status.INPROGRESS or |
| 681 |
_statusstatus == _status.LEFTRECURSION): |
| 682 |
_status.status = _status.LEFTRECURSION |
| 683 |
if _status.result is not None: |
| 684 |
self._pos = _status.pos |
| 685 |
return _status |
| 686 |
else: |
| 687 |
raise BacktrackException(None) |
| 688 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 689 |
_status.status = _status.INPROGRESS |
| 690 |
_startingpos = self._pos |
| 691 |
try: |
| 692 |
_result = None |
| 693 |
_error = None |
| 694 |
while 1: |
| 695 |
_choice0 = self._pos |
| 696 |
try: |
| 697 |
_before_discard1 = _result |
| 698 |
_result = self.__chars__('(') |
| 699 |
_result = _before_discard1 |
| 700 |
_call_status = self._regex() |
| 701 |
_result = _call_status.result |
| 702 |
_error = _call_status.error |
| 703 |
_before_discard2 = _result |
| 704 |
_result = self.__chars__(')') |
| 705 |
_result = _before_discard2 |
| 706 |
break |
| 707 |
except BacktrackException as _exc: |
| 708 |
_error = self._combine_errors(_error, _exc.error) |
| 709 |
self._pos = _choice0 |
| 710 |
_choice3 = self._pos |
| 711 |
try: |
| 712 |
_call_status = self._range() |
| 713 |
_result = _call_status.result |
| 714 |
_error = self._combine_errors(_error, _call_status.error) |
| 715 |
break |
| 716 |
except BacktrackException as _exc: |
| 717 |
_error = self._combine_errors(_error, _exc.error) |
| 718 |
self._pos = _choice3 |
| 719 |
_choice4 = self._pos |
| 720 |
try: |
| 721 |
_call_status = self._charclass() |
| 722 |
_result = _call_status.result |
| 723 |
_error = self._combine_errors(_error, _call_status.error) |
| 724 |
cc = _result |
| 725 |
_result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(cc)])) |
| 726 |
break |
| 727 |
except BacktrackException as _exc: |
| 728 |
_error = self._combine_errors(_error, _exc.error) |
| 729 |
self._pos = _choice4 |
| 730 |
_choice5 = self._pos |
| 731 |
try: |
| 732 |
_call_status = self._char() |
| 733 |
_result = _call_status.result |
| 734 |
_error = self._combine_errors(_error, _call_status.error) |
| 735 |
c = _result |
| 736 |
_result = (regex.StringExpression(c)) |
| 737 |
break |
| 738 |
except BacktrackException as _exc: |
| 739 |
_error = self._combine_errors(_error, _exc.error) |
| 740 |
self._pos = _choice5 |
| 741 |
_choice6 = self._pos |
| 742 |
try: |
| 743 |
_result = self.__chars__('.') |
| 744 |
_result = (regex.RangeExpression(chr(0), chr(255))) |
| 745 |
break |
| 746 |
except BacktrackException as _exc: |
| 747 |
_error = self._combine_errors(_error, _exc.error) |
| 748 |
self._pos = _choice6 |
| 749 |
_choice7 = self._pos |
| 750 |
try: |
| 751 |
_result = self.__chars__('-') |
| 752 |
_result = (regex.StringExpression('-')) |
| 753 |
break |
| 754 |
except BacktrackException as _exc: |
| 755 |
_error = self._combine_errors(_error, _exc.error) |
| 756 |
self._pos = _choice7 |
| 757 |
_choice8 = self._pos |
| 758 |
try: |
| 759 |
_result = self.__chars__('\\') |
| 760 |
_result = (regex.StringExpression('\\')) |
| 761 |
break |
| 762 |
except BacktrackException as _exc: |
| 763 |
_error = self._combine_errors(_error, _exc.error) |
| 764 |
self._pos = _choice8 |
| 765 |
_choice9 = self._pos |
| 766 |
try: |
| 767 |
_result = self.__chars__(']') |
| 768 |
_result = (regex.StringExpression(']')) |
| 769 |
break |
| 770 |
except BacktrackException as _exc: |
| 771 |
_error = self._combine_errors(_error, _exc.error) |
| 772 |
self._pos = _choice9 |
| 773 |
raise BacktrackException(_error) |
| 774 |
_result = self.__chars__(']') |
| 775 |
_result = (regex.StringExpression(']')) |
| 776 |
break |
| 777 |
if _status.status == _status.LEFTRECURSION: |
| 778 |
if _status.result is not None: |
| 779 |
if _status.pos >= self._pos: |
| 780 |
_status.status = _status.NORMAL |
| 781 |
self._pos = _status.pos |
| 782 |
return _status |
| 783 |
_status.pos = self._pos |
| 784 |
_status.status = _status.SOMESOLUTIONS |
| 785 |
_status.result = _result |
| 786 |
_status.error = _error |
| 787 |
self._pos = _startingpos |
| 788 |
return self._primary() |
| 789 |
_status.status = _status.NORMAL |
| 790 |
_status.pos = self._pos |
| 791 |
_status.result = _result |
| 792 |
_status.error = _error |
| 793 |
return _status |
| 794 |
except BacktrackException as _exc: |
| 795 |
_status.pos = -1 |
| 796 |
_status.result = None |
| 797 |
_error = self._combine_errors(_error, _exc.error) |
| 798 |
_status.error = _error |
| 799 |
_status.status = _status.ERROR |
| 800 |
raise BacktrackException(_error) |
| 801 |
def char(self): |
| 802 |
return self._char().result |
| 803 |
def _char(self): |
| 804 |
_key = self._pos |
| 805 |
_status = self._dict_char.get(_key, None) |
| 806 |
if _status is None: |
| 807 |
_status = self._dict_char[_key] = Status() |
| 808 |
else: |
| 809 |
_statusstatus = _status.status |
| 810 |
if _statusstatus == _status.NORMAL: |
| 811 |
self._pos = _status.pos |
| 812 |
return _status |
| 813 |
elif _statusstatus == _status.ERROR: |
| 814 |
raise BacktrackException(_status.error) |
| 815 |
elif (_statusstatus == _status.INPROGRESS or |
| 816 |
_statusstatus == _status.LEFTRECURSION): |
| 817 |
_status.status = _status.LEFTRECURSION |
| 818 |
if _status.result is not None: |
| 819 |
self._pos = _status.pos |
| 820 |
return _status |
| 821 |
else: |
| 822 |
raise BacktrackException(None) |
| 823 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 824 |
_status.status = _status.INPROGRESS |
| 825 |
_startingpos = self._pos |
| 826 |
try: |
| 827 |
_result = None |
| 828 |
_error = None |
| 829 |
while 1: |
| 830 |
_choice0 = self._pos |
| 831 |
try: |
| 832 |
_call_status = self._QUOTEDCHAR() |
| 833 |
_result = _call_status.result |
| 834 |
_error = _call_status.error |
| 835 |
c = _result |
| 836 |
_result = (unescape(c)) |
| 837 |
break |
| 838 |
except BacktrackException as _exc: |
| 839 |
_error = self._combine_errors(_error, _exc.error) |
| 840 |
self._pos = _choice0 |
| 841 |
_choice1 = self._pos |
| 842 |
try: |
| 843 |
_call_status = self._CHAR() |
| 844 |
_result = _call_status.result |
| 845 |
_error = self._combine_errors(_error, _call_status.error) |
| 846 |
c = _result |
| 847 |
_result = (c) |
| 848 |
break |
| 849 |
except BacktrackException as _exc: |
| 850 |
_error = self._combine_errors(_error, _exc.error) |
| 851 |
self._pos = _choice1 |
| 852 |
raise BacktrackException(_error) |
| 853 |
_call_status = self._CHAR() |
| 854 |
_result = _call_status.result |
| 855 |
_error = self._combine_errors(_error, _call_status.error) |
| 856 |
c = _result |
| 857 |
_result = (c) |
| 858 |
break |
| 859 |
if _status.status == _status.LEFTRECURSION: |
| 860 |
if _status.result is not None: |
| 861 |
if _status.pos >= self._pos: |
| 862 |
_status.status = _status.NORMAL |
| 863 |
self._pos = _status.pos |
| 864 |
return _status |
| 865 |
_status.pos = self._pos |
| 866 |
_status.status = _status.SOMESOLUTIONS |
| 867 |
_status.result = _result |
| 868 |
_status.error = _error |
| 869 |
self._pos = _startingpos |
| 870 |
return self._char() |
| 871 |
_status.status = _status.NORMAL |
| 872 |
_status.pos = self._pos |
| 873 |
_status.result = _result |
| 874 |
_status.error = _error |
| 875 |
return _status |
| 876 |
except BacktrackException as _exc: |
| 877 |
_status.pos = -1 |
| 878 |
_status.result = None |
| 879 |
_error = self._combine_errors(_error, _exc.error) |
| 880 |
_status.error = _error |
| 881 |
_status.status = _status.ERROR |
| 882 |
raise BacktrackException(_error) |
| 883 |
def QUOTEDCHAR(self): |
| 884 |
return self._QUOTEDCHAR().result |
| 885 |
def _QUOTEDCHAR(self): |
| 886 |
_key = self._pos |
| 887 |
_status = self._dict_QUOTEDCHAR.get(_key, None) |
| 888 |
if _status is None: |
| 889 |
_status = self._dict_QUOTEDCHAR[_key] = Status() |
| 890 |
else: |
| 891 |
_statusstatus = _status.status |
| 892 |
if _statusstatus == _status.NORMAL: |
| 893 |
self._pos = _status.pos |
| 894 |
return _status |
| 895 |
elif _statusstatus == _status.ERROR: |
| 896 |
raise BacktrackException(_status.error) |
| 897 |
_startingpos = self._pos |
| 898 |
try: |
| 899 |
_result = None |
| 900 |
_error = None |
| 901 |
_result = self._regex1423754537() |
| 902 |
assert _status.status != _status.LEFTRECURSION |
| 903 |
_status.status = _status.NORMAL |
| 904 |
_status.pos = self._pos |
| 905 |
_status.result = _result |
| 906 |
_status.error = _error |
| 907 |
return _status |
| 908 |
except BacktrackException as _exc: |
| 909 |
_status.pos = -1 |
| 910 |
_status.result = None |
| 911 |
_error = _exc.error |
| 912 |
_status.error = _error |
| 913 |
_status.status = _status.ERROR |
| 914 |
raise BacktrackException(_error) |
| 915 |
def CHAR(self): |
| 916 |
return self._CHAR().result |
| 917 |
def _CHAR(self): |
| 918 |
_key = self._pos |
| 919 |
_status = self._dict_CHAR.get(_key, None) |
| 920 |
if _status is None: |
| 921 |
_status = self._dict_CHAR[_key] = Status() |
| 922 |
else: |
| 923 |
_statusstatus = _status.status |
| 924 |
if _statusstatus == _status.NORMAL: |
| 925 |
self._pos = _status.pos |
| 926 |
return _status |
| 927 |
elif _statusstatus == _status.ERROR: |
| 928 |
raise BacktrackException(_status.error) |
| 929 |
_startingpos = self._pos |
| 930 |
try: |
| 931 |
_result = None |
| 932 |
_error = None |
| 933 |
_result = self._regex2132196932() |
| 934 |
assert _status.status != _status.LEFTRECURSION |
| 935 |
_status.status = _status.NORMAL |
| 936 |
_status.pos = self._pos |
| 937 |
_status.result = _result |
| 938 |
_status.error = _error |
| 939 |
return _status |
| 940 |
except BacktrackException as _exc: |
| 941 |
_status.pos = -1 |
| 942 |
_status.result = None |
| 943 |
_error = _exc.error |
| 944 |
_status.error = _error |
| 945 |
_status.status = _status.ERROR |
| 946 |
raise BacktrackException(_error) |
| 947 |
def range(self): |
| 948 |
return self._range().result |
| 949 |
def _range(self): |
| 950 |
_key = self._pos |
| 951 |
_status = self._dict_range.get(_key, None) |
| 952 |
if _status is None: |
| 953 |
_status = self._dict_range[_key] = Status() |
| 954 |
else: |
| 955 |
_statusstatus = _status.status |
| 956 |
if _statusstatus == _status.NORMAL: |
| 957 |
self._pos = _status.pos |
| 958 |
return _status |
| 959 |
elif _statusstatus == _status.ERROR: |
| 960 |
raise BacktrackException(_status.error) |
| 961 |
elif (_statusstatus == _status.INPROGRESS or |
| 962 |
_statusstatus == _status.LEFTRECURSION): |
| 963 |
_status.status = _status.LEFTRECURSION |
| 964 |
if _status.result is not None: |
| 965 |
self._pos = _status.pos |
| 966 |
return _status |
| 967 |
else: |
| 968 |
raise BacktrackException(None) |
| 969 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 970 |
_status.status = _status.INPROGRESS |
| 971 |
_startingpos = self._pos |
| 972 |
try: |
| 973 |
_result = None |
| 974 |
_error = None |
| 975 |
_result = self.__chars__('[') |
| 976 |
_call_status = self._rangeinner() |
| 977 |
_result = _call_status.result |
| 978 |
_error = _call_status.error |
| 979 |
s = _result |
| 980 |
_result = self.__chars__(']') |
| 981 |
_result = (reduce(operator.or_, [regex.RangeExpression(a, chr(ord(a) + b - 1)) for a, b in compress_char_set(s)])) |
| 982 |
if _status.status == _status.LEFTRECURSION: |
| 983 |
if _status.result is not None: |
| 984 |
if _status.pos >= self._pos: |
| 985 |
_status.status = _status.NORMAL |
| 986 |
self._pos = _status.pos |
| 987 |
return _status |
| 988 |
_status.pos = self._pos |
| 989 |
_status.status = _status.SOMESOLUTIONS |
| 990 |
_status.result = _result |
| 991 |
_status.error = _error |
| 992 |
self._pos = _startingpos |
| 993 |
return self._range() |
| 994 |
_status.status = _status.NORMAL |
| 995 |
_status.pos = self._pos |
| 996 |
_status.result = _result |
| 997 |
_status.error = _error |
| 998 |
return _status |
| 999 |
except BacktrackException as _exc: |
| 1000 |
_status.pos = -1 |
| 1001 |
_status.result = None |
| 1002 |
_error = self._combine_errors(_error, _exc.error) |
| 1003 |
_status.error = _error |
| 1004 |
_status.status = _status.ERROR |
| 1005 |
raise BacktrackException(_error) |
| 1006 |
def rangeinner(self): |
| 1007 |
return self._rangeinner().result |
| 1008 |
def _rangeinner(self): |
| 1009 |
_key = self._pos |
| 1010 |
_status = self._dict_rangeinner.get(_key, None) |
| 1011 |
if _status is None: |
| 1012 |
_status = self._dict_rangeinner[_key] = Status() |
| 1013 |
else: |
| 1014 |
_statusstatus = _status.status |
| 1015 |
if _statusstatus == _status.NORMAL: |
| 1016 |
self._pos = _status.pos |
| 1017 |
return _status |
| 1018 |
elif _statusstatus == _status.ERROR: |
| 1019 |
raise BacktrackException(_status.error) |
| 1020 |
elif (_statusstatus == _status.INPROGRESS or |
| 1021 |
_statusstatus == _status.LEFTRECURSION): |
| 1022 |
_status.status = _status.LEFTRECURSION |
| 1023 |
if _status.result is not None: |
| 1024 |
self._pos = _status.pos |
| 1025 |
return _status |
| 1026 |
else: |
| 1027 |
raise BacktrackException(None) |
| 1028 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 1029 |
_status.status = _status.INPROGRESS |
| 1030 |
_startingpos = self._pos |
| 1031 |
try: |
| 1032 |
_result = None |
| 1033 |
_error = None |
| 1034 |
while 1: |
| 1035 |
_choice0 = self._pos |
| 1036 |
try: |
| 1037 |
_result = self.__chars__('^') |
| 1038 |
_call_status = self._subrange() |
| 1039 |
_result = _call_status.result |
| 1040 |
_error = _call_status.error |
| 1041 |
s = _result |
| 1042 |
_result = (set([chr(c) for c in range(256)]) - s) |
| 1043 |
break |
| 1044 |
except BacktrackException as _exc: |
| 1045 |
_error = self._combine_errors(_error, _exc.error) |
| 1046 |
self._pos = _choice0 |
| 1047 |
_choice1 = self._pos |
| 1048 |
try: |
| 1049 |
_call_status = self._subrange() |
| 1050 |
_result = _call_status.result |
| 1051 |
_error = self._combine_errors(_error, _call_status.error) |
| 1052 |
break |
| 1053 |
except BacktrackException as _exc: |
| 1054 |
_error = self._combine_errors(_error, _exc.error) |
| 1055 |
self._pos = _choice1 |
| 1056 |
raise BacktrackException(_error) |
| 1057 |
_call_status = self._subrange() |
| 1058 |
_result = _call_status.result |
| 1059 |
_error = self._combine_errors(_error, _call_status.error) |
| 1060 |
break |
| 1061 |
if _status.status == _status.LEFTRECURSION: |
| 1062 |
if _status.result is not None: |
| 1063 |
if _status.pos >= self._pos: |
| 1064 |
_status.status = _status.NORMAL |
| 1065 |
self._pos = _status.pos |
| 1066 |
return _status |
| 1067 |
_status.pos = self._pos |
| 1068 |
_status.status = _status.SOMESOLUTIONS |
| 1069 |
_status.result = _result |
| 1070 |
_status.error = _error |
| 1071 |
self._pos = _startingpos |
| 1072 |
return self._rangeinner() |
| 1073 |
_status.status = _status.NORMAL |
| 1074 |
_status.pos = self._pos |
| 1075 |
_status.result = _result |
| 1076 |
_status.error = _error |
| 1077 |
return _status |
| 1078 |
except BacktrackException as _exc: |
| 1079 |
_status.pos = -1 |
| 1080 |
_status.result = None |
| 1081 |
_error = self._combine_errors(_error, _exc.error) |
| 1082 |
_status.error = _error |
| 1083 |
_status.status = _status.ERROR |
| 1084 |
raise BacktrackException(_error) |
| 1085 |
def subrange(self): |
| 1086 |
return self._subrange().result |
| 1087 |
def _subrange(self): |
| 1088 |
_key = self._pos |
| 1089 |
_status = self._dict_subrange.get(_key, None) |
| 1090 |
if _status is None: |
| 1091 |
_status = self._dict_subrange[_key] = Status() |
| 1092 |
else: |
| 1093 |
_statusstatus = _status.status |
| 1094 |
if _statusstatus == _status.NORMAL: |
| 1095 |
self._pos = _status.pos |
| 1096 |
return _status |
| 1097 |
elif _statusstatus == _status.ERROR: |
| 1098 |
raise BacktrackException(_status.error) |
| 1099 |
elif (_statusstatus == _status.INPROGRESS or |
| 1100 |
_statusstatus == _status.LEFTRECURSION): |
| 1101 |
_status.status = _status.LEFTRECURSION |
| 1102 |
if _status.result is not None: |
| 1103 |
self._pos = _status.pos |
| 1104 |
return _status |
| 1105 |
else: |
| 1106 |
raise BacktrackException(None) |
| 1107 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 1108 |
_status.status = _status.INPROGRESS |
| 1109 |
_startingpos = self._pos |
| 1110 |
try: |
| 1111 |
_result = None |
| 1112 |
_error = None |
| 1113 |
while 1: |
| 1114 |
_choice0 = self._pos |
| 1115 |
try: |
| 1116 |
_result = self.__chars__(']') |
| 1117 |
_all1 = [] |
| 1118 |
while 1: |
| 1119 |
_choice2 = self._pos |
| 1120 |
try: |
| 1121 |
_call_status = self._rangeelement() |
| 1122 |
_result = _call_status.result |
| 1123 |
_error = _call_status.error |
| 1124 |
_all1.append(_result) |
| 1125 |
except BacktrackException as _exc: |
| 1126 |
_error = self._combine_errors(_error, _exc.error) |
| 1127 |
self._pos = _choice2 |
| 1128 |
break |
| 1129 |
_result = _all1 |
| 1130 |
l = _result |
| 1131 |
_result = (reduce(operator.or_, [set(["]"])] + l)) |
| 1132 |
break |
| 1133 |
except BacktrackException as _exc: |
| 1134 |
_error = self._combine_errors(_error, _exc.error) |
| 1135 |
self._pos = _choice0 |
| 1136 |
_choice3 = self._pos |
| 1137 |
try: |
| 1138 |
_all4 = [] |
| 1139 |
_call_status = self._rangeelement() |
| 1140 |
_result = _call_status.result |
| 1141 |
_error = self._combine_errors(_error, _call_status.error) |
| 1142 |
_all4.append(_result) |
| 1143 |
while 1: |
| 1144 |
_choice5 = self._pos |
| 1145 |
try: |
| 1146 |
_call_status = self._rangeelement() |
| 1147 |
_result = _call_status.result |
| 1148 |
_error = self._combine_errors(_error, _call_status.error) |
| 1149 |
_all4.append(_result) |
| 1150 |
except BacktrackException as _exc: |
| 1151 |
_error = self._combine_errors(_error, _exc.error) |
| 1152 |
self._pos = _choice5 |
| 1153 |
break |
| 1154 |
_result = _all4 |
| 1155 |
l = _result |
| 1156 |
_result = (reduce(operator.or_, l)) |
| 1157 |
break |
| 1158 |
except BacktrackException as _exc: |
| 1159 |
_error = self._combine_errors(_error, _exc.error) |
| 1160 |
self._pos = _choice3 |
| 1161 |
raise BacktrackException(_error) |
| 1162 |
_all6 = [] |
| 1163 |
_call_status = self._rangeelement() |
| 1164 |
_result = _call_status.result |
| 1165 |
_error = self._combine_errors(_error, _call_status.error) |
| 1166 |
_all6.append(_result) |
| 1167 |
while 1: |
| 1168 |
_choice7 = self._pos |
| 1169 |
try: |
| 1170 |
_call_status = self._rangeelement() |
| 1171 |
_result = _call_status.result |
| 1172 |
_error = self._combine_errors(_error, _call_status.error) |
| 1173 |
_all6.append(_result) |
| 1174 |
except BacktrackException as _exc: |
| 1175 |
_error = self._combine_errors(_error, _exc.error) |
| 1176 |
self._pos = _choice7 |
| 1177 |
break |
| 1178 |
_result = _all6 |
| 1179 |
l = _result |
| 1180 |
_result = (reduce(operator.or_, l)) |
| 1181 |
break |
| 1182 |
if _status.status == _status.LEFTRECURSION: |
| 1183 |
if _status.result is not None: |
| 1184 |
if _status.pos >= self._pos: |
| 1185 |
_status.status = _status.NORMAL |
| 1186 |
self._pos = _status.pos |
| 1187 |
return _status |
| 1188 |
_status.pos = self._pos |
| 1189 |
_status.status = _status.SOMESOLUTIONS |
| 1190 |
_status.result = _result |
| 1191 |
_status.error = _error |
| 1192 |
self._pos = _startingpos |
| 1193 |
return self._subrange() |
| 1194 |
_status.status = _status.NORMAL |
| 1195 |
_status.pos = self._pos |
| 1196 |
_status.result = _result |
| 1197 |
_status.error = _error |
| 1198 |
return _status |
| 1199 |
except BacktrackException as _exc: |
| 1200 |
_status.pos = -1 |
| 1201 |
_status.result = None |
| 1202 |
_error = self._combine_errors(_error, _exc.error) |
| 1203 |
_status.error = _error |
| 1204 |
_status.status = _status.ERROR |
| 1205 |
raise BacktrackException(_error) |
| 1206 |
def rangeelement(self): |
| 1207 |
return self._rangeelement().result |
| 1208 |
def _rangeelement(self): |
| 1209 |
_key = self._pos |
| 1210 |
_status = self._dict_rangeelement.get(_key, None) |
| 1211 |
if _status is None: |
| 1212 |
_status = self._dict_rangeelement[_key] = Status() |
| 1213 |
else: |
| 1214 |
_statusstatus = _status.status |
| 1215 |
if _statusstatus == _status.NORMAL: |
| 1216 |
self._pos = _status.pos |
| 1217 |
return _status |
| 1218 |
elif _statusstatus == _status.ERROR: |
| 1219 |
raise BacktrackException(_status.error) |
| 1220 |
elif (_statusstatus == _status.INPROGRESS or |
| 1221 |
_statusstatus == _status.LEFTRECURSION): |
| 1222 |
_status.status = _status.LEFTRECURSION |
| 1223 |
if _status.result is not None: |
| 1224 |
self._pos = _status.pos |
| 1225 |
return _status |
| 1226 |
else: |
| 1227 |
raise BacktrackException(None) |
| 1228 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 1229 |
_status.status = _status.INPROGRESS |
| 1230 |
_startingpos = self._pos |
| 1231 |
try: |
| 1232 |
_result = None |
| 1233 |
_error = None |
| 1234 |
while 1: |
| 1235 |
_choice0 = self._pos |
| 1236 |
try: |
| 1237 |
_call_status = self._charclass() |
| 1238 |
_result = _call_status.result |
| 1239 |
_error = _call_status.error |
| 1240 |
break |
| 1241 |
except BacktrackException as _exc: |
| 1242 |
_error = self._combine_errors(_error, _exc.error) |
| 1243 |
self._pos = _choice0 |
| 1244 |
_choice1 = self._pos |
| 1245 |
try: |
| 1246 |
_call_status = self._char() |
| 1247 |
_result = _call_status.result |
| 1248 |
_error = self._combine_errors(_error, _call_status.error) |
| 1249 |
c1 = _result |
| 1250 |
_result = self.__chars__('-') |
| 1251 |
_call_status = self._char() |
| 1252 |
_result = _call_status.result |
| 1253 |
_error = self._combine_errors(_error, _call_status.error) |
| 1254 |
c2 = _result |
| 1255 |
_result = (set([chr(i) for i in range(ord(c1), ord(c2) + 1)])) |
| 1256 |
break |
| 1257 |
except BacktrackException as _exc: |
| 1258 |
_error = self._combine_errors(_error, _exc.error) |
| 1259 |
self._pos = _choice1 |
| 1260 |
_choice2 = self._pos |
| 1261 |
try: |
| 1262 |
_result = self.__chars__('.') |
| 1263 |
_result = ( set(['.']) ) |
| 1264 |
break |
| 1265 |
except BacktrackException as _exc: |
| 1266 |
_error = self._combine_errors(_error, _exc.error) |
| 1267 |
self._pos = _choice2 |
| 1268 |
_choice3 = self._pos |
| 1269 |
try: |
| 1270 |
_result = self.__chars__('*') |
| 1271 |
_result = ( set(['*']) ) |
| 1272 |
break |
| 1273 |
except BacktrackException as _exc: |
| 1274 |
_error = self._combine_errors(_error, _exc.error) |
| 1275 |
self._pos = _choice3 |
| 1276 |
_choice4 = self._pos |
| 1277 |
try: |
| 1278 |
_result = self.__chars__('+') |
| 1279 |
_result = ( set(['+']) ) |
| 1280 |
break |
| 1281 |
except BacktrackException as _exc: |
| 1282 |
_error = self._combine_errors(_error, _exc.error) |
| 1283 |
self._pos = _choice4 |
| 1284 |
_choice5 = self._pos |
| 1285 |
try: |
| 1286 |
_result = self.__chars__('?') |
| 1287 |
_result = ( set(['?']) ) |
| 1288 |
break |
| 1289 |
except BacktrackException as _exc: |
| 1290 |
_error = self._combine_errors(_error, _exc.error) |
| 1291 |
self._pos = _choice5 |
| 1292 |
_choice6 = self._pos |
| 1293 |
try: |
| 1294 |
_result = self.__chars__('-') |
| 1295 |
_result = ( set(['-']) ) |
| 1296 |
break |
| 1297 |
except BacktrackException as _exc: |
| 1298 |
_error = self._combine_errors(_error, _exc.error) |
| 1299 |
self._pos = _choice6 |
| 1300 |
_choice7 = self._pos |
| 1301 |
try: |
| 1302 |
_result = self.__chars__('[') |
| 1303 |
_result = ( set(['[']) ) |
| 1304 |
break |
| 1305 |
except BacktrackException as _exc: |
| 1306 |
_error = self._combine_errors(_error, _exc.error) |
| 1307 |
self._pos = _choice7 |
| 1308 |
_choice8 = self._pos |
| 1309 |
try: |
| 1310 |
_call_status = self._char() |
| 1311 |
_result = _call_status.result |
| 1312 |
_error = self._combine_errors(_error, _call_status.error) |
| 1313 |
c = _result |
| 1314 |
_result = ( set([c]) ) |
| 1315 |
break |
| 1316 |
except BacktrackException as _exc: |
| 1317 |
_error = self._combine_errors(_error, _exc.error) |
| 1318 |
self._pos = _choice8 |
| 1319 |
raise BacktrackException(_error) |
| 1320 |
_call_status = self._char() |
| 1321 |
_result = _call_status.result |
| 1322 |
_error = self._combine_errors(_error, _call_status.error) |
| 1323 |
c = _result |
| 1324 |
_result = ( set([c]) ) |
| 1325 |
break |
| 1326 |
if _status.status == _status.LEFTRECURSION: |
| 1327 |
if _status.result is not None: |
| 1328 |
if _status.pos >= self._pos: |
| 1329 |
_status.status = _status.NORMAL |
| 1330 |
self._pos = _status.pos |
| 1331 |
return _status |
| 1332 |
_status.pos = self._pos |
| 1333 |
_status.status = _status.SOMESOLUTIONS |
| 1334 |
_status.result = _result |
| 1335 |
_status.error = _error |
| 1336 |
self._pos = _startingpos |
| 1337 |
return self._rangeelement() |
| 1338 |
_status.status = _status.NORMAL |
| 1339 |
_status.pos = self._pos |
| 1340 |
_status.result = _result |
| 1341 |
_status.error = _error |
| 1342 |
return _status |
| 1343 |
except BacktrackException as _exc: |
| 1344 |
_status.pos = -1 |
| 1345 |
_status.result = None |
| 1346 |
_error = self._combine_errors(_error, _exc.error) |
| 1347 |
_status.error = _error |
| 1348 |
_status.status = _status.ERROR |
| 1349 |
raise BacktrackException(_error) |
| 1350 |
def numrange(self): |
| 1351 |
return self._numrange().result |
| 1352 |
def _numrange(self): |
| 1353 |
_key = self._pos |
| 1354 |
_status = self._dict_numrange.get(_key, None) |
| 1355 |
if _status is None: |
| 1356 |
_status = self._dict_numrange[_key] = Status() |
| 1357 |
else: |
| 1358 |
_statusstatus = _status.status |
| 1359 |
if _statusstatus == _status.NORMAL: |
| 1360 |
self._pos = _status.pos |
| 1361 |
return _status |
| 1362 |
elif _statusstatus == _status.ERROR: |
| 1363 |
raise BacktrackException(_status.error) |
| 1364 |
elif (_statusstatus == _status.INPROGRESS or |
| 1365 |
_statusstatus == _status.LEFTRECURSION): |
| 1366 |
_status.status = _status.LEFTRECURSION |
| 1367 |
if _status.result is not None: |
| 1368 |
self._pos = _status.pos |
| 1369 |
return _status |
| 1370 |
else: |
| 1371 |
raise BacktrackException(None) |
| 1372 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 1373 |
_status.status = _status.INPROGRESS |
| 1374 |
_startingpos = self._pos |
| 1375 |
try: |
| 1376 |
_result = None |
| 1377 |
_error = None |
| 1378 |
while 1: |
| 1379 |
_choice0 = self._pos |
| 1380 |
try: |
| 1381 |
_call_status = self._NUM() |
| 1382 |
_result = _call_status.result |
| 1383 |
_error = _call_status.error |
| 1384 |
n1 = _result |
| 1385 |
_result = self.__chars__(',') |
| 1386 |
_call_status = self._NUM() |
| 1387 |
_result = _call_status.result |
| 1388 |
_error = self._combine_errors(_error, _call_status.error) |
| 1389 |
n2 = _result |
| 1390 |
_result = (n1, n2) |
| 1391 |
break |
| 1392 |
except BacktrackException as _exc: |
| 1393 |
_error = self._combine_errors(_error, _exc.error) |
| 1394 |
self._pos = _choice0 |
| 1395 |
_choice1 = self._pos |
| 1396 |
try: |
| 1397 |
_call_status = self._NUM() |
| 1398 |
_result = _call_status.result |
| 1399 |
_error = self._combine_errors(_error, _call_status.error) |
| 1400 |
n1 = _result |
| 1401 |
_result = (n1, n1) |
| 1402 |
break |
| 1403 |
except BacktrackException as _exc: |
| 1404 |
_error = self._combine_errors(_error, _exc.error) |
| 1405 |
self._pos = _choice1 |
| 1406 |
raise BacktrackException(_error) |
| 1407 |
_call_status = self._NUM() |
| 1408 |
_result = _call_status.result |
| 1409 |
_error = self._combine_errors(_error, _call_status.error) |
| 1410 |
n1 = _result |
| 1411 |
_result = (n1, n1) |
| 1412 |
break |
| 1413 |
if _status.status == _status.LEFTRECURSION: |
| 1414 |
if _status.result is not None: |
| 1415 |
if _status.pos >= self._pos: |
| 1416 |
_status.status = _status.NORMAL |
| 1417 |
self._pos = _status.pos |
| 1418 |
return _status |
| 1419 |
_status.pos = self._pos |
| 1420 |
_status.status = _status.SOMESOLUTIONS |
| 1421 |
_status.result = _result |
| 1422 |
_status.error = _error |
| 1423 |
self._pos = _startingpos |
| 1424 |
return self._numrange() |
| 1425 |
_status.status = _status.NORMAL |
| 1426 |
_status.pos = self._pos |
| 1427 |
_status.result = _result |
| 1428 |
_status.error = _error |
| 1429 |
return _status |
| 1430 |
except BacktrackException as _exc: |
| 1431 |
_status.pos = -1 |
| 1432 |
_status.result = None |
| 1433 |
_error = self._combine_errors(_error, _exc.error) |
| 1434 |
_status.error = _error |
| 1435 |
_status.status = _status.ERROR |
| 1436 |
raise BacktrackException(_error) |
| 1437 |
def clippednumrange(self): |
| 1438 |
return self._clippednumrange().result |
| 1439 |
def _clippednumrange(self): |
| 1440 |
_key = self._pos |
| 1441 |
_status = self._dict_clippednumrange.get(_key, None) |
| 1442 |
if _status is None: |
| 1443 |
_status = self._dict_clippednumrange[_key] = Status() |
| 1444 |
else: |
| 1445 |
_statusstatus = _status.status |
| 1446 |
if _statusstatus == _status.NORMAL: |
| 1447 |
self._pos = _status.pos |
| 1448 |
return _status |
| 1449 |
elif _statusstatus == _status.ERROR: |
| 1450 |
raise BacktrackException(_status.error) |
| 1451 |
elif (_statusstatus == _status.INPROGRESS or |
| 1452 |
_statusstatus == _status.LEFTRECURSION): |
| 1453 |
_status.status = _status.LEFTRECURSION |
| 1454 |
if _status.result is not None: |
| 1455 |
self._pos = _status.pos |
| 1456 |
return _status |
| 1457 |
else: |
| 1458 |
raise BacktrackException(None) |
| 1459 |
elif _statusstatus == _status.SOMESOLUTIONS: |
| 1460 |
_status.status = _status.INPROGRESS |
| 1461 |
_startingpos = self._pos |
| 1462 |
try: |
| 1463 |
_result = None |
| 1464 |
_error = None |
| 1465 |
_call_status = self._NUM() |
| 1466 |
_result = _call_status.result |
| 1467 |
_error = _call_status.error |
| 1468 |
n1 = _result |
| 1469 |
_result = self.__chars__(',') |
| 1470 |
_result = (n1) |
| 1471 |
if _status.status == _status.LEFTRECURSION: |
| 1472 |
if _status.result is not None: |
| 1473 |
if _status.pos >= self._pos: |
| 1474 |
_status.status = _status.NORMAL |
| 1475 |
self._pos = _status.pos |
| 1476 |
return _status |
| 1477 |
_status.pos = self._pos |
| 1478 |
_status.status = _status.SOMESOLUTIONS |
| 1479 |
_status.result = _result |
| 1480 |
_status.error = _error |
| 1481 |
self._pos = _startingpos |
| 1482 |
return self._clippednumrange() |
| 1483 |
_status.status = _status.NORMAL |
| 1484 |
_status.pos = self._pos |
| 1485 |
_status.result = _result |
| 1486 |
_status.error = _error |
| 1487 |
return _status |
| 1488 |
except BacktrackException as _exc: |
| 1489 |
_status.pos = -1 |
| 1490 |
_status.result = None |
| 1491 |
_error = self._combine_errors(_error, _exc.error) |
| 1492 |
_status.error = _error |
| 1493 |
_status.status = _status.ERROR |
| 1494 |
raise BacktrackException(_error) |
| 1495 |
def charclass(self): |
| 1496 |
return self._charclass().result |
| 1497 |
def _charclass(self): |
| 1498 |
_key = self._pos |
| 1499 |
_status = self._dict_charclass.get(_key, None) |
| 1500 |
if _status is None: |
| 1501 |
_status = self._dict_charclass[_key] = Status() |
| 1502 |
else: |
| 1503 |
_statusstatus = _status.status |
| 1504 |
if _statusstatus == _status.NORMAL: |
| 1505 |
self._pos = _status.pos |
| 1506 |
return _status |
| 1507 |
elif _statusstatus == _status.ERROR: |
| 1508 |
raise BacktrackException(_status.error) |
| 1509 |
_startingpos = self._pos |
| 1510 |
try: |
| 1511 |
_result = None |
| 1512 |
_error = None |
| 1513 |
while 1: |
| 1514 |
_choice0 = self._pos |
| 1515 |
try: |
| 1516 |
_result = self.__chars__('\\') |
| 1517 |
_result = self.__chars__('d') |
| 1518 |
_result = ( set([chr(c) for c in range(ord('0'), ord('9')+1)]) ) |
| 1519 |
break |
| 1520 |
except BacktrackException as _exc: |
| 1521 |
_error = _exc.error |
| 1522 |
self._pos = _choice0 |
| 1523 |
_choice1 = self._pos |
| 1524 |
try: |
| 1525 |
_result = self.__chars__('\\') |
| 1526 |
_result = self.__chars__('s') |
| 1527 |
_result = ( set(['\t', '\n', '\f', '\r', ' ']) ) |
| 1528 |
break |
| 1529 |
except BacktrackException as _exc: |
| 1530 |
_error = self._combine_errors(_error, _exc.error) |
| 1531 |
self._pos = _choice1 |
| 1532 |
_choice2 = self._pos |
| 1533 |
try: |
| 1534 |
_result = self.__chars__('\\') |
| 1535 |
_result = self.__chars__('w') |
| 1536 |
_result = ( 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)] + ['_']) ) |
| 1537 |
break |
| 1538 |
except BacktrackException as _exc: |
| 1539 |
_error = self._combine_errors(_error, _exc.error) |
| 1540 |
self._pos = _choice2 |
| 1541 |
_choice3 = self._pos |
| 1542 |
try: |
| 1543 |
_result = self.__chars__('\\') |
| 1544 |
_result = self.__chars__('D') |
| 1545 |
_result = ( set([chr(c) for c in range(256)]) - set([chr(c) for c in range(ord('0'), ord('9')+1)]) ) |
| 1546 |
break |
| 1547 |
except BacktrackException as _exc: |
| 1548 |
_error = self._combine_errors(_error, _exc.error) |
| 1549 |
self._pos = _choice3 |
| 1550 |
_choice4 = self._pos |
| 1551 |
try: |
| 1552 |
_result = self.__chars__('\\') |
| 1553 |
_result = self.__chars__('S') |
| 1554 |
_result = ( set([chr(c) for c in range(256)]) - set(['\t', '\n', '\f', '\r', ' ']) ) |
| 1555 |
break |
| 1556 |
except BacktrackException as _exc: |
| 1557 |
_error = self._combine_errors(_error, _exc.error) |
| 1558 |
self._pos = _choice4 |
| 1559 |
_choice5 = self._pos |
| 1560 |
try: |
| 1561 |
_result = self.__chars__('\\') |
| 1562 |
_result = self.__chars__('W') |
| 1563 |
_result = ( 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)] + ['_'])) |
| 1564 |
break |
| 1565 |
except BacktrackException as _exc: |
| 1566 |
_error = self._combine_errors(_error, _exc.error) |
| 1567 |
self._pos = _choice5 |
| 1568 |
raise BacktrackException(_error) |
| 1569 |
_result = self.__chars__('\\') |
| 1570 |
_result = self.__chars__('W') |
| 1571 |
_result = ( 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)] + ['_'])) |
| 1572 |
break |
| 1573 |
assert _status.status != _status.LEFTRECURSION |
| 1574 |
_status.status = _status.NORMAL |
| 1575 |
_status.pos = self._pos |
| 1576 |
_status.result = _result |
| 1577 |
_status.error = _error |
| 1578 |
return _status |
| 1579 |
except BacktrackException as _exc: |
| 1580 |
_status.pos = -1 |
| 1581 |
_status.result = None |
| 1582 |
_error = self._combine_errors(_error, _exc.error) |
| 1583 |
_status.error = _error |
| 1584 |
_status.status = _status.ERROR |
| 1585 |
raise BacktrackException(_error) |
| 1586 |
def NUM(self): |
| 1587 |
return self._NUM().result |
| 1588 |
def _NUM(self): |
| 1589 |
_key = self._pos |
| 1590 |
_status = self._dict_NUM.get(_key, None) |
| 1591 |
if _status is None: |
| 1592 |
_status = self._dict_NUM[_key] = Status() |
| 1593 |
else: |
| 1594 |
_statusstatus = _status.status |
| 1595 |
if _statusstatus == _status.NORMAL: |
| 1596 |
self._pos = _status.pos |
| 1597 |
return _status |
| 1598 |
elif _statusstatus == _status.ERROR: |
| 1599 |
raise BacktrackException(_status.error) |
| 1600 |
_startingpos = self._pos |
| 1601 |
try: |
| 1602 |
_result = None |
| 1603 |
_error = None |
| 1604 |
_result = self._regex1166214427() |
| 1605 |
c = _result |
| 1606 |
_result = (int(c)) |
| 1607 |
assert _status.status != _status.LEFTRECURSION |
| 1608 |
_status.status = _status.NORMAL |
| 1609 |
_status.pos = self._pos |
| 1610 |
_status.result = _result |
| 1611 |
_status.error = _error |
| 1612 |
return _status |
| 1613 |
except BacktrackException as _exc: |
| 1614 |
_status.pos = -1 |
| 1615 |
_status.result = None |
| 1616 |
_error = _exc.error |
| 1617 |
_status.error = _error |
| 1618 |
_status.status = _status.ERROR |
| 1619 |
raise BacktrackException(_error) |
| 1620 |
def __init__(self, inputstream): |
| 1621 |
self._dict_EOF = {} |
| 1622 |
self._dict_parse = {} |
| 1623 |
self._dict_regex = {} |
| 1624 |
self._dict_concatenation = {} |
| 1625 |
self._dict_repetition = {} |
| 1626 |
self._dict_primary = {} |
| 1627 |
self._dict_char = {} |
| 1628 |
self._dict_QUOTEDCHAR = {} |
| 1629 |
self._dict_CHAR = {} |
| 1630 |
self._dict_range = {} |
| 1631 |
self._dict_rangeinner = {} |
| 1632 |
self._dict_subrange = {} |
| 1633 |
self._dict_rangeelement = {} |
| 1634 |
self._dict_numrange = {} |
| 1635 |
self._dict_clippednumrange = {} |
| 1636 |
self._dict_charclass = {} |
| 1637 |
self._dict_NUM = {} |
| 1638 |
self._pos = 0 |
| 1639 |
self._inputstream = inputstream |
| 1640 |
def _regex2132196932(self): |
| 1641 |
_choice0 = self._pos |
| 1642 |
_runner = self._Runner(self._inputstream, self._pos) |
| 1643 |
_i = _runner.recognize_2132196932(self._pos) |
| 1644 |
if _runner.last_matched_state == -1: |
| 1645 |
self._pos = _choice0 |
| 1646 |
raise BacktrackException |
| 1647 |
_upto = _runner.last_matched_index + 1 |
| 1648 |
_pos = self._pos |
| 1649 |
assert _pos >= 0 |
| 1650 |
assert _upto >= 0 |
| 1651 |
_result = self._inputstream[_pos: _upto] |
| 1652 |
self._pos = _upto |
| 1653 |
return _result |
| 1654 |
def _regex1166214427(self): |
| 1655 |
_choice1 = self._pos |
| 1656 |
_runner = self._Runner(self._inputstream, self._pos) |
| 1657 |
_i = _runner.recognize_1166214427(self._pos) |
| 1658 |
if _runner.last_matched_state == -1: |
| 1659 |
self._pos = _choice1 |
| 1660 |
raise BacktrackException |
| 1661 |
_upto = _runner.last_matched_index + 1 |
| 1662 |
_pos = self._pos |
| 1663 |
assert _pos >= 0 |
| 1664 |
assert _upto >= 0 |
| 1665 |
_result = self._inputstream[_pos: _upto] |
| 1666 |
self._pos = _upto |
| 1667 |
return _result |
| 1668 |
def _regex1423754537(self): |
| 1669 |
_choice2 = self._pos |
| 1670 |
_runner = self._Runner(self._inputstream, self._pos) |
| 1671 |
_i = _runner.recognize_1423754537(self._pos) |
| 1672 |
if _runner.last_matched_state == -1: |
| 1673 |
self._pos = _choice2 |
| 1674 |
raise BacktrackException |
| 1675 |
_upto = _runner.last_matched_index + 1 |
| 1676 |
_pos = self._pos |
| 1677 |
assert _pos >= 0 |
| 1678 |
assert _upto >= 0 |
| 1679 |
_result = self._inputstream[_pos: _upto] |
| 1680 |
self._pos = _upto |
| 1681 |
return _result |
| 1682 |
class _Runner(object): |
| 1683 |
def __init__(self, text, pos): |
| 1684 |
self.text = text |
| 1685 |
self.pos = pos |
| 1686 |
self.last_matched_state = -1 |
| 1687 |
self.last_matched_index = -1 |
| 1688 |
self.state = -1 |
| 1689 |
def recognize_2132196932(runner, i): |
| 1690 |
|
| 1691 |
assert i >= 0 |
| 1692 |
input = runner.text |
| 1693 |
state = 0 |
| 1694 |
while 1: |
| 1695 |
if state == 0: |
| 1696 |
try: |
| 1697 |
char = input[i] |
| 1698 |
i += 1 |
| 1699 |
except IndexError: |
| 1700 |
runner.state = 0 |
| 1701 |
return ~i |
| 1702 |
if '}' <= char <= '\xff': |
| 1703 |
state = 1 |
| 1704 |
elif '\x00' <= char <= "'": |
| 1705 |
state = 1 |
| 1706 |
elif '_' <= char <= 'z': |
| 1707 |
state = 1 |
| 1708 |
elif '@' <= char <= 'Z': |
| 1709 |
state = 1 |
| 1710 |
elif '/' <= char <= '>': |
| 1711 |
state = 1 |
| 1712 |
elif char == ',': |
| 1713 |
state = 1 |
| 1714 |
else: |
| 1715 |
break |
| 1716 |
runner.last_matched_state = state |
| 1717 |
runner.last_matched_index = i - 1 |
| 1718 |
runner.state = state |
| 1719 |
if i == len(input): |
| 1720 |
return i |
| 1721 |
else: |
| 1722 |
return ~i |
| 1723 |
break |
| 1724 |
runner.state = state |
| 1725 |
return ~i |
| 1726 |
def recognize_1166214427(runner, i): |
| 1727 |
|
| 1728 |
assert i >= 0 |
| 1729 |
input = runner.text |
| 1730 |
state = 0 |
| 1731 |
while 1: |
| 1732 |
if state == 0: |
| 1733 |
try: |
| 1734 |
char = input[i] |
| 1735 |
i += 1 |
| 1736 |
except IndexError: |
| 1737 |
runner.state = 0 |
| 1738 |
return ~i |
| 1739 |
if char == '0': |
| 1740 |
state = 1 |
| 1741 |
elif '1' <= char <= '9': |
| 1742 |
state = 2 |
| 1743 |
else: |
| 1744 |
break |
| 1745 |
if state == 2: |
| 1746 |
runner.last_matched_index = i - 1 |
| 1747 |
runner.last_matched_state = state |
| 1748 |
try: |
| 1749 |
char = input[i] |
| 1750 |
i += 1 |
| 1751 |
except IndexError: |
| 1752 |
runner.state = 2 |
| 1753 |
return i |
| 1754 |
if '0' <= char <= '9': |
| 1755 |
state = 2 |
| 1756 |
continue |
| 1757 |
else: |
| 1758 |
break |
| 1759 |
runner.last_matched_state = state |
| 1760 |
runner.last_matched_index = i - 1 |
| 1761 |
runner.state = state |
| 1762 |
if i == len(input): |
| 1763 |
return i |
| 1764 |
else: |
| 1765 |
return ~i |
| 1766 |
break |
| 1767 |
runner.state = state |
| 1768 |
return ~i |
| 1769 |
def recognize_1423754537(runner, i): |
| 1770 |
|
| 1771 |
assert i >= 0 |
| 1772 |
input = runner.text |
| 1773 |
state = 0 |
| 1774 |
while 1: |
| 1775 |
if state == 0: |
| 1776 |
try: |
| 1777 |
char = input[i] |
| 1778 |
i += 1 |
| 1779 |
except IndexError: |
| 1780 |
runner.state = 0 |
| 1781 |
return ~i |
| 1782 |
if char == '\\': |
| 1783 |
state = 5 |
| 1784 |
else: |
| 1785 |
break |
| 1786 |
if state == 1: |
| 1787 |
runner.last_matched_index = i - 1 |
| 1788 |
runner.last_matched_state = state |
| 1789 |
try: |
| 1790 |
char = input[i] |
| 1791 |
i += 1 |
| 1792 |
except IndexError: |
| 1793 |
runner.state = 1 |
| 1794 |
return i |
| 1795 |
if '0' <= char <= '9': |
| 1796 |
state = 6 |
| 1797 |
elif 'A' <= char <= 'F': |
| 1798 |
state = 6 |
| 1799 |
elif 'a' <= char <= 'f': |
| 1800 |
state = 6 |
| 1801 |
else: |
| 1802 |
break |
| 1803 |
if state == 2: |
| 1804 |
runner.last_matched_index = i - 1 |
| 1805 |
runner.last_matched_state = state |
| 1806 |
try: |
| 1807 |
char = input[i] |
| 1808 |
i += 1 |
| 1809 |
except IndexError: |
| 1810 |
runner.state = 2 |
| 1811 |
return i |
| 1812 |
if '0' <= char <= '7': |
| 1813 |
state = 4 |
| 1814 |
else: |
| 1815 |
break |
| 1816 |
if state == 3: |
| 1817 |
runner.last_matched_index = i - 1 |
| 1818 |
runner.last_matched_state = state |
| 1819 |
try: |
| 1820 |
char = input[i] |
| 1821 |
i += 1 |
| 1822 |
except IndexError: |
| 1823 |
runner.state = 3 |
| 1824 |
return i |
| 1825 |
if '0' <= char <= '7': |
| 1826 |
state = 2 |
| 1827 |
continue |
| 1828 |
else: |
| 1829 |
break |
| 1830 |
if state == 5: |
| 1831 |
try: |
| 1832 |
char = input[i] |
| 1833 |
i += 1 |
| 1834 |
except IndexError: |
| 1835 |
runner.state = 5 |
| 1836 |
return ~i |
| 1837 |
if char == 'x': |
| 1838 |
state = 1 |
| 1839 |
continue |
| 1840 |
elif '4' <= char <= '7': |
| 1841 |
state = 2 |
| 1842 |
continue |
| 1843 |
elif '0' <= char <= '3': |
| 1844 |
state = 3 |
| 1845 |
continue |
| 1846 |
elif 'y' <= char <= '\xff': |
| 1847 |
state = 4 |
| 1848 |
elif '\x00' <= char <= '/': |
| 1849 |
state = 4 |
| 1850 |
elif 'E' <= char <= 'R': |
| 1851 |
state = 4 |
| 1852 |
elif 'e' <= char <= 'r': |
| 1853 |
state = 4 |
| 1854 |
elif '8' <= char <= 'C': |
| 1855 |
state = 4 |
| 1856 |
elif 'X' <= char <= 'b': |
| 1857 |
state = 4 |
| 1858 |
elif 'T' <= char <= 'V': |
| 1859 |
state = 4 |
| 1860 |
elif 't' <= char <= 'v': |
| 1861 |
state = 4 |
| 1862 |
elif char == 'c': |
| 1863 |
state = 7 |
| 1864 |
else: |
| 1865 |
break |
| 1866 |
if state == 6: |
| 1867 |
try: |
| 1868 |
char = input[i] |
| 1869 |
i += 1 |
| 1870 |
except IndexError: |
| 1871 |
runner.state = 6 |
| 1872 |
return ~i |
| 1873 |
if '0' <= char <= '9': |
| 1874 |
state = 4 |
| 1875 |
elif 'A' <= char <= 'F': |
| 1876 |
state = 4 |
| 1877 |
elif 'a' <= char <= 'f': |
| 1878 |
state = 4 |
| 1879 |
else: |
| 1880 |
break |
| 1881 |
if state == 7: |
| 1882 |
runner.last_matched_index = i - 1 |
| 1883 |
runner.last_matched_state = state |
| 1884 |
try: |
| 1885 |
char = input[i] |
| 1886 |
i += 1 |
| 1887 |
except IndexError: |
| 1888 |
runner.state = 7 |
| 1889 |
return i |
| 1890 |
if '\x00' <= char <= '\xff': |
| 1891 |
state = 4 |
| 1892 |
else: |
| 1893 |
break |
| 1894 |
runner.last_matched_state = state |
| 1895 |
runner.last_matched_index = i - 1 |
| 1896 |
runner.state = state |
| 1897 |
if i == len(input): |
| 1898 |
return i |
| 1899 |
else: |
| 1900 |
return ~i |
| 1901 |
break |
| 1902 |
runner.state = state |
| 1903 |
return ~i |
| 1904 |
class RegexParser(PackratParser): |
| 1905 |
def __init__(self, stream): |
| 1906 |
self.init_parser(stream) |
| 1907 |
forbidden = dict.fromkeys(("__weakref__ __doc__ " |
| 1908 |
"__dict__ __module__").split()) |
| 1909 |
initthere = "__init__" in RegexParser.__dict__ |
| 1910 |
for key, value in Parser.__dict__.iteritems(): |
| 1911 |
if key not in RegexParser.__dict__ and key not in forbidden: |
| 1912 |
setattr(RegexParser, key, value) |
| 1913 |
RegexParser.init_parser = Parser.__init__.im_func |
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
def test_generate(): |
| 1971 |
f = py.path.local(__file__) |
| 1972 |
oldcontent = f.read() |
| 1973 |
s = "# GENERATED CODE BETWEEN THIS LINE AND ITS OTHER OCCURENCE\n".lower() |
| 1974 |
pre, gen, after = oldcontent.split(s) |
| 1975 |
|
| 1976 |
from pypackrat import PyPackratSyntaxParser |
| 1977 |
from makepackrat import TreeOptimizer, ParserBuilder |
| 1978 |
p = PyPackratSyntaxParser(syntax) |
| 1979 |
t = p.file() |
| 1980 |
t = t.visit(TreeOptimizer()) |
| 1981 |
visitor = ParserBuilder() |
| 1982 |
t.visit(visitor) |
| 1983 |
code = visitor.get_code() |
| 1984 |
content = """\ |
| 1985 |
%s\ |
| 1986 |
%s |
| 1987 |
from rpython.rlib.parsing.pypackrat import PackratParser, Status |
| 1988 |
from rpython.rlib.parsing.pypackrat import BacktrackException |
| 1989 |
from rpython.rlib.parsing import regex |
| 1990 |
import operator |
| 1991 |
%s |
| 1992 |
class RegexParser(PackratParser): |
| 1993 |
def __init__(self, stream): |
| 1994 |
self.init_parser(stream) |
| 1995 |
forbidden = dict.fromkeys(("__weakref__ __doc__ " |
| 1996 |
"__dict__ __module__").split()) |
| 1997 |
initthere = "__init__" in RegexParser.__dict__ |
| 1998 |
for key, value in Parser.__dict__.iteritems(): |
| 1999 |
if key not in RegexParser.__dict__ and key not in forbidden: |
| 2000 |
setattr(RegexParser, key, value) |
| 2001 |
RegexParser.init_parser = Parser.__init__.im_func |
| 2002 |
%s |
| 2003 |
%s\ |
| 2004 |
""" % (pre, s, code, s, after) |
| 2005 |
print(content) |
| 2006 |
f.write(content) |