OSDN Git Service

delimiter.h/cppを、term_lexer、term_checkerとしてテンプレートを利用するように分離した。
[simplecms/utakata.git] / src / lexer / identifier_lexer.h
1 // Scheme構文におけるidentityの解釈を行うlexerを定義します。
2 // ここで定義されるLexerは、IPartsOfLexerから派生しており、以下の条件
3 // をもってLexerDispatcherからディスパッチします。
4 // :検索対象文字列の先頭 = <identifier> の場合:
5 #ifndef _UTAKATA_SRC_LEXER_IDENTIFIER_LEXER_H_
6 #define _UTAKATA_SRC_LEXER_IDENTIFIER_LEXER_H_
7
8 #include "src/lexer/lexer_interface.h"
9
10 namespace utakata {
11 namespace unicode {
12 class UniString;
13 class UniChar;
14 };
15
16 namespace reader {
17 class EncodingReader;
18 }
19
20 namespace lexer {
21 class Lexeme;
22
23 class IdentifierDispatchTerm {
24  public:
25   IdentifierDispatchTerm() {}
26   virtual ~IdentifierDispatchTerm() {}
27
28   // ディスパッチを行うかどうかを判定します。
29   virtual bool IsDispatch(const unicode::UniString& string) const;
30 };
31
32 class IdentifierLexer : public IPartsOfLexer {
33   // Scheme構文における識別子のチェックを行います。
34   // Scheme構文における識別子は、以下の形式を取ります。
35   // ・先頭が次のいずれかである。
36   //   !  $  %  &  *  /  :  <  =  >  ?  ^  _  ~ ->
37   // ・識別子全体が以下である。
38   //   + - ...
39   // ・先頭に続けた、デリミタ以外のunicode及びinline hex escapeを含めた
40   //   文字。
41   // inline hex escape は \x<hex>;の形式を取ります。
42   // inline hex escapeについては、inline_hex_escape_lexer.h において定義
43   // されているInlineHexEscapeLexerを参照してください。
44  public:
45
46   IdentifierLexer() {}
47   virtual ~IdentifierLexer() {}
48
49   // 読出しストリームへのポインタを受け取って、結果として生成した
50   // ILexemeインターフェースの派生クラスを返します。
51   virtual Lexeme* Lex(const unicode::UniString& string,
52                                reader::EncodingReader* reader);
53
54   // このIPartOfLexerへとDispatchする条件を記載したDispatchTermを作成して
55   // 返します。返されたポインタは、取得側で削除する必要があります。
56   // 返された値の保持については、akebono::scoped_ptrの利用を推奨します。
57   virtual ILexerDispatchTerm* GetTerm() const;
58 };
59
60 class IdentifierLexerFactory : public ILexerFactory {
61   // IdentifierLexerをIPartsOfLexerとして生成するファクトリです。
62  public:
63   IdentifierLexerFactory() {}
64   virtual ~IdentifierLexerFactory() {}
65
66   // ChractorLexerを新たに割り当てて返します。
67   // 返されたインスタンスは、取得側で開放する必要があります。
68   virtual IPartsOfLexer* Create() const {return new IdentifierLexer();}
69 };
70 }
71 }
72
73 #endif /* _UTAKATA_SRC_LEXER_IDENTIFIER_LEXER_H_ */