| Home | Trees | Indices | Help |
|---|
|
|
1 2 # The contents of this file are subject to the Mozilla Public License 3 # (MPL) Version 1.1 (the "License"); you may not use this file except 4 # in compliance with the License. You may obtain a copy of the License 5 # at http://www.mozilla.org/MPL/ 6 # 7 # Software distributed under the License is distributed on an "AS IS" 8 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 # the License for the specific language governing rights and 10 # limitations under the License. 11 # 12 # The Original Code is LEPL (http://www.acooke.org/lepl) 13 # The Initial Developer of the Original Code is Andrew Cooke. 14 # Portions created by the Initial Developer are Copyright (C) 2009-2010 15 # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 16 # 17 # Alternatively, the contents of this file may be used under the terms 18 # of the LGPL license (the GNU Lesser General Public License, 19 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 20 # of the LGPL License are applicable instead of those above. 21 # 22 # If you wish to allow use of your version of this file only under the 23 # terms of the LGPL License and not to allow others to use your version 24 # of this file under the MPL, indicate your decision by deleting the 25 # provisions above and replace them with the notice and other provisions 26 # required by the LGPL License. If you do not delete the provisions 27 # above, a recipient may use your version of this file under either the 28 # MPL or the LGPL License. 29 30 ''' 31 Tests for a weird bug when writing the float (rational at the time) matcher. 32 33 This came down to optional entries being mapped in NFA as empty transitions 34 from a single node. If multiple choices were from the same node the empty 35 transition order was incorrect (it's ordered by node number, and the node 36 for the empty transition was created after other nodes, intead of before). 37 38 The fix used was to change the node creation order. Other nodes appear to 39 be created correctly. However, it would be better in the longer term, I 40 suspect, to use an ordered dict or similar to store the empty transitions 41 so that the numbering is not needed for order. 42 ''' 43 44 #from logging import basicConfig, DEBUG 45 46 from lepl.matchers.derived import UnsignedFloat, SignedInteger, Join 47 from lepl.matchers.combine import Or 48 from lepl.matchers.core import Any 49 from lepl._test.base import BaseTest 50 51 52 # pylint: disable-msg=C0103, C0111, C0301, W0702, C0324, C0102, C0321, W0141, R0201, R0913, R0901, R0904 53 # (dude this is just a test) 54 55 #basicConfig(level=DEBUG) 56 5759 63 6684 #print(m.matcher) 85 #print(m.matcher.regexp) 86 87 # (?: 88 # (?: 89 # (?:[0-9] 90 # (?:[0-9])* 91 # )? 92 # \.[0-9](?:[0-9])* 93 # | 94 # [0-9](?:[0-9])*(?:\.)? 95 # ) 96 # [Ee](?:[\+\-])?[0-9](?:[0-9])* 97 # | 98 # (?: 99 # (?: 100 # [0-9](?:[0-9])* 101 # )?\.[0-9](?:[0-9])* 102 # | 103 # [0-9](?:[0-9])*\. 104 # ) 105 # ) 106 #DEBUG:lepl.regexp.core.Compiler:compiling to nfa: (?P<label>(?:(?:(?:[0-9](?:[0-9])*)?\.[0-9](?:[0-9])*|[0-9](?:[0-9])*(?:\.)?)[Ee](?:[\+\-])?[0-9](?:[0-9])*|(?:[0-9](?:[0-9])*)?\.[0-9](?:[0-9])*|[0-9](?:[0-9])*\.)) 107 #DEBUG:lepl.regexp.core.Compiler:nfa graph: 0: [0-9]->5, 10, 4, 18; 1; 2(label): 1; 3: [Ee]->14; 4: \.->7; 5: 6; 6: [0-9]->6, 4; 7: [0-9]->8; 8: 9; 9: [0-9]->9, 3; 10: [0-9]->12; 11: \.->3, 3; 12: 13; 13: [0-9]->13, 11; 14: [\+\-]->15, 15; 15: [0-9]->16; 16: 17; 17: [0-9]->17, 2; 18: [0-9]->20, 25, 19; 19: \.->22; 20: 21; 21: [0-9]->21, 19; 22: [0-9]->23; 23: 24; 24: [0-9]->24, 2; 25: [0-9]->27; 26: \.->2; 27: 28; 28: [0-9]->28, 26 108 # 0: [0-9]->5, 10, 4, 18; 109 # 1; 110 # 2(label): 1; 111 # 3: [Ee]->14; 112 # 4: \.->7; 113 # 5: 6; 114 # 6: [0-9]->6, 4; 115 # 7: [0-9]->8; 116 # 8: 9; 117 # 9: [0-9]->9, 3; 118 # 10: [0-9]->12; 119 # 11: \.->3, 3; 120 # 12: 13; 121 # 13: [0-9]->13, 11; 122 # 14: [\+\-]->15, 15; 123 # 15: [0-9]->16; 124 # 16: 17; 125 # 17: [0-9]->17, 2; 126 # 18: [0-9]->20, 25, 19; 127 # 19: \.->22; 128 # 20: 21; 129 # 21: [0-9]->21, 19; 130 # 22: [0-9]->23; 131 # 23: 24; 132 # 24: [0-9]->24, 2; 133 # 25: [0-9]->27; 134 # 26: \.->2; 135 # 27: 28; 136 # 28: [0-9]->28, 26 13768 first = Join(UnsignedFloat(), Any('eE'), SignedInteger()) 69 second = UnsignedFloat() 70 all = Or(first, second) 71 all.config.default() # wrong order 72 #all.config.compile_to_dfa() # gives 1.e3 only 73 #all.config.compile_to_nfa() # wrong order 74 #all.config.no_compile_to_regexp() # ok 75 #all.config.clear() # ok 76 self.assert_direct('1.e3', all, [['1.e3'], ['1.']])7779 first = Join(UnsignedFloat(), Any('eE'), SignedInteger()) 80 second = UnsignedFloat() 81 all = Or(first, second) 82 all.config.clear().compile_to_nfa() 83 m = all.get_parse()
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Jun 9 21:51:00 2012 | http://epydoc.sourceforge.net |