Manual:Debugging:Deepest Matches

まんま

>>> from lepl import *
>>> from lepl.matchers import *
>>> from logging import basicConfig, INFO
>>> basicConfig(level=INFO)
>>> name    = Word()              >= 'name'
>>> phone   = Integer()           >= 'phone'
>>> line    = name / ',' / phone  >= make_dict
>>> matcher = line[0:,~Newline()]
>>> matcher.parse_string('andrew, 3333253\n bob, 12345',
...                      Configuration(monitors=[RecordDeepest()]))
WARNING:lepl.parser.trampoline:Exception at epoch 159
WARNING:lepl.parser.trampoline:Top of stack: DepthFirst(Line('andrew, 3333253\n')[0:])
WARNING:lepl.parser.trampoline:Traceback (most recent call last):
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 173, in trampoline
    value = stack[-1].send(value)
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 75, in send
    return self.__generator.send(value)
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/matchers.py", line 403, in _match
    acc2 = acc1 + value
TypeError: can only concatenate list (not "dict") to list

WARNING:lepl.parser.trampoline:Stack: DepthFirst
INFO:lepl.trace._RecordDeepest:
Up to 6 matches before and including longest match:
00137 3333253
      1.8   (0008) 008       next(Any('0123456789')(Line('andrew, 3333253\n')[8:])) -> (['3'], Line('andrew, 3333253\n')[9:])
00139 333253
       1.9   (0009) 008       next(Any('0123456789')(Line('andrew, 3333253\n')[9:])) -> (['3'], Line('andrew, 3333253\n')[10:])
00141 33253
        1.10  (0010) 008      next(Any('0123456789')(Line('andrew, 3333253\n')[10:])) -> (['3'], Line('andrew, 3333253\n')[11:])
00143 3253
         1.11  (0011) 008      next(Any('0123456789')(Line('andrew, 3333253\n')[11:])) -> (['3'], Line('andrew, 3333253\n')[12:])
00145 253
          1.12  (0012) 008      next(Any('0123456789')(Line('andrew, 3333253\n')[12:])) -> (['2'], Line('andrew, 3333253\n')[13:])
00147 53
           1.13  (0013) 008      next(Any('0123456789')(Line('andrew, 3333253\n')[13:])) -> (['5'], Line('andrew, 3333253\n')[14:])
Up to 2 failures following longest match:
00151
             1.15  (0015) 008      next(Any('0123456789')(Line('andrew, 3333253\n')[15:])) -> stop
Up to 2 successful matches following longest match:
00152 3333253
      1.8   (0008) 009            stop -> DepthFirst(Line('andrew, 3333253\n')[8:]) -> (['3', '3', '3', '3', '2', '5', '3'], Line('andrew, 3333253\n')[15:])
00153 3333253
      1.8   (0008) 008 (['3', '3', '3', '3', '2', '5', '3'], Line('andrew, 3333253\n')[15:]) -> Transform(Add) -> (['3333253'], Line('andrew, 3333253\n')[15:])

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/matchers.py", line 180, in parse_string
    return self.string_parser(config)(string)
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 249, in single
    return next(matcher(arg))[0]
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 182, in trampoline
    raise value
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 173, in trampoline
    value = stack[-1].send(value)
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/parser.py", line 75, in send
    return self.__generator.send(value)
  File "/usr/local/Python-3.1/lib/python3.1/site-packages/lepl/matchers.py", line 403, in _match
    acc2 = acc1 + value
TypeError: can only concatenate list (not "dict") to list
  • あれ?関係ないところでエラーに???
  • 「from lepl.matchers import *」が「from lepl.match import *」に


id:noritsugu:20090802:parser のコードを使って
「=>」が「>」なのが大きな違い???

>>> from lepl import *
>>> from lepl.matchers import *
>>> from logging import basicConfig, INFO
>>> basicConfig(level=INFO)
>>> spaces  = Space()[0:]
>>> name    = Word()              > 'name'
>>> phone   = Integer()           > 'phone'
>>> line    = name / ',' / phone  > make_dict
>>> newline = spaces & Newline() & spaces
>>> matcher = line[0:,~newline]
>>> matcher.parse_string('andrew, 3333253\n bob, 12345', Configuration(monitors=[RecordDeepest()]))
INFO:lepl.trace._RecordDeepest:
Up to 6 matches before and including longest match:
00306 12345         2.6   (0022) 007                (['12345'], Line(None)[0:]) -> Transform(Add) -> (['12345'], Line(None)[0:])
00307 12345         2.6   (0022) 006              (['12345'], Line(None)[0:]) -> Transform(Apply) -> ([('phone', '12345')], Line(None)[0:])
00308 bob, 12345    2.1   (0017) 005                ([('phone', '12345')], Line(None)[0:]) -> And -> ([('name', 'bob'), ',', ' ', ('phone', '12345')], Line(None)[0:])
00309 bob, 12345    2.1   (0017) 004 ([('name', 'bob'), ',', ' ', ('phone', '12345')], Line(None)[0:]) -> Transform(Apply) -> ([{'phone': '12345', 'name': 'bob'}], Line(None)[0:])
00310
             1.15  (0015) 003 ([{'phone': '12345', 'name': 'bob'}], Line(None)[0:]) -> And -> ([{'phone': '12345', 'name': 'bob'}], Line(None)[0:])
00317               eof   (-001) 006                             next(Any(' \t')(Line(None)[0:])) -> stop
Up to 2 failures following longest match:
00321               eof   (-001) 006                          next(Literal('\n')(Line(None)[0:])) -> stop
00323               eof   (-001) 006                        next(Literal('\r\n')(Line(None)[0:])) -> stop
Up to 2 successful matches following longest match:
00331 andrew, 3333253
   1.0   (0000) 002            stop -> DepthFirst(Line('andrew, 3333253\n')[0:]) -> ([{'phone': '3333253', 'name': 'andrew'}, {'phone': '12345', 'name': 'bob'}], Line(None)[0:])

[{'phone': '3333253', 'name': 'andrew'}, {'phone': '12345', 'name': 'bob'}]