python: read automata from pipes

* src/hoaparse/hoaparse.yy, src/hoaparse/hoascan.ll,
src/hoaparse/parsedecl.hh, src/hoaparse/public.hh:
Add a way to read automata from a file descriptor.
* wrap/python/spot.py: Add machinery to read from
pipes.
* wrap/python/tests/piperead.ipynb: New file.
* wrap/python/tests/Makefile.am: Add it.
* wrap/python/tests/run.in: Setup PATH.
This commit is contained in:
Alexandre Duret-Lutz 2015-03-30 17:05:04 +02:00
parent af8e7d62de
commit 961d005b84
8 changed files with 603 additions and 8 deletions

View file

@ -1620,6 +1620,15 @@ namespace spot
throw std::runtime_error(std::string("Cannot open file ") + name);
}
hoa_stream_parser::hoa_stream_parser(int fd,
const std::string& name,
bool ignore_abort)
: filename_(name), ignore_abort_(ignore_abort)
{
if (hoayyopen(fd))
throw std::runtime_error(std::string("Cannot open file ") + name);
}
hoa_stream_parser::~hoa_stream_parser()
{
hoayyclose();

View file

@ -388,6 +388,31 @@ namespace spot
return 0;
}
int
hoayyopen(int fd)
{
bool want_interactive = false;
yyin = fdopen(fd, "r");
// If the input is a pipe, make the scanner
// interactive so that it does not wait for the input
// buffer to be full to process automata.
struct stat s;
if (fstat(fd, &s) < 0)
throw std::runtime_error("fstat failed");
if (S_ISFIFO(s.st_mode))
want_interactive = true;
// Reset the lexer in case a previous parse
// ended badly.
YY_NEW_FILE;
hoayyreset();
if (want_interactive)
yy_set_interactive(true);
return 0;
}
void
hoayyclose()
{

View file

@ -1,5 +1,5 @@
// -*- coding: utf-8 -*-
// Copyright (C) 2014 Laboratoire de Recherche et Développement
// Copyright (C) 2014, 2015 Laboratoire de Recherche et Développement
// de l'EPITA.
//
// This file is part of Spot, a model checking library.
@ -33,6 +33,7 @@ namespace spot
{
void hoayyreset();
int hoayyopen(const std::string& name);
int hoayyopen(int fd);
void hoayyclose();
// This exception is thrown by the lexer when it reads "--ABORT--".

View file

@ -64,6 +64,10 @@ namespace spot
bool ignore_abort_;
public:
hoa_stream_parser(const std::string& filename, bool ignore_abort = false);
// Read from an already open file descriptor.
// Use filename in error messages.
hoa_stream_parser(int fd, const std::string& filename,
bool ignore_abort = false);
~hoa_stream_parser();
hoa_aut_ptr parse(hoa_parse_error_list& error_list,
const bdd_dict_ptr& dict,