Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pybison
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
pybison
Commits
0bdb2622
Commit
0bdb2622
authored
13 years ago
by
Sander Mathijs van Veen
Browse files
Options
Downloads
Patches
Plain Diff
Improved py_callback exception handling and code cleanup.
parent
3d541647
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pyrex/bison_.pyx
+36
-38
36 additions, 38 deletions
src/pyrex/bison_.pyx
src/python/bison.py
+15
-4
15 additions, 4 deletions
src/python/bison.py
with
51 additions
and
42 deletions
src/pyrex/bison_.pyx
+
36
−
38
View file @
0bdb2622
...
...
@@ -88,45 +88,41 @@ cdef public object py_callback(object parser, char *target, int option, \
#if parser.verbose:
# print 'py_callback: called with nargs=%d' % nargs
try
:
names
=
PyList_New
(
nargs
)
values
=
PyList_New
(
nargs
)
names
=
PyList_New
(
nargs
)
values
=
PyList_New
(
nargs
)
Py_INCREF
(
names
)
Py_INCREF
(
values
)
Py_INCREF
(
names
)
Py_INCREF
(
values
)
#for i in range(nargs):
# print 'i=%d' % i , <char*>va_arg(ap, str_type), \
# hex(<int>va_arg(ap, str_type))
#for i in range(nargs):
# print 'i=%d' % i , <char*>va_arg(ap, str_type), \
# hex(<int>va_arg(ap, str_type))
for
i
in
range
(
nargs
):
termname
=
<
char
*>
va_arg
(
ap
,
str_type
)
PyList_SetItem
(
names
,
i
,
termname
)
Py_INCREF
(
termname
)
for
i
in
range
(
nargs
):
termname
=
<
char
*>
va_arg
(
ap
,
str_type
)
PyList_SetItem
(
names
,
i
,
termname
)
Py_INCREF
(
termname
)
val
=
<
void
*>
va_arg
(
ap
,
void_type
)
valobj
=
<
object
>
val
PyList_SetItem
(
values
,
i
,
valobj
)
Py_INCREF
(
valobj
)
val
=
<
void
*>
va_arg
(
ap
,
void_type
)
valobj
=
<
object
>
val
PyList_SetItem
(
values
,
i
,
valobj
)
Py_INCREF
(
valobj
)
#if parser.verbose:
# print 'py_callback: calling handler:', \
# (target, option, names, values)
#if parser.verbose:
# print 'py_callback: calling handler:', \
# (target, option, names, values)
# Set the signal handler and a timeout alarm
#signal.signal(signal.SIGALRM, parser.handle_timeout)
#signal.alarm(parser.timeout)
# Set the signal handler and a timeout alarm
#signal.signal(signal.SIGALRM, parser.handle_timeout)
#signal.alarm(parser.timeout)
res
=
parser
.
_handle
(
target
,
option
,
names
,
values
)
res
=
parser
.
_handle
(
target
,
option
,
names
,
values
)
#signal.alarm(0)
#signal.alarm(0)
#if parser.verbose:
# print 'py_callback: handler returned:', res
except
:
traceback
.
print_exc
()
res
=
None
#if parser.verbose:
# print 'py_callback: handler returned:', res
va_end
(
ap
)
...
...
@@ -138,7 +134,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
cdef
int
buflen
if
parser
.
verbose
:
print
"
\n
py_input: want to read up to %s bytes
"
%
max_size
print
'
\n
py_input: want to read up to %s bytes
'
%
max_size
raw
=
parser
.
read
(
max_size
)
buflen
=
PyInt_AsLong
(
len
(
raw
))
...
...
@@ -146,7 +142,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
memcpy
(
buf
,
PyString_AsString
(
raw
),
buflen
)
if
parser
.
verbose
:
print
"
\n
py_input: got %s bytes
"
%
buflen
print
'
\n
py_input: got %s bytes
'
%
buflen
import
sys
,
os
,
sha
,
re
,
imp
,
traceback
...
...
@@ -158,7 +154,7 @@ import distutils.ccompiler
reSpaces
=
re
.
compile
(
"
\\
s+
"
)
#unquoted = r"""^|[^'"]%s[^'"]?"""
unquoted
=
"
[^
'
\"
]%s[^
'
\"
]?
"
unquoted
=
'
[^
\
'
"
]%s[^
\
'
"
]?
'
cdef
class
ParserEngine
:
"""
...
...
@@ -263,19 +259,19 @@ cdef class ParserEngine:
parser
=
self
.
parser
if
parser
.
verbose
:
print
"
Opening library %s
"
%
self
.
libFilename_py
print
'
Opening library %s
'
%
self
.
libFilename_py
handle
=
bisondynlib_open
(
libFilename
)
self
.
libHandle
=
handle
err
=
bisondynlib_err
()
if
err
:
printf
(
"
ParserEngine.openLib: error
'
%s
'
\n
"
,
err
)
printf
(
'
ParserEngine.openLib: error
"
%s
"
\n
'
,
err
)
return
# extract symbols
self
.
libHash
=
bisondynlib_lookup_hash
(
handle
)
if
parser
.
verbose
:
print
"
Successfully loaded library
"
print
'
Successfully loaded library
'
def
buildLib
(
self
):
"""
...
...
@@ -294,14 +290,16 @@ cdef class ParserEngine:
# rip the pertinent grammar specs from parser class
parser
=
self
.
parser
# get target handler methods, in the order of appearance in the
source
# file.
# get target handler methods, in the order of appearance in the
#
source
file.
attribs
=
dir
(
parser
)
gHandlers
=
[]
for
a
in
attribs
:
if
a
.
startswith
(
"
on_
"
):
if
a
.
startswith
(
'
on_
'
):
method
=
getattr
(
parser
,
a
)
gHandlers
.
append
(
method
)
gHandlers
.
sort
(
cmpLines
)
# get start symbol, tokens, precedences, lex script
...
...
This diff is collapsed.
Click to expand it.
src/python/bison.py
+
15
−
4
View file @
0bdb2622
...
...
@@ -320,11 +320,20 @@ class BisonParser(object):
except
:
hdlrline
=
handler
.
__init__
.
func_code
.
co_firstlineno
print
'
_handle: invoking handler at line %s for
"
%s
"'
\
%
(
hdlrline
,
targetname
)
print
'
BisonParser._handle: call handler at line %s with: %s
'
\
%
(
hdlrline
,
str
((
targetname
,
option
,
names
,
values
)))
try
:
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
except
Exception
as
e
:
self
.
lasterror
=
e
print
type
(
e
),
str
(
e
)
#traceback.print_last()
#traceback.print_stack()
traceback
.
print_stack
()
raise
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
#if self.verbose:
# print 'handler for %s returned %s' \
# % (targetname, repr(self.last))
...
...
@@ -334,6 +343,8 @@ class BisonParser(object):
self
.
last
=
BisonNode
(
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
# reset any resulting errors (assume they've been handled)
if
self
.
lasterror
:
print
'
lasterror:
'
,
self
.
lasterror
#self.lasterror = None
# assumedly the last thing parsed is at the top of the tree
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment