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
0bdb2622
Commit
0bdb2622
authored
Dec 01, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved py_callback exception handling and code cleanup.
parent
3d541647
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
42 deletions
+51
-42
src/pyrex/bison_.pyx
src/pyrex/bison_.pyx
+36
-38
src/python/bison.py
src/python/bison.py
+15
-4
No files found.
src/pyrex/bison_.pyx
View file @
0bdb2622
...
@@ -88,7 +88,6 @@ cdef public object py_callback(object parser, char *target, int option, \
...
@@ -88,7 +88,6 @@ cdef public object py_callback(object parser, char *target, int option, \
#if parser.verbose:
#if parser.verbose:
# print 'py_callback: called with nargs=%d' % nargs
# print 'py_callback: called with nargs=%d' % nargs
try
:
names
=
PyList_New
(
nargs
)
names
=
PyList_New
(
nargs
)
values
=
PyList_New
(
nargs
)
values
=
PyList_New
(
nargs
)
...
@@ -124,9 +123,6 @@ cdef public object py_callback(object parser, char *target, int option, \
...
@@ -124,9 +123,6 @@ cdef public object py_callback(object parser, char *target, int option, \
#if parser.verbose:
#if parser.verbose:
# print 'py_callback: handler returned:', res
# print 'py_callback: handler returned:', res
except
:
traceback
.
print_exc
()
res
=
None
va_end
(
ap
)
va_end
(
ap
)
...
@@ -138,7 +134,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
...
@@ -138,7 +134,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
cdef
int
buflen
cdef
int
buflen
if
parser
.
verbose
:
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
)
raw
=
parser
.
read
(
max_size
)
buflen
=
PyInt_AsLong
(
len
(
raw
))
buflen
=
PyInt_AsLong
(
len
(
raw
))
...
@@ -146,7 +142,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
...
@@ -146,7 +142,7 @@ cdef public void py_input(object parser, char *buf, int *result, int max_size):
memcpy
(
buf
,
PyString_AsString
(
raw
),
buflen
)
memcpy
(
buf
,
PyString_AsString
(
raw
),
buflen
)
if
parser
.
verbose
:
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
import
sys
,
os
,
sha
,
re
,
imp
,
traceback
...
@@ -158,7 +154,7 @@ import distutils.ccompiler
...
@@ -158,7 +154,7 @@ import distutils.ccompiler
reSpaces
=
re
.
compile
(
"
\
\
s+"
)
reSpaces
=
re
.
compile
(
"
\
\
s+"
)
#unquoted = r"""^|[^'"]%s[^'"]?"""
#unquoted = r"""^|[^'"]%s[^'"]?"""
unquoted
=
"[^'
\
"
]%s[^'
\
"
]?"
unquoted
=
'[^
\
'
"]%s[^
\
'
"]?'
cdef
class
ParserEngine
:
cdef
class
ParserEngine
:
"""
"""
...
@@ -263,19 +259,19 @@ cdef class ParserEngine:
...
@@ -263,19 +259,19 @@ cdef class ParserEngine:
parser
=
self
.
parser
parser
=
self
.
parser
if
parser
.
verbose
:
if
parser
.
verbose
:
print
"Opening library %s"
%
self
.
libFilename_py
print
'Opening library %s'
%
self
.
libFilename_py
handle
=
bisondynlib_open
(
libFilename
)
handle
=
bisondynlib_open
(
libFilename
)
self
.
libHandle
=
handle
self
.
libHandle
=
handle
err
=
bisondynlib_err
()
err
=
bisondynlib_err
()
if
err
:
if
err
:
printf
(
"ParserEngine.openLib: error '%s'
\
n
"
,
err
)
printf
(
'ParserEngine.openLib: error "%s"
\
n
'
,
err
)
return
return
# extract symbols
# extract symbols
self
.
libHash
=
bisondynlib_lookup_hash
(
handle
)
self
.
libHash
=
bisondynlib_lookup_hash
(
handle
)
if
parser
.
verbose
:
if
parser
.
verbose
:
print
"Successfully loaded library"
print
'Successfully loaded library'
def
buildLib
(
self
):
def
buildLib
(
self
):
"""
"""
...
@@ -294,14 +290,16 @@ cdef class ParserEngine:
...
@@ -294,14 +290,16 @@ cdef class ParserEngine:
# rip the pertinent grammar specs from parser class
# rip the pertinent grammar specs from parser class
parser
=
self
.
parser
parser
=
self
.
parser
# get target handler methods, in the order of appearance in the
source
# get target handler methods, in the order of appearance in the
# file.
#
source
file.
attribs
=
dir
(
parser
)
attribs
=
dir
(
parser
)
gHandlers
=
[]
gHandlers
=
[]
for
a
in
attribs
:
for
a
in
attribs
:
if
a
.
startswith
(
"on_"
):
if
a
.
startswith
(
'on_'
):
method
=
getattr
(
parser
,
a
)
method
=
getattr
(
parser
,
a
)
gHandlers
.
append
(
method
)
gHandlers
.
append
(
method
)
gHandlers
.
sort
(
cmpLines
)
gHandlers
.
sort
(
cmpLines
)
# get start symbol, tokens, precedences, lex script
# get start symbol, tokens, precedences, lex script
...
...
src/python/bison.py
View file @
0bdb2622
...
@@ -320,11 +320,20 @@ class BisonParser(object):
...
@@ -320,11 +320,20 @@ class BisonParser(object):
except
:
except
:
hdlrline
=
handler
.
__init__
.
func_code
.
co_firstlineno
hdlrline
=
handler
.
__init__
.
func_code
.
co_firstlineno
print
'
_handle: invoking handler at line %s for "%s"
'
\
print
'
BisonParser._handle: call handler at line %s with: %s
'
\
%
(
hdlrline
,
targetname
)
%
(
hdlrline
,
str
((
targetname
,
option
,
names
,
values
))
)
try
:
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
names
=
names
,
self
.
last
=
handler
(
target
=
targetname
,
option
=
option
,
names
=
names
,
values
=
values
)
values
=
values
)
except
Exception
as
e
:
self
.
lasterror
=
e
print
type
(
e
),
str
(
e
)
#traceback.print_last()
#traceback.print_stack()
traceback
.
print_stack
()
raise
#if self.verbose:
#if self.verbose:
# print 'handler for %s returned %s' \
# print 'handler for %s returned %s' \
# % (targetname, repr(self.last))
# % (targetname, repr(self.last))
...
@@ -334,6 +343,8 @@ class BisonParser(object):
...
@@ -334,6 +343,8 @@ 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)
if
self
.
lasterror
:
print
'lasterror:'
,
self
.
lasterror
#self.lasterror = None
#self.lasterror = 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
...
...
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