Commit 5bfed246 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

hoaparse: make it possible to read from a string

* src/hoaparse/public.hh, src/hoaparse/parsedecl.hh,
src/hoaparse/hoascan.ll, src/hoaparse/hoaparse.yy: Implement this new
* wrap/python/ (automata): Use it when the argument contains
a newline.
* wrap/python/tests/automata-io.ipynb: Test it.
parent 528cc04c
......@@ -1667,6 +1667,14 @@ namespace spot
throw std::runtime_error(std::string("Cannot open file ") + name);
hoa_stream_parser::hoa_stream_parser(const char* data,
const std::string& filename,
bool ignore_abort)
: filename_(filename), ignore_abort_(ignore_abort)
......@@ -390,6 +390,14 @@ namespace spot
return 0;
hoayystring(const char* data)
return 0;
hoayyopen(int fd)
......@@ -34,6 +34,7 @@ namespace spot
void hoayyreset();
int hoayyopen(const std::string& name);
int hoayyopen(int fd);
int hoayystring(const char* data);
void hoayyclose();
// This exception is thrown by the lexer when it reads "--ABORT--".
......@@ -68,6 +68,10 @@ namespace spot
// Use filename in error messages.
hoa_stream_parser(int fd, const std::string& filename,
bool ignore_abort = false);
// Read from a buffer
hoa_stream_parser(const char* data,
const std::string& filename,
bool ignore_abort = false);
hoa_aut_ptr parse(hoa_parse_error_list& error_list,
const bdd_dict_ptr& dict,
......@@ -140,20 +140,29 @@ def automata(*filenames):
or in [LBTT's format]
If a filename ends with a `|`, then the filename is interpreted as
If an argument ends with a `|`, then this argument is interpreted as
a shell command, and the output of that command (without the `|`)
is parsed."""
is parsed.
If an argument contains a newline, then it is interpreted as
actual contents to be parsed.
Otherwise, the argument is assumed to be a filename.
for filename in filenames:
p = None
if filename[-1] != '|':
proc = None
p = hoa_stream_parser(filename, True)
if filename[-1] == '|':
proc = subprocess.Popen(filename[:-1], shell=True,
p = hoa_stream_parser(proc.stdout.fileno(), filename, True)
elif '\n' in filename:
proc = None
p = hoa_stream_parser(filename, "<string>", True)
proc = None
p = hoa_stream_parser(filename, True)
a = True
while a:
# This returns None when we reach the end of the file.
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment