OSDN Git Service

a7a4e01fb621b81a28483e52cbc1d2b4e1279b82
[simplecms/utakata.git] / sublexer.h
1 #ifndef _SUBLEXER_H_
2 #define _SUBLEXER_H_
3
4 #include "smart_ptr.h"
5 //#include "utf8.h"
6 //#include "utf8_string.h"
7 //#include "lexeme.h"
8
9
10 // これはあくまで抽象なので、定義に依存させる。
11 namespace utakata {
12
13     namespace lexeme {
14         class ILexeme;
15     };
16
17     namespace utf8 {
18         class CUTF8InputStream;
19     };
20
21     namespace utf8_string {
22         class CUTF8Char;
23         class CUTF8String;
24     };
25 };
26
27
28 namespace utakata {
29
30     namespace sublexer {
31
32         class ISubLexer
33         {
34             /**
35                lexerのlex内で、数々の条件分岐を行わなければならない場合に、
36                それぞれのsublexerからの結果、追加で返されるsublexerを、
37                次の文字における判定として利用することにしておく。
38                このようにすることで、インターフェースを完全に統一しながら、
39                sublexerからsublexerを返すようにしていくだけで、
40                lex内部をシンプルにすることができる。
41
42                これは完全にインターフェースのみを提供する。
43             */
44                
45         public:
46             ISubLexer() {}
47             virtual ~ISubLexer() {}
48
49             // 処理の実体となる。
50             // strは前回のsublexが返した文字列であり、前のsublexによって更新される。
51             // streamは文字通りストリームとなる。sublex中で文字の取得などを
52             // 自由に行う必要があるために渡している。
53             virtual smart_ptr<ISubLexer> lex(const utakata::utf8_string::CUTF8Char& ch,
54                                              const utakata::utf8_string::CUTF8String& str,
55                                              smart_ptr<utakata::utf8::CUTF8InputStream>& stream) = 0;
56           
57             // 作成したILexemeを返す。lexの結果を返さない場合に利用される。
58             // これだけは前方参照のみでなんとか乗り切る必要がある。
59             virtual smart_ptr<utakata::lexeme::ILexeme> getLexeme() = 0;
60
61         };
62
63     };
64
65 };
66
67 #endif /* _SUBLEXER_H_ */