1 // SchemeLexer内部で利用されるインターフェースを定義します。
2 // IPartOfLexerインターフェースは、各非終端記号の字句解析を
3 // 行う、部分的な字句解析器のインターフェースです。
4 // ILexerCreatorは、IPartsOfLexerと、そのLexerの適用条件を
5 // 記述したLexerDispatchTermを返します。
6 // ILexerCreatorは、IPartsOfLexerと1:1で対応していなければなりません。
8 // IPartsOfLexerは、実際に字句解析を行います。解析結果として、ILexemeを
10 #ifndef _UTAKATA_SRC_LEXER_INTERFACE_H_
11 #define _UTAKATA_SRC_LEXER_INTERFACE_H_
14 #include "src/common/smart_ptr.h"
32 class LexException : public exception::Exception {
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) {}
43 class ILexerDispatchTerm {
44 // 各LexerへのDispatchを行うための判定を行うためのクラスです。
45 // 各Lexerに対応するILexerDispatchTermが一つ存在する必要があります。
47 virtual ~ILexerDispatchTerm() {}
49 // ディスパッチを行うかどうかを判定します。
50 virtual bool IsDispatch(const unicode::UniString& string) const = 0;
54 // 各非終端記号の字句解析を行うクラスのインターフェースです。
55 // IPartOfLexerを継承したクラスは、Lexメソッドを実装する必要があります。
56 // Lexは必ず何らかのILexeme派生クラスを返す必要があります。
58 virtual ~IPartOfLexer() {}
60 // 読出しストリームへのポインタを受け取って、結果として生成した
61 // ILexemeインターフェースの派生クラスを返します。
62 virtual utility::smart_ptr<lexeme::ILexeme> Lex(
63 const unicode::UniString& string, reader::StreamReader* stream) = 0;
67 // IPartOfLexerの生成と、生成したLexerの条件を設定した
68 // LexerDispatchTerm生成するインターフェースとなります。
69 // LexerDispatchTermには、Lexerの条件を設定する必要があります。
71 virtual ~ILexerCreator() {}
73 // 各非終端記号に該当するIPartOfLexer派生のLexerを作成します。
74 virtual IPartOfLexer* Create() const = 0;
76 // このILexerCreatorが生成するIPartOfLexerへとDispatchする条件を記載
77 // したDispatchTermを返します。
78 virtual ILexerDispatchTerm* GetTerm() const = 0;
83 #endif /* __HOME_DERUI_DEVELOP_UTAKATA_SRC_LEXER_INTERFACE_H_ */