From 6517316fb0d2ddeb530276d4711e188e6dc92cd0 Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Mon, 23 May 2011 21:04:29 +0200 Subject: [PATCH] add parse file from path --- libwccl/parser/Parser.cpp | 15 +++++++++++++++ libwccl/parser/Parser.h | 13 +++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/libwccl/parser/Parser.cpp b/libwccl/parser/Parser.cpp index de20b63..8086cb2 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 bcf22d9..09969a2 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 { -- GitLab