PageRenderTime 8ms CodeModel.GetById 3ms app.highlight 82ms RepoModel.GetById 1ms app.codeStats 1ms

/jaspyon/rlib/parsing/regexparse.py

https://bitbucket.org/santagada/jaspyon
Python | 2004 lines | 1993 code | 4 blank | 7 comment | 11 complexity | 31fa14b51b3b976826549006db2bd5a2 MD5 | raw file

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

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

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