@darabonba/python-generator 1.2.19 → 2.0.1

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.
Files changed (152) hide show
  1. package/ChangeLog.md +0 -158
  2. package/lib/builtin.js +818 -0
  3. package/lib/generator.js +2708 -0
  4. package/lib/helper.js +422 -0
  5. package/package.json +6 -5
  6. package/tests/expected/alias/setup.py +79 -0
  7. package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
  8. package/tests/expected/alias/tea_python_tests/client.py +35 -0
  9. package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
  10. package/tests/expected/annotation/tea_python_tests/client.py +93 -0
  11. package/tests/expected/annotation/tea_python_tests/models.py +37 -0
  12. package/tests/expected/api/tea_python_tests/__init__.py +1 -0
  13. package/tests/expected/api/tea_python_tests/client.py +106 -0
  14. package/tests/expected/builtin/tea_python_tests/client.py +685 -0
  15. package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
  16. package/tests/expected/comment/tea_python_tests/client.py +288 -0
  17. package/tests/expected/comment/tea_python_tests/models.py +195 -0
  18. package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
  19. package/tests/expected/complex/tea_python_tests/client.py +1169 -0
  20. package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
  21. package/tests/expected/complex/tea_python_tests/models.py +570 -0
  22. package/tests/expected/const/tea_python_tests/__init__.py +1 -0
  23. package/tests/expected/const/tea_python_tests/client.py +14 -0
  24. package/{src/langs/python/files/setup.py.tmpl → tests/expected/empty/setup.py} +11 -11
  25. package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
  26. package/tests/expected/empty/tea_python_tests/client.py +10 -0
  27. package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
  28. package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
  29. package/tests/expected/function/tea_python_tests/__init__.py +1 -0
  30. package/tests/expected/function/tea_python_tests/client.py +64 -0
  31. package/tests/expected/import/setup.py +78 -0
  32. package/tests/expected/import/tea_python_tests/__init__.py +1 -0
  33. package/tests/expected/import/tea_python_tests/client.py +29 -0
  34. package/tests/expected/map/tea_python_tests/__init__.py +1 -0
  35. package/tests/expected/map/tea_python_tests/client.py +39 -0
  36. package/tests/expected/model/tea_python_tests/__init__.py +1 -0
  37. package/tests/expected/model/tea_python_tests/client.py +10 -0
  38. package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
  39. package/tests/expected/model/tea_python_tests/models.py +780 -0
  40. package/tests/expected/multi/tea_python_tests/api.py +95 -0
  41. package/tests/expected/multi/tea_python_tests/client.py +40 -0
  42. package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
  43. package/tests/expected/multi/tea_python_tests/model/user.py +26 -0
  44. package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
  45. package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
  46. package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
  47. package/tests/expected/statements/tea_python_tests/client.py +86 -0
  48. package/tests/expected/super/tea_python_tests/__init__.py +1 -0
  49. package/tests/expected/super/tea_python_tests/client.py +16 -0
  50. package/tests/expected/typedef/setup.py +77 -0
  51. package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
  52. package/tests/expected/typedef/tea_python_tests/client.py +74 -0
  53. package/tests/expected/typedef/tea_python_tests/models.py +42 -0
  54. package/tests/fixtures/alias/Darafile +11 -0
  55. package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
  56. package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
  57. package/tests/fixtures/builtin/Darafile +6 -0
  58. package/tests/fixtures/builtin/main.dara +333 -0
  59. package/tests/fixtures/complex/libraries/import.dara +18 -11
  60. package/tests/fixtures/complex/main.dara +452 -103
  61. package/tests/fixtures/import/libraries/Darafile +1 -1
  62. package/tests/fixtures/import/pack/Darafile +3 -0
  63. package/tests/fixtures/map/libraries/Darafile +3 -0
  64. package/tests/fixtures/map/libraries/import.dara +4 -0
  65. package/tests/fixtures/map/main.dara +17 -2
  66. package/tests/fixtures/model/.libraries.json +3 -0
  67. package/tests/fixtures/model/Darafile +5 -2
  68. package/tests/fixtures/model/libraries/Darafile +20 -0
  69. package/tests/fixtures/model/libraries/import.dara +27 -0
  70. package/tests/fixtures/model/main.dara +60 -42
  71. package/tests/fixtures/multi/.libraries.json +3 -0
  72. package/tests/fixtures/multi/Darafile +12 -0
  73. package/tests/fixtures/multi/api.dara +20 -0
  74. package/tests/fixtures/multi/lib/util.dara +5 -0
  75. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +68 -0
  76. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
  77. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
  78. package/tests/fixtures/multi/main.dara +32 -0
  79. package/tests/fixtures/multi/model/user.dara +35 -0
  80. package/tests/{python3.tests.js → main.tests.js} +107 -65
  81. package/tests/output/alias/setup.py +79 -0
  82. package/tests/output/alias/tea_python_tests/client.py +35 -0
  83. package/{src/langs/python2/files/setup.py.tmpl → tests/output/annotation/setup.py} +19 -24
  84. package/tests/output/annotation/tea_python_tests/client.py +93 -0
  85. package/tests/output/annotation/tea_python_tests/models.py +37 -0
  86. package/tests/output/api/setup.py +77 -0
  87. package/tests/output/api/tea_python_tests/client.py +106 -0
  88. package/tests/output/builtin/setup.py +77 -0
  89. package/tests/output/builtin/tea_python_tests/client.py +685 -0
  90. package/tests/output/comment/setup.py +77 -0
  91. package/tests/output/comment/tea_python_tests/client.py +288 -0
  92. package/tests/output/comment/tea_python_tests/models.py +195 -0
  93. package/tests/output/complex/setup.py +77 -0
  94. package/tests/output/complex/tea_python_tests/client.py +1169 -0
  95. package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
  96. package/tests/output/complex/tea_python_tests/models.py +570 -0
  97. package/tests/output/const/setup.py +77 -0
  98. package/tests/output/const/tea_python_tests/client.py +14 -0
  99. package/tests/output/empty/setup.py +77 -0
  100. package/tests/output/empty/tea_python_tests/client.py +10 -0
  101. package/tests/output/exec/setup.py +77 -0
  102. package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
  103. package/tests/output/function/setup.py +77 -0
  104. package/tests/output/function/tea_python_tests/client.py +64 -0
  105. package/tests/output/import/setup.py +78 -0
  106. package/tests/output/import/tea_python_tests/client.py +29 -0
  107. package/tests/output/map/setup.py +77 -0
  108. package/tests/output/map/tea_python_tests/client.py +39 -0
  109. package/tests/output/model/setup.py +77 -0
  110. package/tests/output/model/tea_python_tests/client.py +10 -0
  111. package/tests/output/model/tea_python_tests/exceptions.py +28 -0
  112. package/tests/output/model/tea_python_tests/models.py +780 -0
  113. package/tests/output/multi/setup.py +77 -0
  114. package/tests/output/multi/tea_python_tests/api.py +95 -0
  115. package/tests/output/multi/tea_python_tests/client.py +40 -0
  116. package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
  117. package/tests/output/multi/tea_python_tests/model/user.py +26 -0
  118. package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
  119. package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
  120. package/tests/output/statements/setup.py +77 -0
  121. package/tests/output/statements/tea_python_tests/client.py +86 -0
  122. package/tests/output/super/setup.py +77 -0
  123. package/tests/output/super/tea_python_tests/client.py +16 -0
  124. package/tests/output/typedef/setup.py +78 -0
  125. package/tests/output/typedef/tea_python_tests/client.py +74 -0
  126. package/tests/output/typedef/tea_python_tests/models.py +42 -0
  127. package/src/generator.js +0 -231
  128. package/src/langs/common/combinator.js +0 -193
  129. package/src/langs/common/config.js +0 -60
  130. package/src/langs/common/enum.js +0 -179
  131. package/src/langs/common/items.js +0 -551
  132. package/src/langs/common/package_info.js +0 -53
  133. package/src/langs/python/combinator.js +0 -1898
  134. package/src/langs/python/config.js +0 -169
  135. package/src/langs/python/files/.gitignore.tmpl +0 -5
  136. package/src/langs/python/files/__init__.py.tmpl +0 -1
  137. package/src/langs/python/package_info.js +0 -78
  138. package/src/langs/python2/combinator.js +0 -1770
  139. package/src/langs/python2/config.js +0 -162
  140. package/src/langs/python2/files/.gitignore.tmpl +0 -5
  141. package/src/langs/python2/files/__init__.py.tmpl +0 -1
  142. package/src/langs/python2/package_info.js +0 -78
  143. package/src/lib/debug.js +0 -55
  144. package/src/lib/emitter.js +0 -95
  145. package/src/lib/helper.js +0 -207
  146. package/src/resolver/base.js +0 -282
  147. package/src/resolver/client.js +0 -1013
  148. package/src/resolver/model.js +0 -159
  149. package/tests/common.tests.js +0 -244
  150. package/tests/lib.tests.js +0 -269
  151. package/tests/python2.tests.js +0 -283
  152. package/tests/resolver.tests.js +0 -434
@@ -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
- };
@@ -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
- };