From 61c5b7db71667c7801ef2be2c82aaad888ec8e78 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Fri, 23 Oct 2015 15:21:50 +0200 Subject: Fix a parser bug --- prolog/parser.py | 6 +++--- prolog/util.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'prolog') diff --git a/prolog/parser.py b/prolog/parser.py index 5b5c325..c9f4d86 100644 --- a/prolog/parser.py +++ b/prolog/parser.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from nltk import ParentedTree as Tree +from nltk import Tree import ply.yacc as yacc from .lexer import operators, tokens from .util import Token @@ -165,10 +165,10 @@ def p_list_empty(p): p[0] = Tree('list', [make_token(p, 1), make_token(p, 2)]) def p_list(p): 'list : LBRACKET args RBRACKET' - p[0] = Tree('list', [make_token(p, 1)] + p[2] + [make_token(p, 3)]) + p[0] = Tree('list', [make_token(p, 1)] + list(p[2]) + [make_token(p, 3)]) def p_list_tail(p): 'list : LBRACKET args PIPE term RBRACKET' - p[0] = Tree('list', [make_token(p, 1)] + p[2] + [make_token(p, 3), p[4], make_token(p, 5)]) + p[0] = Tree('list', [make_token(p, 1)] + list(p[2]) + [make_token(p, 3), p[4], make_token(p, 5)]) def p_functor(p): 'functor : NAME' diff --git a/prolog/util.py b/prolog/util.py index a9fe944..ba48732 100644 --- a/prolog/util.py +++ b/prolog/util.py @@ -57,7 +57,7 @@ from .parser import parser def parse(code): try: return parser.parse(code) - except: + except SyntaxError: return None # Return a list of tokens in [text]. -- cgit v1.2.1