[r1]: trunk / Soul / Soul.Parsing / Keyword.hpp Maximize Restore History

Download this file

Keyword.hpp    103 lines (91 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
/*========================================================================
Copyright (c) 2011 Seppo Laakko
http://sourceforge.net/projects/soulparsing/
Distributed under the GNU General Public License, version 3 (GPLv3).
(See accompanying LICENSE.txt or http://www.gnu.org/licenses/gpl.html)
========================================================================*/
#ifndef SOUL_PARSING_KEYWORD_INCLUDED
#define SOUL_PARSING_KEYWORD_INCLUDED
#include <Soul.Parsing/Rule.hpp>
#include <boost/unordered_set.hpp>
namespace Soul { namespace Parsing {
class IdentifierCharsRule : public RuleParser
{
public:
static RuleParserPtr Instance();
};
class KeywordParser : public Parser
{
public:
KeywordParser(const String& keyword_);
KeywordParser(const String& keyword_, const String& continuationRuleName_);
const String& Keyword() const { return keyword; }
const String& ContinuationRuleName() const { return continuationRuleName; }
void SetContinuationRule(const RuleParserPtr& continuationRule_);
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
String keyword;
String continuationRuleName;
RuleParserPtr continuationRule;
ParserPtr keywordStringParser;
RuleParserPtr keywordRule;
void CreateKeywordRule();
};
class KeywordListParser : public Parser
{
public:
typedef boost::unordered_set<String> KeywordSet;
typedef KeywordSet::const_iterator KeywordSetIt;
KeywordListParser(const String& selectorRuleName_, const std::vector<String>& keywords_);
const String& SelectorRuleName() const { return selectorRuleName; }
const String& KeywordVecName() const { return keywordVecName; }
String& KeywordVecName() { return keywordVecName; }
const KeywordSet& Keywords() const { return keywords; }
void SetSelectorRule(const RuleParserPtr& selectorRule_) { selectorRule = selectorRule_; }
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
String selectorRuleName;
String keywordVecName;
KeywordSet keywords;
RuleParserPtr selectorRule;
};
class KeywordRule
{
public:
KeywordRule(): keyword(), ruleName(), rule() {}
KeywordRule(const String& keyword_, const String& ruleName_): keyword(keyword_), ruleName(ruleName_) {}
const String& Keyword() const { return keyword; }
const String& RuleName() const { return ruleName; }
const RuleParserPtr& Rule() const { return rule; }
RuleParserPtr& Rule() { return rule; }
private:
String keyword;
String ruleName;
RuleParserPtr rule;
};
class KeywordRuleListParser : public Parser
{
public:
typedef std::vector<KeywordRule> KeywordRuleVector;
KeywordRuleListParser(const String& selectorRuleName_, const KeywordRuleVector& keywordRules_);
const String& SelectorRuleName() const { return selectorRuleName; }
const String& KeywordRuleVecName() const { return keywordRuleVecName; }
String& KeywordRuleVecName() { return keywordRuleVecName; }
const KeywordRuleVector& KeywordRules() const { return keywordRules; }
void SetSelectorRule(const RuleParserPtr& selectorRule_) { selectorRule = selectorRule_; }
void SetKeywordRule(const String& keyword, const RuleParserPtr& rule);
virtual Match Parse(Scanner& scanner, ObjectStack& stack);
virtual void Accept(Visitor& visitor);
private:
String selectorRuleName;
String keywordRuleVecName;
KeywordRuleVector keywordRules;
RuleParserPtr selectorRule;
typedef boost::unordered_map<String, KeywordRule> KeywordRuleMap;
typedef KeywordRuleMap::iterator KeywordRuleMapIt;
KeywordRuleMap keywordRuleMap;
};
} } // namespace Soul.Parsing
#endif // SOUL_PARSING_KEYWORD_INCLUDED