summaryrefslogtreecommitdiff
path: root/src/parser/antlr_input.cpp
diff options
context:
space:
mode:
authorChristopher L. Conway <christopherleeconway@gmail.com>2010-06-03 22:27:16 +0000
committerChristopher L. Conway <christopherleeconway@gmail.com>2010-06-03 22:27:16 +0000
commitf780dd882fc343cef668d5cd9eed8f515d0e70ed (patch)
tree5a3432a90d1f30cdc00f2353c0b43a468da09661 /src/parser/antlr_input.cpp
parent4cd2a432d621d18f7b811caab8935a617b4771c5 (diff)
Implementing input from stdin (Fixes: #144)
Diffstat (limited to 'src/parser/antlr_input.cpp')
-rw-r--r--src/parser/antlr_input.cpp58
1 files changed, 54 insertions, 4 deletions
diff --git a/src/parser/antlr_input.cpp b/src/parser/antlr_input.cpp
index 300b181a6..9d75dd31f 100644
--- a/src/parser/antlr_input.cpp
+++ b/src/parser/antlr_input.cpp
@@ -40,8 +40,10 @@ using namespace CVC4::kind;
namespace CVC4 {
namespace parser {
-AntlrInputStream::AntlrInputStream(std::string name, pANTLR3_INPUT_STREAM input) :
- InputStream(name),
+AntlrInputStream::AntlrInputStream(std::string name,
+ pANTLR3_INPUT_STREAM input,
+ bool fileIsTemporary) :
+ InputStream(name,fileIsTemporary),
d_input(input) {
AlwaysAssert( input != NULL );
}
@@ -54,7 +56,9 @@ pANTLR3_INPUT_STREAM AntlrInputStream::getAntlr3InputStream() const {
return d_input;
}
-AntlrInputStream* AntlrInputStream::newFileInputStream(const std::string& name, bool useMmap)
+AntlrInputStream*
+AntlrInputStream::newFileInputStream(const std::string& name,
+ bool useMmap)
throw (InputStreamException) {
pANTLR3_INPUT_STREAM input = NULL;
if( useMmap ) {
@@ -68,7 +72,53 @@ AntlrInputStream* AntlrInputStream::newFileInputStream(const std::string& name,
return new AntlrInputStream( name, input );
}
-AntlrInputStream* AntlrInputStream::newStringInputStream(const std::string& input, const std::string& name)
+AntlrInputStream*
+AntlrInputStream::newStreamInputStream(std::istream& input,
+ const std::string& name)
+ throw (InputStreamException) {
+ // // TODO: make this more portable
+ // char *filename = strdup("/tmp/streaminput.XXXXXX");
+ // int fd = mkstemp(filename);
+ // if( fd == -1 ) {
+ // throw InputStreamException("Couldn't create temporary for stream input: " + name);
+ // }
+
+ // // We don't want to use the temp file directly, so first close it
+ // close(fd);
+
+ // // Make a FIFO with our reserved temporary name
+ // int fd = mkfifo(filename, s_IRUSR);
+
+ // // Just stuff everything from the istream into the FIFO
+ // char buf[4096];
+ // while( !input.eof() && !input.fail() ) {
+ // input.read( buf, sizeof(buf) );
+ // write( fd, buf, input.gcount() );
+ // }
+
+ // if( !input.eof() ) {
+ // throw InputStreamException("Stream input failed: " + name);
+ // }
+
+ // // Now create the ANTLR stream
+ // pANTLR3_INPUT_STREAM input = antlr3AsciiFileStreamNew((pANTLR3_UINT8) filename);
+
+ // if( input == NULL ) {
+ // throw InputStreamException("Couldn't create stream input: " + name);
+ // }
+
+ // // Create the stream with fileIsTemporary = true
+ // return new AntlrInputStream( name, input, true );
+
+ stringstream ss( ios_base::out );
+ ss << input.rdbuf();
+ return newStringInputStream( ss.str(), name );
+}
+
+
+AntlrInputStream*
+AntlrInputStream::newStringInputStream(const std::string& input,
+ const std::string& name)
throw (InputStreamException) {
char* inputStr = strdup(input.c_str());
char* nameStr = strdup(name.c_str());
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback