diff options
author | 2012-03-02 16:01:49 +0800 | |
---|---|---|
committer | 2012-03-02 16:01:49 +0800 | |
commit | e6d7f3a96a8850199da5d71d717243333943549c (patch) | |
tree | d48f234fca9ad253782f52965448b20300d3f048 /src | |
parent | Walker: allow bash expansions in regular expressions (diff) | |
download | libbash-e6d7f3a96a8850199da5d71d717243333943549c.tar.gz libbash-e6d7f3a96a8850199da5d71d717243333943549c.tar.bz2 libbash-e6d7f3a96a8850199da5d71d717243333943549c.zip |
Parser&Walker: support literals in regular exp
Diffstat (limited to 'src')
-rw-r--r-- | src/core/bash_ast.cpp | 15 | ||||
-rw-r--r-- | src/core/bash_ast.h | 6 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/core/bash_ast.cpp b/src/core/bash_ast.cpp index 5cca4f4..23571ef 100644 --- a/src/core/bash_ast.cpp +++ b/src/core/bash_ast.cpp @@ -36,31 +36,34 @@ #include "libbashParser.h" #include "libbashWalker.h" -void bash_ast::read_script(const std::istream& source) +void bash_ast::read_script(const std::istream& source, bool trim) { std::stringstream stream; stream << source.rdbuf(); script = stream.str(); boost::algorithm::erase_all(script, "\\\n"); - boost::trim_if(script, boost::is_any_of(" \t\n")); + if(trim) + boost::trim_if(script, boost::is_any_of(" \t\n")); } bash_ast::bash_ast(const std::istream& source, - std::function<pANTLR3_BASE_TREE(plibbashParser)> p): parse(p) + std::function<pANTLR3_BASE_TREE(plibbashParser)> p, + bool trim): parse(p) { - read_script(source); + read_script(source, trim); init_parser("unknown source"); } bash_ast::bash_ast(const std::string& script_path, - std::function<pANTLR3_BASE_TREE(plibbashParser)> p): parse(p) + std::function<pANTLR3_BASE_TREE(plibbashParser)> p, + bool trim): parse(p) { std::stringstream stream; std::ifstream file_stream(script_path); if(!file_stream) throw libbash::parse_exception(script_path + " can't be read"); - read_script(file_stream); + read_script(file_stream, trim); init_parser(script_path); } diff --git a/src/core/bash_ast.h b/src/core/bash_ast.h index 50ca7a6..073553c 100644 --- a/src/core/bash_ast.h +++ b/src/core/bash_ast.h @@ -67,7 +67,7 @@ class bash_ast: public boost::noncopyable typedef std::unique_ptr<libbashWalker_Ctx_struct, std::function<void(libbashWalker_Ctx_struct*)>> walker_pointer; - void read_script(const std::istream& source); + void read_script(const std::istream& source, bool trim); void init_parser(const std::string& script_path); walker_pointer create_walker(interpreter& walker, antlr_pointer<ANTLR3_COMMON_TREE_NODE_STREAM_struct>& nodes); @@ -77,13 +77,13 @@ public: /// \param source input source /// \param p the parser rule for building the AST bash_ast(const std::istream& source, - std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start); + std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start, bool trim=true); /// \brief build AST from string /// \param script_path input source /// \param p the parser rule for building the AST bash_ast(const std::string& script_path, - std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start); + std::function<pANTLR3_BASE_TREE(libbashParser_Ctx_struct*)> p=parser_start, bool trim=true); /// \brief the functor for walker start rule /// \param tree_parser the pointer to the tree_parser |