From 8aa47d3a0a19a9d0b88a65ddf28d6d7c6eaffdfa Mon Sep 17 00:00:00 2001 From: Adam Wardynski <award@.(win7-laptop)> Date: Fri, 6 May 2011 01:20:51 +0200 Subject: [PATCH] Keep file name with Lexicon. --- libwccl/lexicon/lexfilegrammar.g | 4 ++-- libwccl/lexicon/lexicon.h | 10 ++++++++-- libwccl/lexicon/lexiconparser.cpp | 2 +- libwccl/lexicon/lexicons.h | 4 ++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/libwccl/lexicon/lexfilegrammar.g b/libwccl/lexicon/lexfilegrammar.g index 19640c6..ce36648 100644 --- a/libwccl/lexicon/lexfilegrammar.g +++ b/libwccl/lexicon/lexfilegrammar.g @@ -53,10 +53,10 @@ private: /////////////////////////////////////////////////////////////////////////////// parse_lexicon_file - [const std::string& name] + [const std::string& name, const std::string& file_name] returns [boost::shared_ptr<Lexicon> lex] { - lex.reset(new Lexicon(name)); + lex.reset(new Lexicon(name, file_name)); } : (lexicon_entry [*lex])* EOF diff --git a/libwccl/lexicon/lexicon.h b/libwccl/lexicon/lexicon.h index c02f628..d691f4b 100644 --- a/libwccl/lexicon/lexicon.h +++ b/libwccl/lexicon/lexicon.h @@ -14,8 +14,9 @@ class Lexicon : boost::noncopyable public: typedef boost::unordered_map<UnicodeString, UnicodeString> map_t; - Lexicon(const std::string& name) - : name_(name) + Lexicon(const std::string& name, const std::string& file_name) + : name_(name), + file_name_(file_name_) { BOOST_ASSERT(!name_.empty()); } @@ -40,6 +41,10 @@ public: return name_; } + std::string file_name() const { + return file_name_; + } + bool has_key(const UnicodeString& key) const { return map_.find(key) != map_.end(); } @@ -55,6 +60,7 @@ public: private: map_t map_; const std::string name_; + const std::string file_name_; }; } /* end ns Wccl */ diff --git a/libwccl/lexicon/lexiconparser.cpp b/libwccl/lexicon/lexiconparser.cpp index acb54cc..578d322 100644 --- a/libwccl/lexicon/lexiconparser.cpp +++ b/libwccl/lexicon/lexiconparser.cpp @@ -22,7 +22,7 @@ boost::shared_ptr<Lexicon> LexiconParser::parse_lexicon( ANTLRLexiconLexer lexer(is); ANTLRLexiconParser parser(lexer); - return parser.parse_lexicon_file(lexicon_name); + return parser.parse_lexicon_file(lexicon_name, filename); } } /* end ns Wccl */ diff --git a/libwccl/lexicon/lexicons.h b/libwccl/lexicon/lexicons.h index 1fd0c5f..96f4fa1 100644 --- a/libwccl/lexicon/lexicons.h +++ b/libwccl/lexicon/lexicons.h @@ -26,6 +26,10 @@ public: void insert(const boost::shared_ptr<Lexicon>& lexicon); + const map_t& get_lexicons() const { + return lexicons_; + } + private: map_t lexicons_; }; -- GitLab