@darabonba/python-generator 2.0.0 → 2.0.2
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.
- package/lib/generator.js +43 -29
- package/package.json +1 -1
- package/tests/expected/complex/tea_python_tests/client.py +5 -4
- package/tests/expected/complex/tea_python_tests/models.py +16 -16
- package/tests/expected/model/tea_python_tests/models.py +41 -58
- package/tests/expected/multi/tea_python_tests/model/user.py +3 -0
- package/tests/fixtures/complex/main.dara +1 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +7 -1
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/model/user.dara +2 -0
- package/tests/output/complex/tea_python_tests/client.py +5 -4
- package/tests/output/complex/tea_python_tests/models.py +16 -16
- package/tests/output/model/tea_python_tests/models.py +41 -58
- package/tests/output/multi/tea_python_tests/model/user.py +3 -0
- package/src/generator.js +0 -231
- package/src/langs/common/combinator.js +0 -193
- package/src/langs/common/config.js +0 -60
- package/src/langs/common/enum.js +0 -179
- package/src/langs/common/items.js +0 -551
- package/src/langs/common/package_info.js +0 -53
- package/src/langs/python/combinator.js +0 -1898
- package/src/langs/python/config.js +0 -169
- package/src/langs/python/files/.gitignore.tmpl +0 -5
- package/src/langs/python/files/__init__.py.tmpl +0 -1
- package/src/langs/python/files/setup.py.tmpl +0 -74
- package/src/langs/python/package_info.js +0 -78
- package/src/langs/python2/combinator.js +0 -1770
- package/src/langs/python2/config.js +0 -162
- package/src/langs/python2/files/.gitignore.tmpl +0 -5
- package/src/langs/python2/files/__init__.py.tmpl +0 -1
- package/src/langs/python2/files/setup.py.tmpl +0 -82
- package/src/langs/python2/package_info.js +0 -78
- package/src/lib/debug.js +0 -55
- package/src/lib/emitter.js +0 -95
- package/src/lib/helper.js +0 -207
- package/src/resolver/base.js +0 -282
- package/src/resolver/client.js +0 -1013
- package/src/resolver/model.js +0 -159
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const debug = require('../../lib/debug');
|
|
4
|
-
const Emitter = require('../../lib/emitter');
|
|
5
|
-
|
|
6
|
-
const {
|
|
7
|
-
Grammer,
|
|
8
|
-
GrammerThrows,
|
|
9
|
-
|
|
10
|
-
Behavior,
|
|
11
|
-
PropItem,
|
|
12
|
-
AnnotationItem,
|
|
13
|
-
ObjectItem,
|
|
14
|
-
} = require('./items');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
_config,
|
|
18
|
-
_upperFirst,
|
|
19
|
-
_lowerFirst,
|
|
20
|
-
} = require('../../lib/helper.js');
|
|
21
|
-
|
|
22
|
-
class BaseCombinator {
|
|
23
|
-
constructor(config = {}, imports = {}) {
|
|
24
|
-
this.level = 0;
|
|
25
|
-
this.eol = '';
|
|
26
|
-
|
|
27
|
-
this.includeList = [];
|
|
28
|
-
this.includeModelList = [];
|
|
29
|
-
this.includeSet = [];
|
|
30
|
-
|
|
31
|
-
this.config = config;
|
|
32
|
-
this.imports = imports;
|
|
33
|
-
|
|
34
|
-
this.requirePackage = imports.requirePackage;
|
|
35
|
-
this.thirdPackageNamespace = imports.thirdPackageNamespace;
|
|
36
|
-
this.thirdPackageClient = imports.thirdPackageClient;
|
|
37
|
-
this.thirdPackageClientAlias = imports.thirdPackageClientAlias;
|
|
38
|
-
this.thirdPackageModel = imports.thirdPackageModel;
|
|
39
|
-
this.typedef = imports.typedef;
|
|
40
|
-
this.importsTypedef = imports.importsTypedef;
|
|
41
|
-
this.additionalPackage = imports.additionalPackage;
|
|
42
|
-
|
|
43
|
-
_config(this.config);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
combine(objects = []) {
|
|
47
|
-
if (objects.some(Object => !(Object instanceof ObjectItem))) {
|
|
48
|
-
throw new Error('Only supported ObjectItem.');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
combineOutputParts(config, outputParts) {
|
|
53
|
-
const globalEmitter = new Emitter(config);
|
|
54
|
-
globalEmitter.emit(outputParts.head);
|
|
55
|
-
globalEmitter.emit(outputParts.body);
|
|
56
|
-
globalEmitter.emit(outputParts.foot);
|
|
57
|
-
globalEmitter.save();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
coreClass(objName) {
|
|
61
|
-
const key = _lowerFirst(objName.split('$').join(''));
|
|
62
|
-
if (this.config.tea[key]) {
|
|
63
|
-
return this.config.tea[key].name;
|
|
64
|
-
}
|
|
65
|
-
debug.stack('Unsupported core class name : ' + objName);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
resolveNotes(nodes) {
|
|
69
|
-
let notes = {};
|
|
70
|
-
nodes.filter(node => node instanceof PropItem).map(prop => {
|
|
71
|
-
if (prop.notes.length > 0) {
|
|
72
|
-
prop.notes.forEach(note => {
|
|
73
|
-
note.belong = prop.index;
|
|
74
|
-
note.prop = prop.name;
|
|
75
|
-
if (typeof notes[note.key] === 'undefined') {
|
|
76
|
-
notes[note.key] = [];
|
|
77
|
-
}
|
|
78
|
-
notes[note.key].push(note);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
return notes;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
emitAnnotations(emitter, annotations) {
|
|
86
|
-
annotations.forEach(annotation => {
|
|
87
|
-
this.emitAnnotation(emitter, annotation);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
findThrows(grammer, set = []) {
|
|
92
|
-
if (grammer.body) {
|
|
93
|
-
grammer.body.filter(node => {
|
|
94
|
-
if (node instanceof GrammerThrows) {
|
|
95
|
-
set.push(node);
|
|
96
|
-
} else if (node.body) {
|
|
97
|
-
this.findThrows(node, set);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return set;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
init(ast) {
|
|
105
|
-
throw new Error('unimpelemented');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
levelUp() {
|
|
109
|
-
this.level++;
|
|
110
|
-
return this.level;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
levelDown() {
|
|
114
|
-
this.level--;
|
|
115
|
-
return this.level;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
addModelInclude(modelName) {
|
|
119
|
-
throw new Error('unimpelemented');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
addInclude(include) {
|
|
123
|
-
throw new Error('unimpelemented');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
systemfunc(emitter, gram) {
|
|
127
|
-
let tmp = [];
|
|
128
|
-
gram.path.forEach(path => {
|
|
129
|
-
tmp.push(_upperFirst(path.name));
|
|
130
|
-
});
|
|
131
|
-
if (tmp.length === 0) {
|
|
132
|
-
debug.stack('Invalid path. path list cannot be empty.');
|
|
133
|
-
}
|
|
134
|
-
let systemFunc = 'sys' + tmp.join('');
|
|
135
|
-
if (this[systemFunc]) {
|
|
136
|
-
this[systemFunc].apply(this, [emitter, gram]);
|
|
137
|
-
} else {
|
|
138
|
-
debug.stack(`unimpelemented ${systemFunc}(emitter, gram){} method\n`, gram);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
grammer(emit, gram, eol = true, newLine = true) {
|
|
143
|
-
if (gram instanceof AnnotationItem) {
|
|
144
|
-
this.emitAnnotation(emit, gram);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let emitter = new Emitter();
|
|
149
|
-
let method = null;
|
|
150
|
-
if (gram instanceof Behavior) {
|
|
151
|
-
method = gram.name;
|
|
152
|
-
} else if (gram instanceof Grammer) {
|
|
153
|
-
method = _lowerFirst(gram.constructor.name);
|
|
154
|
-
} else {
|
|
155
|
-
debug.stack('Unsupported', gram);
|
|
156
|
-
}
|
|
157
|
-
if (typeof this[method] !== 'undefined') {
|
|
158
|
-
this[method].call(this, emitter, gram);
|
|
159
|
-
} else {
|
|
160
|
-
debug.stack('Unimpelemented : ' + method);
|
|
161
|
-
}
|
|
162
|
-
if (gram.eol !== null) {
|
|
163
|
-
eol = gram.eol;
|
|
164
|
-
}
|
|
165
|
-
if (gram.newLine !== null) {
|
|
166
|
-
newLine = gram.newLine;
|
|
167
|
-
}
|
|
168
|
-
if (newLine) {
|
|
169
|
-
emit.emit('', this.level);
|
|
170
|
-
}
|
|
171
|
-
emit.emit(emitter.output);
|
|
172
|
-
if (eol) {
|
|
173
|
-
emit.emitln(this.eol);
|
|
174
|
-
}
|
|
175
|
-
emitter = null;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
grammerNewLine(emitter, gram) {
|
|
179
|
-
let number = gram.number;
|
|
180
|
-
while (number > 0) {
|
|
181
|
-
emitter.emitln();
|
|
182
|
-
number--;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
emitGrammerValue(gram) {
|
|
187
|
-
let emitter = new Emitter();
|
|
188
|
-
this.grammerValue(emitter, gram);
|
|
189
|
-
return emitter.output;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
module.exports = BaseCombinator;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
indent: ' ',
|
|
5
|
-
ext: '.tea',
|
|
6
|
-
resolvePathByPackage: false,
|
|
7
|
-
keywords: {
|
|
8
|
-
general: [],
|
|
9
|
-
function: [],
|
|
10
|
-
class: [],
|
|
11
|
-
param_variables: []
|
|
12
|
-
},
|
|
13
|
-
typeMap: {},
|
|
14
|
-
symbolMap: {},
|
|
15
|
-
modifyOrder: [],
|
|
16
|
-
exceptionMap: {},
|
|
17
|
-
model: {
|
|
18
|
-
include: [],
|
|
19
|
-
constructor: {
|
|
20
|
-
params: []
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
client: {
|
|
24
|
-
filename: 'client',
|
|
25
|
-
include: []
|
|
26
|
-
},
|
|
27
|
-
generateFileInfo: 'This file is auto-generated, don\'t edit it. Thanks.',
|
|
28
|
-
response: '_response',
|
|
29
|
-
request: '_request',
|
|
30
|
-
runtime: '_runtime',
|
|
31
|
-
baseClient: [],
|
|
32
|
-
tea: {
|
|
33
|
-
core: {
|
|
34
|
-
name: 'TeaCore',
|
|
35
|
-
doAction: 'doAction',
|
|
36
|
-
allowRetry: 'allowRetry',
|
|
37
|
-
sleep: 'sleep',
|
|
38
|
-
getBackoffTime: 'getBackoffTime',
|
|
39
|
-
isRetryable: 'isRetryable'
|
|
40
|
-
},
|
|
41
|
-
model: {
|
|
42
|
-
name: 'TeaModel'
|
|
43
|
-
},
|
|
44
|
-
converter: {
|
|
45
|
-
name: 'TeaConverter'
|
|
46
|
-
},
|
|
47
|
-
response: {
|
|
48
|
-
name: 'TeaResponse'
|
|
49
|
-
},
|
|
50
|
-
request: {
|
|
51
|
-
name: 'TeaRequest'
|
|
52
|
-
},
|
|
53
|
-
exception: {
|
|
54
|
-
name: 'TeaException'
|
|
55
|
-
},
|
|
56
|
-
exceptionUnretryable: {
|
|
57
|
-
name: 'TeaUnretryableException'
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
};
|
package/src/langs/common/enum.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Enum = require('enum');
|
|
4
|
-
|
|
5
|
-
class SymbolEnum extends Enum {
|
|
6
|
-
constructor() {
|
|
7
|
-
super([
|
|
8
|
-
'ASSIGN',
|
|
9
|
-
'EQ',
|
|
10
|
-
'NOT',
|
|
11
|
-
'AND',
|
|
12
|
-
'OR',
|
|
13
|
-
'PLUS',
|
|
14
|
-
'SUB',
|
|
15
|
-
'MULTI',
|
|
16
|
-
'DIV',
|
|
17
|
-
'POWER',
|
|
18
|
-
'GREATER',
|
|
19
|
-
'GREATER_EQ',
|
|
20
|
-
'LESS',
|
|
21
|
-
'LESS_EQ',
|
|
22
|
-
'REVERSE',
|
|
23
|
-
'CONCAT',
|
|
24
|
-
'JUDGE',
|
|
25
|
-
'RISK'
|
|
26
|
-
], { name: 'symbol', ignoreCase: true });
|
|
27
|
-
}
|
|
28
|
-
assign() {
|
|
29
|
-
return this.ASSIGN.key;
|
|
30
|
-
}
|
|
31
|
-
eq() {
|
|
32
|
-
return this.EQ.key;
|
|
33
|
-
}
|
|
34
|
-
not() {
|
|
35
|
-
return this.NOT.key;
|
|
36
|
-
}
|
|
37
|
-
and() {
|
|
38
|
-
return this.AND.key;
|
|
39
|
-
}
|
|
40
|
-
or() {
|
|
41
|
-
return this.OR.key;
|
|
42
|
-
}
|
|
43
|
-
plus() {
|
|
44
|
-
return this.PLUS.key;
|
|
45
|
-
}
|
|
46
|
-
multi() {
|
|
47
|
-
return this.MULTI.key;
|
|
48
|
-
}
|
|
49
|
-
div() {
|
|
50
|
-
return this.DIV.key;
|
|
51
|
-
}
|
|
52
|
-
power() {
|
|
53
|
-
return this.POWER.key;
|
|
54
|
-
}
|
|
55
|
-
greater() {
|
|
56
|
-
return this.GREATER.key;
|
|
57
|
-
}
|
|
58
|
-
greaterEq() {
|
|
59
|
-
return this.GREATER_EQ.key;
|
|
60
|
-
}
|
|
61
|
-
less() {
|
|
62
|
-
return this.LESS.key;
|
|
63
|
-
}
|
|
64
|
-
lessEq() {
|
|
65
|
-
return this.LESS_EQ.key;
|
|
66
|
-
}
|
|
67
|
-
reverse() {
|
|
68
|
-
return this.REVERSE.key;
|
|
69
|
-
}
|
|
70
|
-
concat() {
|
|
71
|
-
return this.CONCAT.key;
|
|
72
|
-
}
|
|
73
|
-
judge() {
|
|
74
|
-
return this.JUDGE.key;
|
|
75
|
-
}
|
|
76
|
-
risk() {
|
|
77
|
-
return this.RISK.key;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
class ModifyEnum extends Enum {
|
|
82
|
-
constructor() {
|
|
83
|
-
super([
|
|
84
|
-
'ASYNC',
|
|
85
|
-
'PRIVATE',
|
|
86
|
-
'PROTECTED',
|
|
87
|
-
'INTERNAL',
|
|
88
|
-
'PUBLIC',
|
|
89
|
-
'FINAL',
|
|
90
|
-
'ABSTRACT',
|
|
91
|
-
'STATIC'
|
|
92
|
-
], { name: 'modify', ignoreCase: true });
|
|
93
|
-
}
|
|
94
|
-
async() {
|
|
95
|
-
return this.ASYNC.key;
|
|
96
|
-
}
|
|
97
|
-
private() {
|
|
98
|
-
return this.PRIVATE.key;
|
|
99
|
-
}
|
|
100
|
-
protected() {
|
|
101
|
-
return this.PROTECTED.key;
|
|
102
|
-
}
|
|
103
|
-
internal() {
|
|
104
|
-
return this.INTERNAL.key;
|
|
105
|
-
}
|
|
106
|
-
public() {
|
|
107
|
-
return this.PUBLIC.key;
|
|
108
|
-
}
|
|
109
|
-
final() {
|
|
110
|
-
return this.FINAL.key;
|
|
111
|
-
}
|
|
112
|
-
abstract() {
|
|
113
|
-
return this.ABSTRACT.key;
|
|
114
|
-
}
|
|
115
|
-
static() {
|
|
116
|
-
return this.STATIC.key;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
class ExceptionEnum extends Enum {
|
|
121
|
-
constructor() {
|
|
122
|
-
super([
|
|
123
|
-
'BASE',
|
|
124
|
-
], { name: 'exceptions', ignoreCase: true });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
base() {
|
|
128
|
-
return this.BASE.key;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
class TypeEnum extends Enum {
|
|
133
|
-
constructor() {
|
|
134
|
-
super([
|
|
135
|
-
'any',
|
|
136
|
-
'anyReference',
|
|
137
|
-
'void',
|
|
138
|
-
'null',
|
|
139
|
-
'empty',
|
|
140
|
-
'char',
|
|
141
|
-
'string',
|
|
142
|
-
'boolean',
|
|
143
|
-
'number',
|
|
144
|
-
'integer',
|
|
145
|
-
'uint8',
|
|
146
|
-
'int8',
|
|
147
|
-
'uint16',
|
|
148
|
-
'int16',
|
|
149
|
-
'uint32',
|
|
150
|
-
'int32',
|
|
151
|
-
'uint64',
|
|
152
|
-
'int64',
|
|
153
|
-
'long',
|
|
154
|
-
'ulong',
|
|
155
|
-
'float',
|
|
156
|
-
'double',
|
|
157
|
-
'single',
|
|
158
|
-
'decimal',
|
|
159
|
-
'byte',
|
|
160
|
-
'map',
|
|
161
|
-
'list',
|
|
162
|
-
'object',
|
|
163
|
-
'readable',
|
|
164
|
-
'writable'
|
|
165
|
-
], { name: 'types', ignoreCase: true });
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const Symbol = new SymbolEnum();
|
|
170
|
-
const Modify = new ModifyEnum();
|
|
171
|
-
const Exceptions = new ExceptionEnum();
|
|
172
|
-
const Types = new TypeEnum();
|
|
173
|
-
|
|
174
|
-
module.exports = {
|
|
175
|
-
Symbol,
|
|
176
|
-
Modify,
|
|
177
|
-
Exceptions,
|
|
178
|
-
Types
|
|
179
|
-
};
|