Package: python-yappy
Version: 1.8-3
Severity: important
Tags: patch
Hi,
When given any input containing whitespace characters, the parser fails with the
following exception:
yappy.parser.LRParserError: Error in LR: (0,) not found
This also happens whenever I try to create a parser using a grammar string,
giving the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "demo.py", line 244, in __init__
Yappy.__init__(self,tokenize,grammar,table,no_table)
File "/var/lib/python-support/python2.4/yappy/parser.py", line 1736, in
__init__
grammar = self.parse_grammar(grammar,{'locals':locals()},args)
File "/var/lib/python-support/python2.4/yappy/parser.py", line 1530, in
parse_grammar
self.pg.input(st,context)
File "/var/lib/python-support/python2.4/yappy/parser.py", line 1770, in input
return self.parsing(self.tokens,self.context)
File "/var/lib/python-support/python2.4/yappy/parser.py", line 1503, in
parsing
raise LRParserError(s,a)
yappy.parser.LRParserError: Error in LR: (0,) not found
I think this is caused by a bug in the Lexer class. According to the
documentation, when funct is an empty string it should not output a
token. However, it outputs an empty token:
>>> from yappy.parser import *
>>> rules = [("\s+", '') , ("[A-Z]+", lambda x: ("id", x))]
>>> lex = Lexer(rules)
>>> lex.scan("AAA BB C")
[('id', 'AAA'), ('', ' '), ('id', 'BB'), ('', ' '), ('id', 'C')]
^^ ^^
When the parser encounters these empty tokens and can't find a rule for
them, it fails. This is easily corrected by fixing Lexer so that if
funct is an empty string, it doesn't output anything. I've done this
using the patch below and it seems to fix the problem.
Thanks,
Stephen Dann
diff -u yappy-1.8.orig/parser.py yappy-1.8/parser.py
--- yappy-1.8.orig/parser.py 2008-03-02 15:04:14.000000000 +0000
+++ yappy-1.8/parser.py 2008-03-02 15:04:58.000000000 +0000
@@ -143,9 +143,7 @@
else:
if m.start() != 0:
st1.append(s1[0:m.start()])
- if fun == "":
- st1.append(("",s1[m.start():m.end()]))
- else:
+ if fun != "":
st1.append(apply(fun,[s1[m.start():m.end()]]))
if m.end() == len(s1):
break
-- System Information:
Debian Release: lenny/sid
APT prefers testing
APT policy: (500, 'testing'), (450, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.24.3 (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages python-yappy depends on:
ii python-support 0.7.6 automated rebuilding support for p
python-yappy recommends no packages.
-- no debconf information
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]