Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pybison
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
pybison
Commits
b200b18e
Commit
b200b18e
authored
Dec 08, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved error reporting facilities.
parent
260359e3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
20 deletions
+26
-20
src/pyrex/bison_.pyx
src/pyrex/bison_.pyx
+7
-7
src/python/bison.py
src/python/bison.py
+19
-13
No files found.
src/pyrex/bison_.pyx
View file @
b200b18e
...
@@ -278,7 +278,7 @@ cdef class ParserEngine:
...
@@ -278,7 +278,7 @@ cdef class ParserEngine:
#s = s + ' if ($$ && $$ != Py_None && PyObject_HasAttrString($$, "_pyBisonError"))\n'
#s = s + ' if ($$ && $$ != Py_None && PyObject_HasAttrString($$, "_pyBisonError"))\n'
#s = s + ' {\n'
#s = s + ' {\n'
#s = s + '
yyerror(PyString_AsString(PyObject_GetAttrString(py_parser, "last
error")));\n'
#s = s + '
yyerror(PyString_AsString(PyObject_GetAttrString(py_parser, "last_
error")));\n'
#s = s + ' Py_INCREF(Py_None);\n'
#s = s + ' Py_INCREF(Py_None);\n'
#s = s + ' YYERROR;\n'
#s = s + ' YYERROR;\n'
#s = s + ' }\n'
#s = s + ' }\n'
...
@@ -287,11 +287,11 @@ cdef class ParserEngine:
...
@@ -287,11 +287,11 @@ cdef class ParserEngine:
s
+=
' {
\
n
'
s
+=
' {
\
n
'
s
+=
' if (PyObject_HasAttrString($$, "_pyBisonError"))
\
n
'
s
+=
' if (PyObject_HasAttrString($$, "_pyBisonError"))
\
n
'
s
+=
' {
\
n
'
s
+=
' {
\
n
'
s
+=
' //PyObject* last
error = PyObject_GetAttrString(py_parser, "last
error");
\
n
'
s
+=
' //PyObject* last
_error = PyObject_GetAttrString(py_parser, "last_
error");
\
n
'
s
+=
' //if (last
error && PyString_Check(last
error))
\
n
'
s
+=
' //if (last
_error && PyString_Check(last_
error))
\
n
'
s
+=
' // yyerror(PyString_AsString(lasterror));
\
n
'
s
+=
' // yyerror(PyString_AsString(last
_
error));
\
n
'
s
+=
' //else
\
n
'
s
+=
' //else
\
n
'
s
+=
' // yyerror("No
\
\
"lasterror
\
\
" attribute set in BisonError or not a string");
\
n
'
s
+=
' // yyerror("No
\
\
"last
_
error
\
\
" attribute set in BisonError or not a string");
\
n
'
s
+=
' Py_INCREF(Py_None);
\
n
'
s
+=
' Py_INCREF(Py_None);
\
n
'
s
+=
' YYERROR;
\
n
'
s
+=
' YYERROR;
\
n
'
s
+=
' }
\
n
'
s
+=
' }
\
n
'
...
@@ -459,7 +459,7 @@ cdef class ParserEngine:
...
@@ -459,7 +459,7 @@ cdef class ParserEngine:
action = action + "
,
\
n
".join(args) + "
\
n
);
\
n
"
action = action + "
,
\
n
".join(args) + "
\
n
);
\
n
"
if 'error' in option:
if 'error' in option:
action = action + "
PyObject_SetAttrString
(
py_parser
,
\
"last
error
\
"
, Py_None);
\
n
"
action = action + "
PyObject_SetAttrString
(
py_parser
,
\
"last_
error
\
"
, Py_None);
\
n
"
action
=
action
+
" Py_INCREF(Py_None);
\
n
"
action
=
action
+
" Py_INCREF(Py_None);
\
n
"
action
=
action
+
" yyclearin;
\
n
"
action
=
action
+
" yyclearin;
\
n
"
...
@@ -504,7 +504,7 @@ cdef class ParserEngine:
...
@@ -504,7 +504,7 @@ cdef class ParserEngine:
' PyTuple_SetItem(args, 1, PyString_FromString(mesg));'
,
' PyTuple_SetItem(args, 1, PyString_FromString(mesg));'
,
' PyTuple_SetItem(args, 2, PyString_FromString(yytext));'
,
' PyTuple_SetItem(args, 2, PyString_FromString(yytext));'
,
''
,
''
,
' ret = PyObject_SetAttrString((PyObject *)py_parser, "lasterror", args);'
,
' ret = PyObject_SetAttrString((PyObject *)py_parser, "last
_
error", args);'
,
' //printf("PyObject_SetAttrString: %d
\
\
n", ret);'
,
' //printf("PyObject_SetAttrString: %d
\
\
n", ret);'
,
''
,
''
,
' //printf("line %d: %s before %s
\
\
n", yylineno+1, mesg, yytext);'
,
' //printf("line %d: %s before %s
\
\
n", yylineno+1, mesg, yytext);'
,
...
...
src/python/bison.py
View file @
b200b18e
...
@@ -45,8 +45,9 @@ class BisonError(object):
...
@@ -45,8 +45,9 @@ class BisonError(object):
"""
"""
_pyBisonError
=
1
_pyBisonError
=
1
def
__init__
(
self
,
value
=
'syntax error'
):
def
__init__
(
self
,
error
,
traceback_info
):
self
.
value
=
value
self
.
value
=
error
self
.
traceback_info
=
traceback_info
class
BisonException
(
Exception
):
class
BisonException
(
Exception
):
...
@@ -244,7 +245,7 @@ class BisonParser(object):
...
@@ -244,7 +245,7 @@ class BisonParser(object):
last
=
None
# last parsed target, top of parse tree
last
=
None
# last parsed target, top of parse tree
lasterror
=
None
# gets set if there was an error
last
_
error
=
None
# gets set if there was an error
keepfiles
=
0
# set to 1 to keep temporary engine build files
keepfiles
=
0
# set to 1 to keep temporary engine build files
...
@@ -328,9 +329,9 @@ class BisonParser(object):
...
@@ -328,9 +329,9 @@ class BisonParser(object):
try
:
try
:
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
names
=
names
,
values
=
values
)
except
:
except
Exception
as
e
:
#traceback.print_exception(*sys.exc_info())
#traceback.print_exception(*sys.exc_info())
return
self
.
error
(
sys
.
exc_info
())
return
self
.
error
(
e
,
sys
.
exc_info
())
# raise
# raise
#if self.verbose:
#if self.verbose:
...
@@ -342,7 +343,7 @@ class BisonParser(object):
...
@@ -342,7 +343,7 @@ class BisonParser(object):
self
.
last
=
BisonNode
(
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
self
.
last
=
BisonNode
(
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
# reset any resulting errors (assume they've been handled)
# reset any resulting errors (assume they've been handled)
#self.lasterror = None
#self.last
_
error = None
# assumedly the last thing parsed is at the top of the tree
# assumedly the last thing parsed is at the top of the tree
return
self
.
last
return
self
.
last
...
@@ -395,11 +396,11 @@ class BisonParser(object):
...
@@ -395,11 +396,11 @@ class BisonParser(object):
while
not
self
.
file
.
closed
:
while
not
self
.
file
.
closed
:
# do the parsing job, spew if error
# do the parsing job, spew if error
self
.
last
=
None
self
.
last
=
None
self
.
lasterror
=
None
self
.
last
_
error
=
None
self
.
engine
.
runEngine
(
debug
)
self
.
engine
.
runEngine
(
debug
)
if
self
.
lasterror
:
if
self
.
last
_
error
:
self
.
report_last_error
(
filename
,
self
.
lasterror
)
self
.
report_last_error
(
filename
,
self
.
last
_
error
)
if
self
.
verbose
:
if
self
.
verbose
:
print
'Parser.run: back from engine'
print
'Parser.run: back from engine'
...
@@ -446,13 +447,14 @@ class BisonParser(object):
...
@@ -446,13 +447,14 @@ class BisonParser(object):
print
'Parser: line %s: syntax error "%s" before "%s"'
\
print
'Parser: line %s: syntax error "%s" before "%s"'
\
%
(
linenum
,
msg
,
tok
)
%
(
linenum
,
msg
,
tok
)
def
error
(
self
,
value
):
def
error
(
self
,
exception
,
traceback_info
):
"""
"""
Return the result of this method from a handler to notify a syntax error
Return the result of this method from a handler to notify a syntax error
"""
"""
# TODO: should this function be removed?
# TODO: should this function be removed?
self
.
lasterror
=
value
self
.
last_error
=
BisonError
(
exception
,
traceback_info
)
return
BisonError
(
value
)
return
self
.
last_error
def
exception
(
self
,
exception
):
def
exception
(
self
,
exception
):
# TODO: should this function be removed?
# TODO: should this function be removed?
...
@@ -476,7 +478,11 @@ class BisonParser(object):
...
@@ -476,7 +478,11 @@ class BisonParser(object):
print
>>
sys
.
stderr
,
msg
print
>>
sys
.
stderr
,
msg
else
:
else
:
traceback
.
print_exception
(
*
error
)
print
error
if
not
self
.
interactive
:
raise
error
[
3
]
traceback
.
print_exception
(
*
error
[:
2
])
def
toxml
(
self
):
def
toxml
(
self
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment