s2 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +22 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/s2/s2_parse/Makefile +52 -0
- data/ext/s2/s2_parse/Parser.cpp +525 -0
- data/ext/s2/s2_parse/Parser.h +130 -0
- data/ext/s2/s2_parse/S2.hpp +246 -0
- data/ext/s2/s2_parse/Scanner.cpp +796 -0
- data/ext/s2/s2_parse/Scanner.h +263 -0
- data/ext/s2/s2_parse/extconf.rb +5 -0
- data/ext/s2/s2_parse/parse_s2.cpp +630 -0
- data/ext/s2/s2_parse/parse_s2.hpp +42 -0
- data/ext/s2/s2_parse/picojson.hpp +1299 -0
- data/ext/s2/s2_parse/s2.atg +321 -0
- data/ext/s2/s2_parse/s2.ruco +93 -0
- data/ext/s2/s2_parse/s2_parse.cpp +70 -0
- data/lib/s2.rb +5 -0
- data/lib/s2/display.rb +21 -0
- data/lib/s2/internal/c.rb +128 -0
- data/lib/s2/s2_parse.rb +18 -0
- data/lib/s2/version.rb +3 -0
- metadata +151 -0
@@ -0,0 +1,263 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#if !defined(S2_COCO_SCANNER_H__)
|
4
|
+
#define S2_COCO_SCANNER_H__
|
5
|
+
|
6
|
+
#include <limits.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include <string.h>
|
10
|
+
#include <wchar.h>
|
11
|
+
|
12
|
+
// io.h and fcntl are used to ensure binary read from streams on windows
|
13
|
+
#if _MSC_VER >= 1300
|
14
|
+
#include <io.h>
|
15
|
+
#include <fcntl.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#if _MSC_VER >= 1400
|
19
|
+
#define coco_swprintf swprintf_s
|
20
|
+
#elif _MSC_VER >= 1300
|
21
|
+
#define coco_swprintf _snwprintf
|
22
|
+
#elif defined __MINGW32__
|
23
|
+
#define coco_swprintf _snwprintf
|
24
|
+
#else
|
25
|
+
// assume every other compiler knows swprintf
|
26
|
+
#define coco_swprintf swprintf
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#define COCO_WCHAR_MAX 65535
|
30
|
+
#define COCO_MIN_BUFFER_LENGTH 1024
|
31
|
+
#define COCO_MAX_BUFFER_LENGTH (64*COCO_MIN_BUFFER_LENGTH)
|
32
|
+
#define COCO_HEAP_BLOCK_SIZE (64*1024)
|
33
|
+
#define COCO_CPP_NAMESPACE_SEPARATOR L':'
|
34
|
+
|
35
|
+
namespace S2 {
|
36
|
+
|
37
|
+
|
38
|
+
// string handling, wide character
|
39
|
+
wchar_t* coco_string_create(const wchar_t *value);
|
40
|
+
wchar_t* coco_string_create(const wchar_t *value, int startIndex);
|
41
|
+
wchar_t* coco_string_create(const wchar_t *value, int startIndex, int length);
|
42
|
+
wchar_t* coco_string_create_upper(const wchar_t* data);
|
43
|
+
wchar_t* coco_string_create_lower(const wchar_t* data);
|
44
|
+
wchar_t* coco_string_create_lower(const wchar_t* data, int startIndex, int dataLen);
|
45
|
+
wchar_t* coco_string_create_append(const wchar_t* data1, const wchar_t* data2);
|
46
|
+
wchar_t* coco_string_create_append(const wchar_t* data, const wchar_t value);
|
47
|
+
void coco_string_delete(wchar_t* &data);
|
48
|
+
int coco_string_length(const wchar_t* data);
|
49
|
+
bool coco_string_endswith(const wchar_t* data, const wchar_t *value);
|
50
|
+
int coco_string_indexof(const wchar_t* data, const wchar_t value);
|
51
|
+
int coco_string_lastindexof(const wchar_t* data, const wchar_t value);
|
52
|
+
void coco_string_merge(wchar_t* &data, const wchar_t* value);
|
53
|
+
bool coco_string_equal(const wchar_t* data1, const wchar_t* data2);
|
54
|
+
int coco_string_compareto(const wchar_t* data1, const wchar_t* data2);
|
55
|
+
int coco_string_hash(const wchar_t* data);
|
56
|
+
|
57
|
+
// string handling, ascii character
|
58
|
+
wchar_t* coco_string_create(const char *value);
|
59
|
+
char* coco_string_create_char(const wchar_t *value);
|
60
|
+
void coco_string_delete(char* &data);
|
61
|
+
|
62
|
+
|
63
|
+
class Token
|
64
|
+
{
|
65
|
+
public:
|
66
|
+
int kind; // token kind
|
67
|
+
int pos; // token position in bytes in the source text (starting at 0)
|
68
|
+
int charPos; // token position in characters in the source text (starting at 0)
|
69
|
+
int col; // token column (starting at 1)
|
70
|
+
int line; // token line (starting at 1)
|
71
|
+
wchar_t* val; // token value
|
72
|
+
Token *next; // ML 2005-03-11 Peek tokens are kept in linked list
|
73
|
+
|
74
|
+
Token();
|
75
|
+
~Token();
|
76
|
+
};
|
77
|
+
|
78
|
+
class Buffer {
|
79
|
+
// This Buffer supports the following cases:
|
80
|
+
// 1) seekable stream (file)
|
81
|
+
// a) whole stream in buffer
|
82
|
+
// b) part of stream in buffer
|
83
|
+
// 2) non seekable stream (network, console)
|
84
|
+
private:
|
85
|
+
char *buf; // input buffer
|
86
|
+
int bufCapacity; // capacity of buf
|
87
|
+
int bufStart; // position of first byte in buffer relative to input stream
|
88
|
+
int bufLen; // length of buffer
|
89
|
+
int fileLen; // length of input stream (may change if the stream is no file)
|
90
|
+
int bufPos; // current position in buffer
|
91
|
+
FILE* stream; // input stream (seekable)
|
92
|
+
bool isUserStream; // was the stream opened by the user?
|
93
|
+
|
94
|
+
int ReadNextStreamChunk();
|
95
|
+
bool CanSeek(); // true if stream can be seeked otherwise false
|
96
|
+
|
97
|
+
public:
|
98
|
+
static const int EoF = COCO_WCHAR_MAX + 1;
|
99
|
+
|
100
|
+
Buffer(FILE* s, bool isUserStream);
|
101
|
+
Buffer(const char* buf, size_t len);
|
102
|
+
Buffer(Buffer *b);
|
103
|
+
virtual ~Buffer();
|
104
|
+
|
105
|
+
virtual void Close();
|
106
|
+
virtual int Read();
|
107
|
+
virtual int Peek();
|
108
|
+
virtual wchar_t* GetString(int beg, int end);
|
109
|
+
virtual int GetPos();
|
110
|
+
virtual void SetPos(int value);
|
111
|
+
};
|
112
|
+
|
113
|
+
class UTF8Buffer : public Buffer {
|
114
|
+
public:
|
115
|
+
UTF8Buffer(Buffer *b) : Buffer(b) {};
|
116
|
+
virtual int Read();
|
117
|
+
};
|
118
|
+
|
119
|
+
//-----------------------------------------------------------------------------------
|
120
|
+
// StartStates -- maps characters to start states of tokens
|
121
|
+
//-----------------------------------------------------------------------------------
|
122
|
+
class StartStates {
|
123
|
+
private:
|
124
|
+
class Elem {
|
125
|
+
public:
|
126
|
+
int key, val;
|
127
|
+
Elem *next;
|
128
|
+
Elem(int key, int val) { this->key = key; this->val = val; next = NULL; }
|
129
|
+
};
|
130
|
+
|
131
|
+
Elem **tab;
|
132
|
+
|
133
|
+
public:
|
134
|
+
StartStates() { tab = new Elem*[128]; memset(tab, 0, 128 * sizeof(Elem*)); }
|
135
|
+
virtual ~StartStates() {
|
136
|
+
for (int i = 0; i < 128; ++i) {
|
137
|
+
Elem *e = tab[i];
|
138
|
+
while (e != NULL) {
|
139
|
+
Elem *next = e->next;
|
140
|
+
delete e;
|
141
|
+
e = next;
|
142
|
+
}
|
143
|
+
}
|
144
|
+
delete [] tab;
|
145
|
+
}
|
146
|
+
|
147
|
+
void set(int key, int val) {
|
148
|
+
Elem *e = new Elem(key, val);
|
149
|
+
int k = ((unsigned int) key) % 128;
|
150
|
+
e->next = tab[k]; tab[k] = e;
|
151
|
+
}
|
152
|
+
|
153
|
+
int state(int key) {
|
154
|
+
Elem *e = tab[((unsigned int) key) % 128];
|
155
|
+
while (e != NULL && e->key != key) e = e->next;
|
156
|
+
return e == NULL ? 0 : e->val;
|
157
|
+
}
|
158
|
+
};
|
159
|
+
|
160
|
+
//-------------------------------------------------------------------------------------------
|
161
|
+
// KeywordMap -- maps strings to integers (identifiers to keyword kinds)
|
162
|
+
//-------------------------------------------------------------------------------------------
|
163
|
+
class KeywordMap {
|
164
|
+
private:
|
165
|
+
class Elem {
|
166
|
+
public:
|
167
|
+
wchar_t *key;
|
168
|
+
int val;
|
169
|
+
Elem *next;
|
170
|
+
Elem(const wchar_t *key, int val) { this->key = coco_string_create(key); this->val = val; next = NULL; }
|
171
|
+
virtual ~Elem() { coco_string_delete(key); }
|
172
|
+
};
|
173
|
+
|
174
|
+
Elem **tab;
|
175
|
+
|
176
|
+
public:
|
177
|
+
KeywordMap() { tab = new Elem*[128]; memset(tab, 0, 128 * sizeof(Elem*)); }
|
178
|
+
virtual ~KeywordMap() {
|
179
|
+
for (int i = 0; i < 128; ++i) {
|
180
|
+
Elem *e = tab[i];
|
181
|
+
while (e != NULL) {
|
182
|
+
Elem *next = e->next;
|
183
|
+
delete e;
|
184
|
+
e = next;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
delete [] tab;
|
188
|
+
}
|
189
|
+
|
190
|
+
void set(const wchar_t *key, int val) {
|
191
|
+
Elem *e = new Elem(key, val);
|
192
|
+
int k = coco_string_hash(key) % 128;
|
193
|
+
e->next = tab[k]; tab[k] = e;
|
194
|
+
}
|
195
|
+
|
196
|
+
int get(const wchar_t *key, int defaultVal) {
|
197
|
+
Elem *e = tab[coco_string_hash(key) % 128];
|
198
|
+
while (e != NULL && !coco_string_equal(e->key, key)) e = e->next;
|
199
|
+
return e == NULL ? defaultVal : e->val;
|
200
|
+
}
|
201
|
+
};
|
202
|
+
|
203
|
+
class Scanner {
|
204
|
+
private:
|
205
|
+
void *firstHeap;
|
206
|
+
void *heap;
|
207
|
+
void *heapTop;
|
208
|
+
void **heapEnd;
|
209
|
+
|
210
|
+
unsigned char EOL;
|
211
|
+
int eofSym;
|
212
|
+
int noSym;
|
213
|
+
int maxT;
|
214
|
+
StartStates start;
|
215
|
+
KeywordMap keywords;
|
216
|
+
|
217
|
+
Token *t; // current token
|
218
|
+
wchar_t *tval; // text of current token
|
219
|
+
int tvalLength; // length of text of current token
|
220
|
+
int tlen; // length of current token
|
221
|
+
|
222
|
+
Token *tokens; // list of tokens already peeked (first token is a dummy)
|
223
|
+
Token *pt; // current peek token
|
224
|
+
|
225
|
+
int ch; // current input character
|
226
|
+
|
227
|
+
int pos; // byte position of current character
|
228
|
+
int charPos; // position by unicode characters starting with 0
|
229
|
+
int line; // line number of current character
|
230
|
+
int col; // column number of current character
|
231
|
+
int oldEols; // EOLs that appeared in a comment;
|
232
|
+
|
233
|
+
void CreateHeapBlock();
|
234
|
+
Token* CreateToken();
|
235
|
+
void AppendVal(Token *t);
|
236
|
+
void SetScannerBehindT();
|
237
|
+
|
238
|
+
void Init();
|
239
|
+
void NextCh();
|
240
|
+
void AddCh();
|
241
|
+
bool Comment0();
|
242
|
+
bool Comment1();
|
243
|
+
|
244
|
+
Token* NextToken();
|
245
|
+
|
246
|
+
public:
|
247
|
+
Buffer *buffer; // scanner buffer
|
248
|
+
|
249
|
+
Scanner(const char* buf, size_t len);
|
250
|
+
Scanner(const wchar_t* fileName);
|
251
|
+
Scanner(FILE* s);
|
252
|
+
~Scanner();
|
253
|
+
Token* Scan();
|
254
|
+
Token* Peek();
|
255
|
+
void ResetPeek();
|
256
|
+
|
257
|
+
}; // end Scanner
|
258
|
+
|
259
|
+
} // namespace
|
260
|
+
|
261
|
+
|
262
|
+
#endif
|
263
|
+
|
@@ -0,0 +1,630 @@
|
|
1
|
+
|
2
|
+
#include "parse_s2.hpp"
|
3
|
+
|
4
|
+
/*
|
5
|
+
WARNING: This file is generated using ruco. Please modify the .ruco file if you wish to change anything
|
6
|
+
https://github.com/davidsiaw/ruco
|
7
|
+
*/
|
8
|
+
|
9
|
+
namespace S2
|
10
|
+
{
|
11
|
+
S2Ptr Parse(std::string sourceFile)
|
12
|
+
{
|
13
|
+
std::shared_ptr<FILE> fp (fopen(sourceFile.c_str(), "r"), fclose);
|
14
|
+
if (!fp)
|
15
|
+
{
|
16
|
+
throw FileNotFoundException();
|
17
|
+
}
|
18
|
+
std::shared_ptr<Scanner> scanner (new Scanner(fp.get()));
|
19
|
+
std::shared_ptr<Parser> parser (new Parser(scanner.get()));
|
20
|
+
parser->Parse();
|
21
|
+
|
22
|
+
return parser->s2;
|
23
|
+
}
|
24
|
+
|
25
|
+
picojson::object CompileS2(S2Ptr pointer);
|
26
|
+
picojson::object CompileTypeVariable(TypeVariablePtr pointer);
|
27
|
+
picojson::object CompileStructName(StructNamePtr pointer);
|
28
|
+
picojson::object CompileMemberName(MemberNamePtr pointer);
|
29
|
+
picojson::object CompileNumberLiteral(NumberLiteralPtr pointer);
|
30
|
+
picojson::object CompileStringLiteral(StringLiteralPtr pointer);
|
31
|
+
picojson::object CompileTypeIdentifier(TypeIdentifierPtr pointer);
|
32
|
+
picojson::object CompileTypeExpression(TypeExpressionPtr pointer);
|
33
|
+
picojson::object CompileTypeParameterArguments(TypeParameterArgumentsPtr pointer);
|
34
|
+
picojson::object CompileTypeDeclaration(TypeDeclarationPtr pointer);
|
35
|
+
picojson::object CompileTypeParameters(TypeParametersPtr pointer);
|
36
|
+
picojson::object CompileNumberLit(NumberLitPtr pointer);
|
37
|
+
picojson::object CompileExpression(ExpressionPtr pointer);
|
38
|
+
picojson::object CompileAttributeParam(AttributeParamPtr pointer);
|
39
|
+
picojson::object CompileAttributeParamList(AttributeParamListPtr pointer);
|
40
|
+
picojson::object CompileAttribute(AttributePtr pointer);
|
41
|
+
picojson::object CompileMember(MemberPtr pointer);
|
42
|
+
picojson::object CompileStructure(StructurePtr pointer);
|
43
|
+
picojson::object CompileImport(ImportPtr pointer);
|
44
|
+
picojson::object CompileStatement(StatementPtr pointer);
|
45
|
+
|
46
|
+
picojson::object CompileS2(S2Ptr pointer)
|
47
|
+
{
|
48
|
+
picojson::object object;
|
49
|
+
|
50
|
+
// normal
|
51
|
+
object[L"_type"] = picojson::value(L"S2");
|
52
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
53
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
54
|
+
|
55
|
+
|
56
|
+
// {:count=>3, :type=>:id}
|
57
|
+
|
58
|
+
picojson::array statements;
|
59
|
+
|
60
|
+
for(unsigned i=0; i<pointer->statements.size(); i++)
|
61
|
+
{
|
62
|
+
statements.push_back(picojson::value(CompileStatement(pointer->statements[i])));
|
63
|
+
}
|
64
|
+
|
65
|
+
object[L"statements"] = picojson::value(statements);
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
return object;
|
71
|
+
}
|
72
|
+
|
73
|
+
picojson::object CompileTypeVariable(TypeVariablePtr pointer)
|
74
|
+
{
|
75
|
+
picojson::object object;
|
76
|
+
|
77
|
+
// normal
|
78
|
+
object[L"_type"] = picojson::value(L"TypeVariable");
|
79
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
80
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
81
|
+
|
82
|
+
|
83
|
+
// {:count=>1, :type=>:token}
|
84
|
+
object[L"_token"] = picojson::value(pointer->content);
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
return object;
|
90
|
+
}
|
91
|
+
|
92
|
+
picojson::object CompileStructName(StructNamePtr pointer)
|
93
|
+
{
|
94
|
+
picojson::object object;
|
95
|
+
|
96
|
+
// normal
|
97
|
+
object[L"_type"] = picojson::value(L"StructName");
|
98
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
99
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
100
|
+
|
101
|
+
|
102
|
+
// {:count=>1, :type=>:token}
|
103
|
+
object[L"_token"] = picojson::value(pointer->content);
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
return object;
|
109
|
+
}
|
110
|
+
|
111
|
+
picojson::object CompileMemberName(MemberNamePtr pointer)
|
112
|
+
{
|
113
|
+
picojson::object object;
|
114
|
+
|
115
|
+
// normal
|
116
|
+
object[L"_type"] = picojson::value(L"MemberName");
|
117
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
118
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
119
|
+
|
120
|
+
|
121
|
+
// {:count=>1, :type=>:token}
|
122
|
+
object[L"_token"] = picojson::value(pointer->content);
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
return object;
|
128
|
+
}
|
129
|
+
|
130
|
+
picojson::object CompileNumberLiteral(NumberLiteralPtr pointer)
|
131
|
+
{
|
132
|
+
picojson::object object;
|
133
|
+
|
134
|
+
// normal
|
135
|
+
object[L"_type"] = picojson::value(L"NumberLiteral");
|
136
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
137
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
138
|
+
|
139
|
+
|
140
|
+
// {:count=>1, :type=>:token}
|
141
|
+
object[L"_token"] = picojson::value(pointer->content);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
return object;
|
147
|
+
}
|
148
|
+
|
149
|
+
picojson::object CompileStringLiteral(StringLiteralPtr pointer)
|
150
|
+
{
|
151
|
+
picojson::object object;
|
152
|
+
|
153
|
+
// normal
|
154
|
+
object[L"_type"] = picojson::value(L"StringLiteral");
|
155
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
156
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
157
|
+
|
158
|
+
|
159
|
+
// {:count=>1, :type=>:token}
|
160
|
+
object[L"_token"] = picojson::value(pointer->content);
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
return object;
|
166
|
+
}
|
167
|
+
|
168
|
+
picojson::object CompileTypeIdentifier(TypeIdentifierPtr pointer)
|
169
|
+
{
|
170
|
+
picojson::object object;
|
171
|
+
|
172
|
+
// normal
|
173
|
+
object[L"_type"] = picojson::value(L"TypeIdentifier");
|
174
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
175
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
176
|
+
|
177
|
+
|
178
|
+
// {:count=>1, :type=>:id}
|
179
|
+
if (pointer->structname)
|
180
|
+
{
|
181
|
+
picojson::object structname;
|
182
|
+
|
183
|
+
structname = CompileStructName(pointer->structname);
|
184
|
+
|
185
|
+
object[L"structname"] = picojson::value(structname);
|
186
|
+
}
|
187
|
+
// {:count=>1, :type=>:id}
|
188
|
+
if (pointer->typevariable)
|
189
|
+
{
|
190
|
+
picojson::object typevariable;
|
191
|
+
|
192
|
+
typevariable = CompileTypeVariable(pointer->typevariable);
|
193
|
+
|
194
|
+
object[L"typevariable"] = picojson::value(typevariable);
|
195
|
+
}
|
196
|
+
// {:count=>3, :type=>:id}
|
197
|
+
|
198
|
+
picojson::array typeparameterarguments;
|
199
|
+
|
200
|
+
for(unsigned i=0; i<pointer->typeparameterarguments.size(); i++)
|
201
|
+
{
|
202
|
+
typeparameterarguments.push_back(picojson::value(CompileTypeParameterArguments(pointer->typeparameterarguments[i])));
|
203
|
+
}
|
204
|
+
|
205
|
+
object[L"typeparameterarguments"] = picojson::value(typeparameterarguments);
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
return object;
|
211
|
+
}
|
212
|
+
|
213
|
+
picojson::object CompileTypeExpression(TypeExpressionPtr pointer)
|
214
|
+
{
|
215
|
+
picojson::object object;
|
216
|
+
|
217
|
+
// variation
|
218
|
+
object[L"_type"] = picojson::value(L"TypeExpression");
|
219
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
220
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
221
|
+
picojson::object content;
|
222
|
+
switch(pointer->get_typeexpression_type())
|
223
|
+
{
|
224
|
+
case TYPEIDENTIFIER_TYPEEXPRESSION:
|
225
|
+
{
|
226
|
+
content = CompileTypeIdentifier(std::dynamic_pointer_cast<TypeIdentifier>(pointer));
|
227
|
+
break;
|
228
|
+
}
|
229
|
+
|
230
|
+
}
|
231
|
+
|
232
|
+
object[L"_content"] = picojson::value(content);
|
233
|
+
|
234
|
+
return object;
|
235
|
+
}
|
236
|
+
|
237
|
+
picojson::object CompileTypeParameterArguments(TypeParameterArgumentsPtr pointer)
|
238
|
+
{
|
239
|
+
picojson::object object;
|
240
|
+
|
241
|
+
// normal
|
242
|
+
object[L"_type"] = picojson::value(L"TypeParameterArguments");
|
243
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
244
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
245
|
+
|
246
|
+
|
247
|
+
// {:count=>3, :type=>:id}
|
248
|
+
|
249
|
+
picojson::array typeexpressions;
|
250
|
+
|
251
|
+
for(unsigned i=0; i<pointer->typeexpressions.size(); i++)
|
252
|
+
{
|
253
|
+
typeexpressions.push_back(picojson::value(CompileTypeExpression(pointer->typeexpressions[i])));
|
254
|
+
}
|
255
|
+
|
256
|
+
object[L"typeexpressions"] = picojson::value(typeexpressions);
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
return object;
|
262
|
+
}
|
263
|
+
|
264
|
+
picojson::object CompileTypeDeclaration(TypeDeclarationPtr pointer)
|
265
|
+
{
|
266
|
+
picojson::object object;
|
267
|
+
|
268
|
+
// normal
|
269
|
+
object[L"_type"] = picojson::value(L"TypeDeclaration");
|
270
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
271
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
272
|
+
|
273
|
+
|
274
|
+
// {:count=>1, :type=>:id}
|
275
|
+
if (pointer->structname)
|
276
|
+
{
|
277
|
+
picojson::object structname;
|
278
|
+
|
279
|
+
structname = CompileStructName(pointer->structname);
|
280
|
+
|
281
|
+
object[L"structname"] = picojson::value(structname);
|
282
|
+
}
|
283
|
+
// {:count=>3, :type=>:id}
|
284
|
+
|
285
|
+
picojson::array typeparameters;
|
286
|
+
|
287
|
+
for(unsigned i=0; i<pointer->typeparameters.size(); i++)
|
288
|
+
{
|
289
|
+
typeparameters.push_back(picojson::value(CompileTypeParameters(pointer->typeparameters[i])));
|
290
|
+
}
|
291
|
+
|
292
|
+
object[L"typeparameters"] = picojson::value(typeparameters);
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
return object;
|
298
|
+
}
|
299
|
+
|
300
|
+
picojson::object CompileTypeParameters(TypeParametersPtr pointer)
|
301
|
+
{
|
302
|
+
picojson::object object;
|
303
|
+
|
304
|
+
// normal
|
305
|
+
object[L"_type"] = picojson::value(L"TypeParameters");
|
306
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
307
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
308
|
+
|
309
|
+
|
310
|
+
// {:count=>3, :type=>:id}
|
311
|
+
|
312
|
+
picojson::array typevariables;
|
313
|
+
|
314
|
+
for(unsigned i=0; i<pointer->typevariables.size(); i++)
|
315
|
+
{
|
316
|
+
typevariables.push_back(picojson::value(CompileTypeVariable(pointer->typevariables[i])));
|
317
|
+
}
|
318
|
+
|
319
|
+
object[L"typevariables"] = picojson::value(typevariables);
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
return object;
|
325
|
+
}
|
326
|
+
|
327
|
+
picojson::object CompileNumberLit(NumberLitPtr pointer)
|
328
|
+
{
|
329
|
+
picojson::object object;
|
330
|
+
|
331
|
+
// normal
|
332
|
+
object[L"_type"] = picojson::value(L"NumberLit");
|
333
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
334
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
335
|
+
|
336
|
+
|
337
|
+
// {:count=>1, :type=>:id}
|
338
|
+
if (pointer->numberliteral)
|
339
|
+
{
|
340
|
+
picojson::object numberliteral;
|
341
|
+
|
342
|
+
numberliteral = CompileNumberLiteral(pointer->numberliteral);
|
343
|
+
|
344
|
+
object[L"numberliteral"] = picojson::value(numberliteral);
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
return object;
|
351
|
+
}
|
352
|
+
|
353
|
+
picojson::object CompileExpression(ExpressionPtr pointer)
|
354
|
+
{
|
355
|
+
picojson::object object;
|
356
|
+
|
357
|
+
// variation
|
358
|
+
object[L"_type"] = picojson::value(L"Expression");
|
359
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
360
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
361
|
+
picojson::object content;
|
362
|
+
switch(pointer->get_expression_type())
|
363
|
+
{
|
364
|
+
case NUMBERLIT_EXPRESSION:
|
365
|
+
{
|
366
|
+
content = CompileNumberLit(std::dynamic_pointer_cast<NumberLit>(pointer));
|
367
|
+
break;
|
368
|
+
}
|
369
|
+
|
370
|
+
}
|
371
|
+
|
372
|
+
object[L"_content"] = picojson::value(content);
|
373
|
+
|
374
|
+
return object;
|
375
|
+
}
|
376
|
+
|
377
|
+
picojson::object CompileAttributeParam(AttributeParamPtr pointer)
|
378
|
+
{
|
379
|
+
picojson::object object;
|
380
|
+
|
381
|
+
// normal
|
382
|
+
object[L"_type"] = picojson::value(L"AttributeParam");
|
383
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
384
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
385
|
+
|
386
|
+
|
387
|
+
// {:count=>1, :type=>:id}
|
388
|
+
if (pointer->membername)
|
389
|
+
{
|
390
|
+
picojson::object membername;
|
391
|
+
|
392
|
+
membername = CompileMemberName(pointer->membername);
|
393
|
+
|
394
|
+
object[L"membername"] = picojson::value(membername);
|
395
|
+
}
|
396
|
+
// {:count=>1, :type=>:id}
|
397
|
+
if (pointer->expression)
|
398
|
+
{
|
399
|
+
picojson::object expression;
|
400
|
+
|
401
|
+
expression = CompileExpression(pointer->expression);
|
402
|
+
|
403
|
+
object[L"expression"] = picojson::value(expression);
|
404
|
+
}
|
405
|
+
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
return object;
|
410
|
+
}
|
411
|
+
|
412
|
+
picojson::object CompileAttributeParamList(AttributeParamListPtr pointer)
|
413
|
+
{
|
414
|
+
picojson::object object;
|
415
|
+
|
416
|
+
// normal
|
417
|
+
object[L"_type"] = picojson::value(L"AttributeParamList");
|
418
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
419
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
420
|
+
|
421
|
+
|
422
|
+
// {:count=>3, :type=>:id}
|
423
|
+
|
424
|
+
picojson::array attributeparams;
|
425
|
+
|
426
|
+
for(unsigned i=0; i<pointer->attributeparams.size(); i++)
|
427
|
+
{
|
428
|
+
attributeparams.push_back(picojson::value(CompileAttributeParam(pointer->attributeparams[i])));
|
429
|
+
}
|
430
|
+
|
431
|
+
object[L"attributeparams"] = picojson::value(attributeparams);
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
return object;
|
437
|
+
}
|
438
|
+
|
439
|
+
picojson::object CompileAttribute(AttributePtr pointer)
|
440
|
+
{
|
441
|
+
picojson::object object;
|
442
|
+
|
443
|
+
// normal
|
444
|
+
object[L"_type"] = picojson::value(L"Attribute");
|
445
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
446
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
447
|
+
|
448
|
+
|
449
|
+
// {:count=>1, :type=>:id}
|
450
|
+
if (pointer->typeexpression)
|
451
|
+
{
|
452
|
+
picojson::object typeexpression;
|
453
|
+
|
454
|
+
typeexpression = CompileTypeExpression(pointer->typeexpression);
|
455
|
+
|
456
|
+
object[L"typeexpression"] = picojson::value(typeexpression);
|
457
|
+
}
|
458
|
+
// {:count=>3, :type=>:id}
|
459
|
+
|
460
|
+
picojson::array attributeparamlists;
|
461
|
+
|
462
|
+
for(unsigned i=0; i<pointer->attributeparamlists.size(); i++)
|
463
|
+
{
|
464
|
+
attributeparamlists.push_back(picojson::value(CompileAttributeParamList(pointer->attributeparamlists[i])));
|
465
|
+
}
|
466
|
+
|
467
|
+
object[L"attributeparamlists"] = picojson::value(attributeparamlists);
|
468
|
+
|
469
|
+
|
470
|
+
|
471
|
+
|
472
|
+
return object;
|
473
|
+
}
|
474
|
+
|
475
|
+
picojson::object CompileMember(MemberPtr pointer)
|
476
|
+
{
|
477
|
+
picojson::object object;
|
478
|
+
|
479
|
+
// normal
|
480
|
+
object[L"_type"] = picojson::value(L"Member");
|
481
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
482
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
483
|
+
|
484
|
+
|
485
|
+
// {:count=>3, :type=>:id}
|
486
|
+
|
487
|
+
picojson::array attributes;
|
488
|
+
|
489
|
+
for(unsigned i=0; i<pointer->attributes.size(); i++)
|
490
|
+
{
|
491
|
+
attributes.push_back(picojson::value(CompileAttribute(pointer->attributes[i])));
|
492
|
+
}
|
493
|
+
|
494
|
+
object[L"attributes"] = picojson::value(attributes);
|
495
|
+
// {:count=>1, :type=>:id}
|
496
|
+
if (pointer->typeidentifier)
|
497
|
+
{
|
498
|
+
picojson::object typeidentifier;
|
499
|
+
|
500
|
+
typeidentifier = CompileTypeIdentifier(pointer->typeidentifier);
|
501
|
+
|
502
|
+
object[L"typeidentifier"] = picojson::value(typeidentifier);
|
503
|
+
}
|
504
|
+
// {:count=>3, :type=>:id}
|
505
|
+
|
506
|
+
picojson::array membernames;
|
507
|
+
|
508
|
+
for(unsigned i=0; i<pointer->membernames.size(); i++)
|
509
|
+
{
|
510
|
+
membernames.push_back(picojson::value(CompileMemberName(pointer->membernames[i])));
|
511
|
+
}
|
512
|
+
|
513
|
+
object[L"membernames"] = picojson::value(membernames);
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
return object;
|
519
|
+
}
|
520
|
+
|
521
|
+
picojson::object CompileStructure(StructurePtr pointer)
|
522
|
+
{
|
523
|
+
picojson::object object;
|
524
|
+
|
525
|
+
// normal
|
526
|
+
object[L"_type"] = picojson::value(L"Structure");
|
527
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
528
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
529
|
+
|
530
|
+
|
531
|
+
// {:count=>3, :type=>:id}
|
532
|
+
|
533
|
+
picojson::array attributes;
|
534
|
+
|
535
|
+
for(unsigned i=0; i<pointer->attributes.size(); i++)
|
536
|
+
{
|
537
|
+
attributes.push_back(picojson::value(CompileAttribute(pointer->attributes[i])));
|
538
|
+
}
|
539
|
+
|
540
|
+
object[L"attributes"] = picojson::value(attributes);
|
541
|
+
// {:count=>1, :type=>:id}
|
542
|
+
if (pointer->typedeclaration)
|
543
|
+
{
|
544
|
+
picojson::object typedeclaration;
|
545
|
+
|
546
|
+
typedeclaration = CompileTypeDeclaration(pointer->typedeclaration);
|
547
|
+
|
548
|
+
object[L"typedeclaration"] = picojson::value(typedeclaration);
|
549
|
+
}
|
550
|
+
// {:count=>4, :type=>:id}
|
551
|
+
|
552
|
+
picojson::array members;
|
553
|
+
|
554
|
+
for(unsigned i=0; i<pointer->members.size(); i++)
|
555
|
+
{
|
556
|
+
members.push_back(picojson::value(CompileMember(pointer->members[i])));
|
557
|
+
}
|
558
|
+
|
559
|
+
object[L"members"] = picojson::value(members);
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
|
564
|
+
return object;
|
565
|
+
}
|
566
|
+
|
567
|
+
picojson::object CompileImport(ImportPtr pointer)
|
568
|
+
{
|
569
|
+
picojson::object object;
|
570
|
+
|
571
|
+
// normal
|
572
|
+
object[L"_type"] = picojson::value(L"Import");
|
573
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
574
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
575
|
+
|
576
|
+
|
577
|
+
// {:count=>1, :type=>:id}
|
578
|
+
if (pointer->stringliteral)
|
579
|
+
{
|
580
|
+
picojson::object stringliteral;
|
581
|
+
|
582
|
+
stringliteral = CompileStringLiteral(pointer->stringliteral);
|
583
|
+
|
584
|
+
object[L"stringliteral"] = picojson::value(stringliteral);
|
585
|
+
}
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
return object;
|
591
|
+
}
|
592
|
+
|
593
|
+
picojson::object CompileStatement(StatementPtr pointer)
|
594
|
+
{
|
595
|
+
picojson::object object;
|
596
|
+
|
597
|
+
// variation
|
598
|
+
object[L"_type"] = picojson::value(L"Statement");
|
599
|
+
object[L"_col"] = picojson::value((double)pointer->_col);
|
600
|
+
object[L"_line"] = picojson::value((double)pointer->_line);
|
601
|
+
picojson::object content;
|
602
|
+
switch(pointer->get_statement_type())
|
603
|
+
{
|
604
|
+
case STRUCTURE_STATEMENT:
|
605
|
+
{
|
606
|
+
content = CompileStructure(std::dynamic_pointer_cast<Structure>(pointer));
|
607
|
+
break;
|
608
|
+
}
|
609
|
+
case IMPORT_STATEMENT:
|
610
|
+
{
|
611
|
+
content = CompileImport(std::dynamic_pointer_cast<Import>(pointer));
|
612
|
+
break;
|
613
|
+
}
|
614
|
+
|
615
|
+
}
|
616
|
+
|
617
|
+
object[L"_content"] = picojson::value(content);
|
618
|
+
|
619
|
+
return object;
|
620
|
+
}
|
621
|
+
|
622
|
+
|
623
|
+
|
624
|
+
picojson::value Jsonify(S2Ptr parseResult)
|
625
|
+
{
|
626
|
+
return picojson::value(CompileS2(parseResult));
|
627
|
+
}
|
628
|
+
|
629
|
+
}
|
630
|
+
|