OSDN Git Service

utakataの標準となる例外クラス及びマクロを定義した。
[simplecms/utakata.git] / src / lexer_interface.h
1 // SchemeLexer内部で利用されるインターフェースを定義します。
2 // IPartOfLexerインターフェースは、各非終端記号の字句解析を
3 // 行う、部分的な字句解析器のインターフェースです。
4 // ILexerCreatorは、IPartsOfLexerと、そのLexerの適用条件を
5 // 記述したLexerDispatchTermを返します。
6 // ILexerCreatorは、IPartsOfLexerと1:1で対応していなければなりません。
7 //
8 // IPartsOfLexerは、実際に字句解析を行います。解析結果として、ILexemeを
9 // 返すようにします。
10 #ifndef _UTAKATA_SRC_LEXER_INTERFACE_H_
11 #define _UTAKATA_SRC_LEXER_INTERFACE_H_
12
13 #include <string>
14 #include "src/common/smart_ptr.h"
15
16 namespace utakata {
17
18 namespace unicode {
19 class UniString;
20 }
21
22 namespace reader {
23 class StreamReader;
24 };
25
26 namespace lexeme {
27 class ILexeme;
28 };
29
30 namespace lexer {
31
32 class LexException : public exception::Exception {
33  public:
34   LexException(const std::string& message,
35                const utakata::exception::ExceptionInfo& info) :
36       Exception(message, info) {}
37   LexException(const utakata::exception::Exception& exception,
38                const std::string& message,
39                const utakata::exception::ExceptionInfo& info) :
40       Exception(exception, message, info) {}
41 };
42
43 class ILexerDispatchTerm {
44   // 各LexerへのDispatchを行うための判定を行うためのクラスです。
45   // 各Lexerに対応するILexerDispatchTermが一つ存在する必要があります。
46  public:
47   virtual ~ILexerDispatchTerm() {}
48
49   // ディスパッチを行うかどうかを判定します。
50   virtual bool IsDispatch(const unicode::UniString& string) const = 0;
51 };
52
53 class IPartOfLexer {
54   // 各非終端記号の字句解析を行うクラスのインターフェースです。
55   // IPartOfLexerを継承したクラスは、Lexメソッドを実装する必要があります。
56   // Lexは必ず何らかのILexeme派生クラスを返す必要があります。
57  public:
58   virtual ~IPartOfLexer() {}
59
60   // 読出しストリームへのポインタを受け取って、結果として生成した
61   // ILexemeインターフェースの派生クラスを返します。
62   virtual utility::smart_ptr<lexeme::ILexeme> Lex(
63       const unicode::UniString& string, reader::StreamReader* stream) = 0;
64 };
65
66 class ILexerCreator {
67   // IPartOfLexerの生成と、生成したLexerの条件を設定した
68   // LexerDispatchTerm生成するインターフェースとなります。
69   // LexerDispatchTermには、Lexerの条件を設定する必要があります。
70  public:
71   virtual ~ILexerCreator() {}
72
73   // 各非終端記号に該当するIPartOfLexer派生のLexerを作成します。
74   virtual IPartOfLexer* Create() const = 0;
75
76   // このILexerCreatorが生成するIPartOfLexerへとDispatchする条件を記載
77   // したDispatchTermを返します。
78   virtual ILexerDispatchTerm* GetTerm() const = 0;
79 };
80 };
81 };
82
83 #endif /* __HOME_DERUI_DEVELOP_UTAKATA_SRC_LEXER_INTERFACE_H_ */