OSDN Git Service

-- NestedCommentLexer、StringLexerの実装を完了。
[simplecms/utakata.git] / sublexer.h
1 #ifndef _SUBLEXER_H_
2 #define _SUBLEXER_H_
3
4 #include "smart_ptr.h"
5
6 // これはあくまで抽象なので、定義に依存させる。
7 namespace utakata {
8
9     namespace lexeme {
10         class ILexeme;
11     };
12
13     namespace utf8 {
14         class UTF8InputStream;
15     };
16
17 };
18
19 namespace utakata {
20
21     namespace sublexer {
22
23         class ISubLexer
24         {
25             /**
26                lexerのlex内で、数々の条件分岐を行わなければならない場合に、
27                それぞれのsublexerからの結果、追加で返されるsublexerを、
28                次の文字における判定として利用することにしておく。
29                このようにすることで、インターフェースを完全に統一しながら、
30                sublexerからsublexerを返すようにしていくだけで、
31                lex内部をシンプルにすることができる。
32
33                これは完全にインターフェースのみを提供する。
34             */
35                
36         public:
37             ISubLexer() {}
38             virtual ~ISubLexer() {}
39
40             // ストリームを受け取り、lexemeを返す。
41             // 次に処理すべきlexerが存在する場合、nextに設定しておくと、
42             // 返されたlexemeは無視され、nextが実行される。
43             virtual smart_ptr<lexeme::ILexeme> lex(
44                 smart_ptr<utakata::utf8::UTF8InputStream> stream,
45                 smart_ptr<ISubLexer>& next) = 0;
46         };
47
48     };
49
50 };
51
52 #endif /* _SUBLEXER_H_ */