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
0a49121e
Commit
0a49121e
authored
May 24, 2012
by
Sander Mathijs van Veen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added reset_flex_buffer hook to support flushing flex's internal buffer.
parent
91979192
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
9 deletions
+45
-9
src/c/bisondynlib-linux.c
src/c/bisondynlib-linux.c
+33
-8
src/c/bisondynlib.h
src/c/bisondynlib.h
+1
-1
src/pyrex/bison_.pyx
src/pyrex/bison_.pyx
+7
-0
src/python/bison.py
src/python/bison.py
+4
-0
No files found.
src/c/bisondynlib-linux.c
View file @
0a49121e
...
@@ -6,12 +6,23 @@
...
@@ -6,12 +6,23 @@
#include <stdio.h>
#include <stdio.h>
#include <dlfcn.h>
#include <dlfcn.h>
void
(
*
reset_flex_buffer
)(
void
)
=
NULL
;
void
*
bisondynlib_open
(
char
*
filename
)
void
*
bisondynlib_open
(
char
*
filename
)
{
{
void
*
handle
;
void
*
handle
;
dlerror
();
handle
=
dlopen
(
filename
,
(
RTLD_NOW
|
RTLD_GLOBAL
));
handle
=
dlopen
(
filename
,
(
RTLD_NOW
|
RTLD_GLOBAL
));
dlerror
();
if
(
!
handle
)
return
NULL
;
reset_flex_buffer
=
dlsym
(
handle
,
"reset_flex_buffer"
);
dlerror
();
return
handle
;
return
handle
;
}
}
...
@@ -20,6 +31,12 @@ int bisondynlib_close(void *handle)
...
@@ -20,6 +31,12 @@ int bisondynlib_close(void *handle)
return
dlclose
(
handle
);
return
dlclose
(
handle
);
}
}
void
bisondynlib_reset
(
void
)
{
if
(
reset_flex_buffer
)
reset_flex_buffer
();
}
char
*
bisondynlib_err
()
char
*
bisondynlib_err
()
{
{
return
dlerror
();
return
dlerror
();
...
@@ -28,16 +45,19 @@ char *bisondynlib_err()
...
@@ -28,16 +45,19 @@ char *bisondynlib_err()
char
*
bisondynlib_lookup_hash
(
void
*
handle
)
char
*
bisondynlib_lookup_hash
(
void
*
handle
)
{
{
char
**
hash
;
char
**
hash
;
dlerror
();
hash
=
dlsym
(
handle
,
"rules_hash"
);
hash
=
dlsym
(
handle
,
"rules_hash"
);
/*
printf("bisondynlib_lookup_hash: hash=%s\n", *hash
);
dlerror
(
);
*/
return
*
hash
;
return
hash
?
*
hash
:
NULL
;
}
}
PyObject
*
bisondynlib_run
(
void
*
handle
,
PyObject
*
parser
,
void
*
cb
,
void
*
in
,
int
debug
)
PyObject
*
bisondynlib_run
(
void
*
handle
,
PyObject
*
parser
,
void
*
cb
,
void
*
in
,
int
debug
)
{
{
if
(
!
handle
)
return
NULL
;
PyObject
*
(
*
pparser
)(
PyObject
*
,
void
*
,
void
*
,
int
);
PyObject
*
(
*
pparser
)(
PyObject
*
,
void
*
,
void
*
,
int
);
pparser
=
bisondynlib_lookup_parser
(
handle
);
pparser
=
bisondynlib_lookup_parser
(
handle
);
...
@@ -60,12 +80,17 @@ PyObject *bisondynlib_run(void *handle, PyObject *parser, void *cb, void *in, in
...
@@ -60,12 +80,17 @@ PyObject *bisondynlib_run(void *handle, PyObject *parser, void *cb, void *in, in
}
}
/*
/*
* function(void *) returns a pointer to a function(PyObject *, char *) returning PyObject*
* function(void *) returns a pointer to a function(PyObject *, char *)
* returning PyObject*
*/
*/
PyObject
*
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
PyObject
*
,
void
*
,
void
*
,
int
)
PyObject
*
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
PyObject
*
,
void
*
,
void
*
,
int
)
{
{
PyObject
*
(
*
do_parse
)(
PyObject
*
,
void
*
,
void
*
,
int
)
=
dlsym
(
handle
,
"do_parse"
);
dlerror
();
dlerror
();
return
dlsym
(
handle
,
"do_parse"
);
return
do_parse
;
}
}
/*
/*
...
...
src/c/bisondynlib.h
View file @
0a49121e
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
void
*
bisondynlib_open
(
char
*
filename
);
void
*
bisondynlib_open
(
char
*
filename
);
int
bisondynlib_close
(
void
*
handle
);
int
bisondynlib_close
(
void
*
handle
);
void
bisondynlib_reset
(
void
);
char
*
bisondynlib_err
(
void
);
char
*
bisondynlib_err
(
void
);
PyObject
*
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
PyObject
*
,
void
*
,
void
*
,
int
);
PyObject
*
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
PyObject
*
,
void
*
,
void
*
,
int
);
...
@@ -14,7 +15,6 @@ PyObject *(*bisondynlib_lookup_parser(void *handle))(PyObject *, void *, void *,
...
@@ -14,7 +15,6 @@ PyObject *(*bisondynlib_lookup_parser(void *handle))(PyObject *, void *, void *,
char
*
bisondynlib_lookup_hash
(
void
*
handle
);
char
*
bisondynlib_lookup_hash
(
void
*
handle
);
PyObject
*
bisondynlib_run
(
void
*
handle
,
PyObject
*
parser
,
void
*
cb
,
void
*
in
,
int
debug
);
PyObject
*
bisondynlib_run
(
void
*
handle
,
PyObject
*
parser
,
void
*
cb
,
void
*
in
,
int
debug
);
/*
/*
int bisondynlib_build(char *libName, char *pyincdir);
int bisondynlib_build(char *libName, char *pyincdir);
*/
*/
src/pyrex/bison_.pyx
View file @
0a49121e
...
@@ -53,6 +53,7 @@ cdef extern from "../c/bison_callback.h":
...
@@ -53,6 +53,7 @@ cdef extern from "../c/bison_callback.h":
cdef
extern
from
"../c/bisondynlib.h"
:
cdef
extern
from
"../c/bisondynlib.h"
:
void
*
bisondynlib_open
(
char
*
filename
)
void
*
bisondynlib_open
(
char
*
filename
)
int
bisondynlib_close
(
void
*
handle
)
int
bisondynlib_close
(
void
*
handle
)
void
bisondynlib_reset
()
char
*
bisondynlib_err
()
char
*
bisondynlib_err
()
object
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
object
,
char
*
)
object
(
*
bisondynlib_lookup_parser
(
void
*
handle
))(
object
,
char
*
)
char
*
bisondynlib_lookup_hash
(
void
*
handle
)
char
*
bisondynlib_lookup_hash
(
void
*
handle
)
...
@@ -121,6 +122,12 @@ cdef class ParserEngine:
...
@@ -121,6 +122,12 @@ cdef class ParserEngine:
self
.
openCurrentLib
()
self
.
openCurrentLib
()
def
reset
(
self
):
"""
Reset Flex's buffer and state.
"""
bisondynlib_reset
()
def
openCurrentLib
(
self
):
def
openCurrentLib
(
self
):
"""
"""
Tests if library exists and is current. If not, builds a fresh one.
Tests if library exists and is current. If not, builds a fresh one.
...
...
src/python/bison.py
View file @
0a49121e
...
@@ -200,6 +200,9 @@ class BisonParser(object):
...
@@ -200,6 +200,9 @@ class BisonParser(object):
def
handle_timeout
(
self
,
signum
,
frame
):
def
handle_timeout
(
self
,
signum
,
frame
):
raise
TimeoutError
(
'Computation exceeded timeout limit.'
)
raise
TimeoutError
(
'Computation exceeded timeout limit.'
)
def
reset
(
self
):
self
.
engine
.
reset
()
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.
...
@@ -247,6 +250,7 @@ class BisonParser(object):
...
@@ -247,6 +250,7 @@ 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
.
engine
.
reset
()
try
:
try
:
self
.
engine
.
runEngine
(
debug
)
self
.
engine
.
runEngine
(
debug
)
...
...
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