Manual:Debugging:Logging
id:noritsugu:20090726:parser のコードを使って
>>> from lepl import * >>> symbol = Token('[^0-9a-zA-Z \t\r\n]') >>> value = Token(UnsignedFloat()) >>> negfloat = lambda x: -float(x) >>> number = Or(value >> float, ... ~symbol('-') & value >> negfloat) >>> group2, group3 = Delayed(), Delayed() >>> parens = symbol('(') & group3 & symbol(')') >>> group1 = parens | number >>> mul = group2 & symbol('*') & group2 > Node >>> div = group2 & symbol('/') & group2 > Node >>> group2 += mul | div | group1 >>> add = group3 & symbol('+') & group3 > Node >>> sub = group3 & symbol('-') & group3 > Node >>> group3 += add | sub | group2 >>> ast = group3.parse('1+2*(3-4)+5/6+7')[0] >>> len(list(group3.match('1+2*(3-4)+5/6+7'))) No handlers could be found for logger "lepl.memo.PerCallCache" 12 >>> from logging import basicConfig, DEBUG >>> basicConfig(level=DEBUG) >>> len(list(group3.match('1+2*(3-4)+5/6+7'))) DEBUG:lepl.regexp.rewriters.make_clone:Any: cloned [0-9] DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.make_clone:DFS: cloned [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.matchers.DepthFirst'>,[0-9]([0-9])*,True,True DEBUG:lepl.regexp.rewriters.make_clone:Transform: cloning [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.make_clone:Transform: OK DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9]([0-9])*,True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9]([0-9])*,True,False DEBUG:lepl.regexp.rewriters.make_clone:DFS: cloned ([0-9]([0-9])*|) DEBUG:lepl.regexp.rewriters.make_clone:Any: cloned \. DEBUG:lepl.regexp.rewriters.make_clone:Any: cloned [0-9] DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.make_clone:DFS: cloned [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.matchers.DepthFirst'>,[0-9]([0-9])*,True,True DEBUG:lepl.regexp.rewriters.make_clone:Transform: cloning [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.make_clone:Transform: OK DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,([0-9]([0-9])*|),True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,\.,True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9]([0-9])*,True,False DEBUG:lepl.regexp.rewriters.make_clone:And: cloning ([0-9]([0-9])*|)\.[0-9]([0-9])* DEBUG:lepl.regexp.rewriters.make_clone:And: OK DEBUG:lepl.regexp.rewriters.make_clone:Any: cloned [0-9] DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9],True,False DEBUG:lepl.regexp.rewriters.make_clone:DFS: cloned [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.matchers.DepthFirst'>,[0-9]([0-9])*,True,True DEBUG:lepl.regexp.rewriters.make_clone:Transform: cloning [0-9]([0-9])* DEBUG:lepl.regexp.rewriters.make_clone:Transform: OK DEBUG:lepl.regexp.rewriters.make_clone:Any: cloned \. DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,\.,True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,\.,True,False DEBUG:lepl.regexp.rewriters.make_clone:DFS: cloned (\.|) DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9]([0-9])*,True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,(\.|),True,False DEBUG:lepl.regexp.rewriters.make_clone:And: cloning [0-9]([0-9])*(\.|) DEBUG:lepl.regexp.rewriters.make_clone:And: OK DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,([0-9]([0-9])*|)\.[0-9]([0-9])*,True,False DEBUG:lepl.regexp.rewriters.RegexpContainer:unpacking: <class 'lepl.regexp.matchers.NfaRegexp'>,[0-9]([0-9])*(\.|),True,False DEBUG:lepl.regexp.rewriters.make_clone:Or: cloned (([0-9]([0-9])*|)\.[0-9]([0-9])*|[0-9]([0-9])*(\.|)) DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '1' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '+' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '2' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '*' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '(' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '3' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '-' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '4' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] ')' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '+' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '5' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '/' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '6' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [0] '+' DEBUG:lepl.lexer.stream.lexed_simple_stream:Token: [1] '7' WARNING:lepl.memo.PerCallCache:A view completed before the cache was complete: Or(Line([([1], '1'), ([0], '+'), ([1], '2'), ([0], '*'), ([0], '('), ([1], '3'), ([0], '-'), ([1], '4'), ([0], ')'), ([0], '+'), ([1], '5'), ([0], '/'), ([1], '6'), ([0], '+'), ([1], '7')])[5:]). This typically means that the grammar contains a matcher that does not consume input within a loop and is usually an error. WARNING:lepl.memo.PerCallCache:A view completed before the cache was complete: Or(Line([([1], '1'), ([0], '+'), ([1], '2'), ([0], '*'), ([0], '('), ([1], '3'), ([0], '-'), ([1], '4'), ([0], ')'), ([0], '+'), ([1], '5'), ([0], '/'), ([1], '6'), ([0], '+'), ([1], '7')])[2:]). This typically means that the grammar contains a matcher that does not consume input within a loop and is usually an error. 12 >>> SignedFloat().parse('123') INFO:lepl.lexer.rewriters.lexer_rewriter:Lexer rewriter used, but no tokens found. ['123'] >>> add = SignedFloat() & Literal('+') & SignedFloat() DEBUG:lepl.context.Global:Getting operators/<class 'lepl.operators.DefaultNamespace'> DEBUG:lepl.context.Global:Getting operators/<class 'lepl.operators.DefaultNamespace'> >>> add.parse('12+30') INFO:lepl.lexer.rewriters.lexer_rewriter:Lexer rewriter used, but no tokens found. ['12', '+', '30']