diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index de20b637e8aa0ede5afa18a4adaaf09b81042258..8086cb2f6e88e36e023954f2fb18b93d4b03d743 100644 --- a/libwccl/parser/Parser.cpp +++ b/libwccl/parser/Parser.cpp @@ -615,4 +615,19 @@ boost::shared_ptr<WcclFile> Parser::parseWcclFile(std::istream& istr, return res; } +boost::shared_ptr<WcclFile> Parser::parseWcclFileFromPath(const std::string& + filename, const std::string& search_path /*= "."*/) const +{ + std::ifstream is(filename.c_str()); + if (!is.good()) { + throw Wccl::FileNotFound(filename, "", __FUNCTION__); + } + try { + return this->parseWcclFile(is, search_path); + } + catch (ParserException&) { + throw; + } +} + } // end Wccl ns diff --git a/libwccl/parser/Parser.h b/libwccl/parser/Parser.h index bcf22d958a09afcf92a0b1ec50a7adc6729f0fbb..09969a292086696d905342eaef3f0a4bf3e2ec50 100644 --- a/libwccl/parser/Parser.h +++ b/libwccl/parser/Parser.h @@ -5,7 +5,7 @@ // ---------------------------------------------------------------------------- #include <sstream> - +#include <fstream> // ---------------------------------------------------------------------------- #include <libcorpus2/tagset.h> @@ -93,13 +93,22 @@ public: parseMatchRule(std::istream& is) const; // --------------------------------------------------------------------------- - // WCCL file parsing + // Routines for parsing a whole WCCL file -- the RECOMMENDED way of parser + // usage. The standard whole file syntax is used (see WCCL language specs). + // This way different WCCL expressions (any-type functional operators as well + // as tag/match rules) may be parsed in a uniform fashion. + // This also allows to parse WCCL expressions that reference external + // resources (lexicon files). Those resources are sought in the given + // search_path. boost::shared_ptr<WcclFile> parseWcclFile(const std::string& file_contents_string, const std::string& search_path = ".") const; boost::shared_ptr<WcclFile> parseWcclFile(std::istream& is, const std::string& search_path = ".") const; + boost::shared_ptr<WcclFile> + parseWcclFileFromPath(const std::string& filename, + const std::string& search_path = ".") const; // --------------------------------------------------------------------------- const Corpus2::Tagset& tagset() const {