Package lepl :: Package lexer :: Package lines :: Package _test :: Module left_bug
[hide private]
[frames] | no frames]

Source Code for Module lepl.lexer.lines._test.left_bug

  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  See http://groups.google.com/group/lepl/browse_thread/thread/79e39e03a03718cc?hl=en_US 
 32   
 33  The different tree structures seen here seem to be related to the how the 
 34  left-recursive memoisation fails.  In the case without lexer the string is 
 35  shorter, which causes failure earlier.  I am not at all sure about this... 
 36  ''' 
 37   
 38  from unittest import TestCase 
 39  from logging import basicConfig, DEBUG 
 40   
 41  from lepl import * 
 42  from lepl._test.base import assert_str 
 43   
 44   
45 -class LeftBugTest(TestCase):
46
47 - def test_right_no_lexer(self):
48 #basicConfig(level=DEBUG) 49 word = Any() 50 expr1 = Delayed() 51 call = (expr1 & word) > List 52 expr1 += (call | Empty() | word) 53 program = expr1 & Eos() 54 program.config.trace_stack().auto_memoize() 55 parser = program.get_parse() 56 print(parser.matcher.tree()) 57 parsed = parser("abc") 58 assert_str(parsed[0], 59 """List 60 +- List 61 | +- List 62 | | `- 'a' 63 | `- 'b' 64 `- 'c'""")
65
66 - def test_right(self):
67 #basicConfig(level=DEBUG) 68 #CLine = ContinuedBLineFactory(Token(r'\\')) 69 word = Token("[A-Za-z_][A-Za-z0-9_]*") 70 expr1 = Delayed() 71 call = (expr1 & word) > List 72 expr1 += (call | Empty() | word) 73 program = Trace(expr1 & Eos()) 74 program.config.trace_stack().auto_memoize() 75 parser = program.get_parse() 76 #print(parser.matcher.tree()) 77 parsed = parser("a b c") 78 assert_str(parsed[0], 79 """List 80 +- List 81 | +- List 82 | | `- 'a' 83 | `- 'b' 84 `- 'c'""")
85
86 - def test_left(self):
87 CLine = ContinuedLineFactory(r'\\') 88 expr0 = Token("[A-Za-z_][A-Za-z0-9_]*") 89 expr1 = Delayed() 90 call = (expr1 & expr0) > List # Deliberately not expr0 & expr1 91 expr1 += (call | Empty () | expr0) 92 program = (CLine(expr1) & Eos()) 93 program.config.lines(block_policy=explicit).auto_memoize() 94 parsed = program.parse("a b c") 95 assert_str(parsed[0], 96 """List 97 +- List 98 | +- List 99 | | `- 'a' 100 | `- 'b' 101 `- 'c'""")
102