1 #ifndef _SUBLEXER_IMPL_H_
2 #define _SUBLEXER_IMPL_H_
10 #include "utf8_string.h"
17 class LexException : public std::exception
20 LexException(size_t pos, std::string str);
21 virtual ~LexException() throw() {}
22 const char* what() const throw();
30 class FirstLexer : public ISubLexer
33 // ここから返されない場合は、一文字の構文構成文字が返されるということになる。
36 virtual ~FirstLexer() {}
38 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
39 smart_ptr<ISubLexer>& next);
43 // lex関数中で利用される、雑多になった字句解析関数の分割
44 smart_ptr<lexeme::ILexeme> lex_(const utakata::utf8_string::UTF8String& str,
45 smart_ptr<utakata::utf8::UTF8InputStream> stream,
46 smart_ptr<ISubLexer>& next);
50 class StringLexer : public ISubLexer
52 // 文字列だと判断された場合に実行されるsublexer。
53 // 文字列が不正に終わったりしている場合には、その時点で例
57 virtual ~StringLexer() {}
59 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
60 smart_ptr<ISubLexer>& next);
63 class OneLineCommentLexer : public ISubLexer
66 // と言っても、;から開始されるコメントは完全に無視されるので、lexeme
70 OneLineCommentLexer(){}
71 virtual ~OneLineCommentLexer(){}
73 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
74 smart_ptr<ISubLexer>& next);
77 class NestedCommentLexer : public ISubLexer
80 // と言っても、;から開始されるコメントは完全に無視されるので、lexeme
84 NestedCommentLexer(){}
85 virtual ~NestedCommentLexer(){}
87 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
88 smart_ptr<ISubLexer>& next);
91 class CharactorLexer : public ISubLexer
93 // 文字名、及び16進数による文字指定の解析を行なう。
94 // #\文字名、#\x<hex>;の両方を解釈する。
98 virtual ~CharactorLexer(){}
100 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
101 smart_ptr<ISubLexer>& next);
105 class NumberLexer : public ISubLexer
108 // ここで解析する数値は、<number>に相当する。
109 const unsigned char BINARY;
110 const unsigned char OCTET;
111 const unsigned char DECIMAL;
112 const unsigned char HEX;
115 NumberLexer(const utakata::utf8_string::UTF8String& str);
116 virtual ~NumberLexer(){}
118 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
119 smart_ptr<ISubLexer>& next);
122 smart_ptr<lexeme::ILexeme> innerLex_(smart_ptr<utakata::utf8::UTF8InputStream> stream,
123 smart_ptr<ISubLexer>& next,
124 const utakata::utf8_string::UTF8String& str);
127 // 渡した文字列からprefixを抽出して返す。
128 unsigned char getPrefix_(const utakata::utf8_string::UTF8String& str);
130 void checkExactness_(const utakata::utf8_string::UTF8String& str);
134 smart_ptr<utakata::utf8_string::UTF8String> str_;
136 bool exact_; // 正確性を設定する。
137 unsigned char prefix_; // prefixを設定する。
141 class IdentifierLexer : public ISubLexer
144 // と言っても、;から開始されるコメントは完全に無視されるので、lexeme
148 IdentifierLexer(const utakata::utf8_string::UTF8String& str);
149 virtual ~IdentifierLexer(){}
151 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
152 smart_ptr<ISubLexer>& next);
156 smart_ptr<utakata::utf8_string::UTF8String> str_;
159 class BooleanLexer : public ISubLexer
162 // いずれかの次には、必ず区切り文字がなければならない。
165 BooleanLexer(const utakata::utf8_string::UTF8Char& ch);
166 virtual ~BooleanLexer(){}
168 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
169 smart_ptr<ISubLexer>& next);
173 smart_ptr<utakata::utf8_string::UTF8Char> ch_;
176 class ByteVectorLexer : public ISubLexer
179 // vu8ではない場合には、エラーとなる。
182 ByteVectorLexer(const utakata::utf8_string::UTF8Char& ch);
183 virtual ~ByteVectorLexer(){}
185 smart_ptr<lexeme::ILexeme> lex(smart_ptr<utakata::utf8::UTF8InputStream> stream,
186 smart_ptr<ISubLexer>& next);
190 smart_ptr<utakata::utf8_string::UTF8Char> ch_;
198 #endif /* _SUBLEXER_IMPL_H_ */