OSDN Git Service

8bf92f1295ed44d79644cdfd43d1ebe0ebbfcee3
[simplecms/utakata.git] / src / lexeme_data.h
1 #ifndef _LEXEME_DATA_H_
2 #define _LEXEME_DATA_H_
3
4 #include <string>
5 #include "src/common/smart_ptr.h"
6
7 namespace utakata {
8
9 namespace unicode {
10 class UniString;
11 class UniChar;
12 };
13
14 namespace lexeme {
15
16 struct StringData {
17   // 文字列を保持するためのデータ型. たんにそのまま.
18   smart_ptr<unicode::UniString> str;
19 };
20
21 struct NumberData {
22   // 数値のデータの受け渡しを行うためのデータ型.
23   // 数値データは, それぞれ実数部分と虚数部分, そして
24   // 正確性と radix を定義する必要がある.
25   // radix = 10 ではない場合, 常に exact = true として振る舞う.
26   smart_ptr<unicode::UniString> real;
27   smart_ptr<unicode::UniString> imagin;
28   bool exact;
29   int radix;
30 };
31
32 struct BooleanData {
33   // Boolean を表すデータ. これでは bool 型の変数によって#t と#f を表現
34   // することにする.
35   bool boolean;
36   smart_ptr<unicode::UniString> str;
37 };
38
39 struct CharactorData {
40   // Charactor を構成するためのデータ.
41   // この時点で、渡された文字列から数値に変換が完了しているものとする。
42   smart_ptr<unicode::UniChar> spec;
43 };
44
45 struct SymbolData {
46   // シンボルを構成するためのデータ.
47   smart_ptr<unicode::UniString> id;
48 };
49
50 struct LexemeData {
51   // リテラルとして存在するデータの一部のみを
52   // 内包する.
53   // このデータは, 実際には Lexeme と Object 間でのデータの受け渡しを
54   // 行うためのインタフェースとなっている.
55   // この上のlexemeによって、返される値が確定されると仮定するため、
56   // タグ情報などは含まない。
57
58   smart_ptr<StringData>    string;
59   smart_ptr<NumberData>    number;
60   smart_ptr<BooleanData>   boolean;
61   smart_ptr<CharactorData> charactor;
62   smart_ptr<SymbolData>    symbol;
63 };
64
65 // 各データ入りのLiteralDataを返すヘルパー関数。
66 smart_ptr<LexemeData> makeStringData(const unicode::UniString& str);
67 smart_ptr<LexemeData> makeNumberData(const unicode::UniString& real,
68                                      const unicode::UniString& imagin,
69                                      bool exact, bool radix);
70 smart_ptr<LexemeData> makeBooleanData(const unicode::UniString& str,
71                                       bool boolean);
72 smart_ptr<LexemeData> makeCharactorData(const unicode::UniChar& ch);
73 smart_ptr<LexemeData> makeSymbolData(const unicode::UniString& str);
74 };
75 };
76
77 #endif /* _LEXEME_DATA_H_ */