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
df0ac6f3
Commit
df0ac6f3
authored
Nov 19, 2011
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup.
parent
f9a34e5e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
191 deletions
+137
-191
src/pyrex/bison_.pyx
src/pyrex/bison_.pyx
+43
-66
src/python/bison.py
src/python/bison.py
+94
-125
No files found.
src/pyrex/bison_.pyx
View file @
df0ac6f3
...
@@ -54,6 +54,7 @@ cdef extern from "../c/bisondynlib.h":
...
@@ -54,6 +54,7 @@ cdef extern from "../c/bisondynlib.h":
#int bisondynlib_build(char *libName, char *includedir)
#int bisondynlib_build(char *libName, char *includedir)
# Definitions for variadic functions (e.g. py_callback).
cdef
extern
from
"stdarg.h"
:
cdef
extern
from
"stdarg.h"
:
ctypedef
struct
va_list
:
ctypedef
struct
va_list
:
pass
pass
...
@@ -267,8 +268,6 @@ cdef class ParserEngine:
...
@@ -267,8 +268,6 @@ cdef class ParserEngine:
if
parser
.
verbose
:
if
parser
.
verbose
:
print
"Successfully loaded library"
print
"Successfully loaded library"
#@-node:openLib
#@+node:buildLib
def
buildLib
(
self
):
def
buildLib
(
self
):
"""
"""
Creates the parser engine lib
Creates the parser engine lib
...
@@ -599,16 +598,12 @@ cdef class ParserEngine:
...
@@ -599,16 +598,12 @@ cdef class ParserEngine:
except
:
except
:
print
"Warning: failed to delete temporary file %s"
%
f
print
"Warning: failed to delete temporary file %s"
%
f
#@-node:buildLib
#@+node:closeLib
def
closeLib
(
self
):
def
closeLib
(
self
):
"""
"""
Does the necessary cleanups and closes the parser library
Does the necessary cleanups and closes the parser library
"""
"""
bisondynlib_close
(
self
.
libHandle
)
bisondynlib_close
(
self
.
libHandle
)
#@-node:closeLib
#@+node:runEngine
def
runEngine
(
self
,
debug
=
0
):
def
runEngine
(
self
,
debug
=
0
):
"""
"""
Runs the binary parser engine, as loaded from the lib
Runs the binary parser engine, as loaded from the lib
...
@@ -624,25 +619,15 @@ cdef class ParserEngine:
...
@@ -624,25 +619,15 @@ cdef class ParserEngine:
cbvoid
=
<
void
*>
py_callback
cbvoid
=
<
void
*>
py_callback
invoid
=
<
void
*>
py_input
invoid
=
<
void
*>
py_input
if
parser
.
verbose
:
print
"runEngine: about to call, py_input=0x%lx..."
%
(
<
int
>
invoid
)
return
bisondynlib_run
(
handle
,
parser
,
cbvoid
,
invoid
,
debug
)
return
bisondynlib_run
(
handle
,
parser
,
cbvoid
,
invoid
,
debug
)
if
parser
.
verbose
:
print
"runEngine: back from parser"
#@-node:runEngine
#@+node:__del__
def
__del__
(
self
):
def
__del__
(
self
):
"""
"""
Clean up and bail
Clean up and bail
"""
"""
self
.
closeLib
()
self
.
closeLib
()
#@-node:__del__
#@-others
#@-node:cdef class ParserEngine
#@+node:cmpLines
def
cmpLines
(
meth1
,
meth2
):
def
cmpLines
(
meth1
,
meth2
):
"""
"""
Used as a sort() argument for sorting parse target handler methods by
Used as a sort() argument for sorting parse target handler methods by
...
@@ -657,8 +642,7 @@ def cmpLines(meth1, meth2):
...
@@ -657,8 +642,7 @@ def cmpLines(meth1, meth2):
return
cmp
(
line1
,
line2
)
return
cmp
(
line1
,
line2
)
#@-node:cmpLines
#@+node:hashParserObject
def
hashParserObject
(
parser
):
def
hashParserObject
(
parser
):
"""
"""
Calculates an sha1 hex 'hash' of the lex script
Calculates an sha1 hex 'hash' of the lex script
...
@@ -714,10 +698,3 @@ def hashParserObject(parser):
...
@@ -714,10 +698,3 @@ def hashParserObject(parser):
# done
# done
return
hasher
.
hexdigest
()
return
hasher
.
hexdigest
()
#@-node:hashParserObject
#@-others
#@-node:@file src/pyrex/bison_.pyx
#@-leo
src/python/bison.py
View file @
df0ac6f3
...
@@ -313,12 +313,9 @@ class BisonParser(object):
...
@@ -313,12 +313,9 @@ class BisonParser(object):
# get an engine
# get an engine
self
.
engine
=
ParserEngine
(
self
)
self
.
engine
=
ParserEngine
(
self
)
#@-node:__init__
#@+node:__getattr__
def
__getitem__
(
self
,
idx
):
def
__getitem__
(
self
,
idx
):
return
self
.
last
[
idx
]
return
self
.
last
[
idx
]
#@-node:__getattr__
#@+node:_handle
def
_handle
(
self
,
targetname
,
option
,
names
,
values
):
def
_handle
(
self
,
targetname
,
option
,
names
,
values
):
"""
"""
Callback which receives a target from parser, as a targetname
Callback which receives a target from parser, as a targetname
...
@@ -354,9 +351,6 @@ class BisonParser(object):
...
@@ -354,9 +351,6 @@ class BisonParser(object):
# 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
#@-node:_handle
#@+node:run
def
run
(
self
,
**
kw
):
def
run
(
self
,
**
kw
):
"""
"""
Runs the parser, and returns the top-most parse target.
Runs the parser, and returns the top-most parse target.
...
@@ -414,9 +408,6 @@ class BisonParser(object):
...
@@ -414,9 +408,6 @@ class BisonParser(object):
print
"Parser.run: back from engine"
print
"Parser.run: back from engine"
return
self
.
last
return
self
.
last
#@-node:run
#@+node:read
def
read
(
self
,
nbytes
):
def
read
(
self
,
nbytes
):
"""
"""
Override this in your subclass, if you desire.
Override this in your subclass, if you desire.
...
@@ -433,44 +424,36 @@ class BisonParser(object):
...
@@ -433,44 +424,36 @@ class BisonParser(object):
if
self
.
verbose
:
if
self
.
verbose
:
print
"Parser.read: got %s bytes"
%
len
(
bytes
)
print
"Parser.read: got %s bytes"
%
len
(
bytes
)
return
bytes
return
bytes
#@-node:read
#@+node:_error
def
_error
(
self
,
linenum
,
msg
,
tok
):
def
_error
(
self
,
linenum
,
msg
,
tok
):
print
"Parser: line %s: syntax error '%s' before '%s'"
%
(
linenum
,
msg
,
tok
)
print
"Parser: line %s: syntax error '%s' before '%s'"
%
(
linenum
,
msg
,
tok
)
#@-node:_error
#@+node:error
def
error
(
self
,
value
):
def
error
(
self
,
value
):
"""
"""
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
"""
"""
self
.
lasterror
=
value
self
.
lasterror
=
value
return
BisonError
(
value
)
return
BisonError
(
value
)
#@-node:error
#@+node:toxml
def
toxml
(
self
):
def
toxml
(
self
):
"""
"""
Serialises the parse tree and returns it as a raw xml string
Serialises the parse tree and returns it as a raw xml string
"""
"""
return
self
.
last
.
toxml
()
return
self
.
last
.
toxml
()
#@-node:toxml
#@+node:toxmldoc
def
toxmldoc
(
self
):
def
toxmldoc
(
self
):
"""
"""
Returns an xml.dom.minidom.Document object containing the parse tree
Returns an xml.dom.minidom.Document object containing the parse tree
"""
"""
return
self
.
last
.
toxmldoc
()
return
self
.
last
.
toxmldoc
()
#@-node:toxmldoc
#@+node:toprettyxml
def
toprettyxml
(
self
):
def
toprettyxml
(
self
):
"""
"""
Returns a human-readable xml representation of the parse tree
Returns a human-readable xml representation of the parse tree
"""
"""
return
self
.
last
.
toprettyxml
()
return
self
.
last
.
toprettyxml
()
#@-node:toprettyxml
#@+node:loadxml
def
loadxml
(
self
,
raw
,
namespace
=
None
):
def
loadxml
(
self
,
raw
,
namespace
=
None
):
"""
"""
Loads a parse tree from raw xml text
Loads a parse tree from raw xml text
...
@@ -490,8 +473,7 @@ class BisonParser(object):
...
@@ -490,8 +473,7 @@ class BisonParser(object):
tree
=
self
.
loadxmldoc
(
doc
,
namespace
)
tree
=
self
.
loadxmldoc
(
doc
,
namespace
)
self
.
last
=
tree
self
.
last
=
tree
return
tree
return
tree
#@-node:loadxml
#@+node:loadxmldoc
def
loadxmldoc
(
self
,
xmldoc
,
namespace
=
None
):
def
loadxmldoc
(
self
,
xmldoc
,
namespace
=
None
):
"""
"""
Returns a reconstituted parse tree, loaded from an
Returns a reconstituted parse tree, loaded from an
...
@@ -503,8 +485,7 @@ class BisonParser(object):
...
@@ -503,8 +485,7 @@ class BisonParser(object):
to translate the document into a tree of parse nodes
to translate the document into a tree of parse nodes
"""
"""
return
self
.
loadxmlobj
(
xmldoc
.
childNodes
[
0
],
namespace
)
return
self
.
loadxmlobj
(
xmldoc
.
childNodes
[
0
],
namespace
)
#@-node:loadxmldoc
#@+node:loadxmlobj
def
loadxmlobj
(
self
,
xmlobj
,
namespace
=
None
):
def
loadxmlobj
(
self
,
xmlobj
,
namespace
=
None
):
"""
"""
Returns a node object, being a parse tree, reconstituted from an
Returns a node object, being a parse tree, reconstituted from an
...
@@ -564,18 +545,11 @@ class BisonParser(object):
...
@@ -564,18 +545,11 @@ class BisonParser(object):
nodeobj
.
names
.
append
(
childname
)
nodeobj
.
names
.
append
(
childname
)
nodeobj
.
values
.
append
(
childobj
)
nodeobj
.
values
.
append
(
childobj
)
# done
return
nodeobj
return
nodeobj
#@-node:loadxmlobj
#@+node:_globals
def
_globals
(
self
):
def
_globals
(
self
):
return
globals
().
keys
()
return
globals
().
keys
()
#@-node:_globals
#@-others
#@-node:class BisonParser
#@+node:bisonToPython
def
bisonToPython
(
bisonfileName
,
lexfileName
,
pyfileName
,
generateClasses
=
0
):
def
bisonToPython
(
bisonfileName
,
lexfileName
,
pyfileName
,
generateClasses
=
0
):
"""
"""
Rips the rules, tokens and precedences from a bison file, and the
Rips the rules, tokens and precedences from a bison file, and the
...
@@ -942,8 +916,3 @@ def bisonToPython(bisonfileName, lexfileName, pyfileName, generateClasses=0):
...
@@ -942,8 +916,3 @@ def bisonToPython(bisonfileName, lexfileName, pyfileName, generateClasses=0):
''
,
''
,
''
,
''
,
]))
]))
#@-node:bisonToPython
#@-others
#@-node:@file src/python/bison.py
#@-leo
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