@darabonba/python-generator 1.2.16 → 1.2.18
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/.github/dependabot.yml +11 -0
- package/.github/workflows/ci.yml +3 -3
- package/ChangeLog.md +6 -0
- package/README-CN.md +2 -4
- package/README.md +2 -4
- package/package.json +7 -8
- package/src/langs/common/config.js +6 -1
- package/src/langs/python/combinator.js +69 -62
- package/src/langs/python/config.js +44 -38
- package/src/langs/python2/combinator.js +62 -55
- package/src/langs/python2/config.js +43 -34
- package/src/lib/helper.js +29 -2
- package/tests/expected/python2/complex/tea_python_tests/models.py +75 -1
- package/tests/expected/python2/import/setup.py +1 -1
- package/tests/expected/python3/complex/tea_python_tests/models.py +82 -1
- package/tests/expected/python3/import/setup.py +1 -1
- package/tests/fixtures/complex/main.dara +9 -1
- package/tests/lib.tests.js +18 -2
- package/tests/python2.tests.js +4 -2
- package/tests/python3.tests.js +4 -2
- package/tests/resolver.tests.js +3 -3
- package/tests/expected/python2/import/tea_python_tests/__pycache__/__init__.cpython-39.pyc +0 -0
|
@@ -31,7 +31,9 @@ const {
|
|
|
31
31
|
_toSnakeCase,
|
|
32
32
|
_toCamelCase,
|
|
33
33
|
_avoidKeywords,
|
|
34
|
-
|
|
34
|
+
_avoidFuncKeywords,
|
|
35
|
+
_avoidClassKeywords,
|
|
36
|
+
_avoidVarKeywords,
|
|
35
37
|
_exception,
|
|
36
38
|
_symbol,
|
|
37
39
|
_deepClone,
|
|
@@ -43,6 +45,14 @@ function _name(name) {
|
|
|
43
45
|
return _avoidKeywords(_toSnakeCase(name));
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
function _varName(name){
|
|
49
|
+
return _avoidVarKeywords(_toSnakeCase(name));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _funcName(name){
|
|
53
|
+
return _avoidFuncKeywords(_toSnakeCase(name));
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
function _type(type) {
|
|
47
57
|
const config = _config();
|
|
48
58
|
let t = type instanceof Object ? type.lexeme : type;
|
|
@@ -387,10 +397,7 @@ class Combinator extends CombinatorBase {
|
|
|
387
397
|
} else {
|
|
388
398
|
className = name.split('.').map(item => _upperFirst(item)).join('');
|
|
389
399
|
}
|
|
390
|
-
|
|
391
|
-
className = _avoidKeywords(className);
|
|
392
|
-
}
|
|
393
|
-
return _toCamelCase(className);
|
|
400
|
+
return _toCamelCase(_avoidClassKeywords(className));
|
|
394
401
|
}
|
|
395
402
|
|
|
396
403
|
emitClass(emitter, object) {
|
|
@@ -444,7 +451,7 @@ class Combinator extends CombinatorBase {
|
|
|
444
451
|
} else if (p instanceof PropItem) {
|
|
445
452
|
const type = this.typeHint(p.type);
|
|
446
453
|
if (type) {
|
|
447
|
-
emitter.emitln(`${
|
|
454
|
+
emitter.emitln(`${_varName(p.name)} = None # type: ${type}`, this.level);
|
|
448
455
|
}
|
|
449
456
|
}
|
|
450
457
|
});
|
|
@@ -472,9 +479,9 @@ class Combinator extends CombinatorBase {
|
|
|
472
479
|
this.emitComplexValidate(emitter, `k${depth}`, fieldType.itemType, depth + 1);
|
|
473
480
|
this.levelDown();
|
|
474
481
|
} else {
|
|
475
|
-
emitter.emitln(`if self.${
|
|
482
|
+
emitter.emitln(`if self.${_varName(name)}:`, this.level);
|
|
476
483
|
this.levelUp();
|
|
477
|
-
emitter.emitln(`for k in self.${
|
|
484
|
+
emitter.emitln(`for k in self.${_varName(name)}:`, this.level);
|
|
478
485
|
this.levelUp();
|
|
479
486
|
this.emitComplexValidate(emitter, 'k', fieldType.itemType, depth + 1);
|
|
480
487
|
this.levelDown();
|
|
@@ -487,9 +494,9 @@ class Combinator extends CombinatorBase {
|
|
|
487
494
|
this.emitComplexValidate(emitter, `v${depth}`, fieldType.valType, depth + 1);
|
|
488
495
|
this.levelDown();
|
|
489
496
|
} else {
|
|
490
|
-
emitter.emitln(`if self.${
|
|
497
|
+
emitter.emitln(`if self.${_varName(name)}:`, this.level);
|
|
491
498
|
this.levelUp();
|
|
492
|
-
emitter.emitln(`for v in self.${
|
|
499
|
+
emitter.emitln(`for v in self.${_varName(name)}.values():`, this.level);
|
|
493
500
|
this.levelUp();
|
|
494
501
|
this.emitComplexValidate(emitter, 'v', fieldType.valType, depth + 1);
|
|
495
502
|
this.levelDown();
|
|
@@ -521,29 +528,29 @@ class Combinator extends CombinatorBase {
|
|
|
521
528
|
|
|
522
529
|
if (required.length > 0) {
|
|
523
530
|
emitter.emitln(
|
|
524
|
-
`self.validate_required(self.${
|
|
531
|
+
`self.validate_required(self.${_varName(prop.name)}, '${_varName(prop.name)}')`,
|
|
525
532
|
this.level
|
|
526
533
|
);
|
|
527
534
|
haveValidate = true;
|
|
528
535
|
}
|
|
529
536
|
if (maxLength.length > 0 || pattern.length > 0 || maximum.length > 0 || minimum.length > 0) {
|
|
530
|
-
emitter.emitln(`if self.${
|
|
537
|
+
emitter.emitln(`if self.${_varName(prop.name)} is not None:`, this.level);
|
|
531
538
|
this.levelUp();
|
|
532
539
|
|
|
533
540
|
if (maxLength.length > 0) {
|
|
534
|
-
emitter.emitln(`self.validate_max_length(self.${
|
|
541
|
+
emitter.emitln(`self.validate_max_length(self.${_varName(prop.name)}, '${_varName(prop.name)}', ${maxLength[0].value})`, this.level);
|
|
535
542
|
}
|
|
536
543
|
|
|
537
544
|
if (pattern.length > 0) {
|
|
538
|
-
emitter.emitln(`self.validate_pattern(self.${
|
|
545
|
+
emitter.emitln(`self.validate_pattern(self.${_varName(prop.name)}, '${_varName(prop.name)}', '${pattern[0].value}')`, this.level);
|
|
539
546
|
}
|
|
540
547
|
|
|
541
548
|
if (maximum.length > 0) {
|
|
542
|
-
emitter.emitln(`self.validate_maximum(self.${
|
|
549
|
+
emitter.emitln(`self.validate_maximum(self.${_varName(prop.name)}, '${_varName(prop.name)}', ${maximum[0].value})`, this.level);
|
|
543
550
|
}
|
|
544
551
|
|
|
545
552
|
if (minimum.length > 0) {
|
|
546
|
-
emitter.emitln(`self.validate_minimum(self.${
|
|
553
|
+
emitter.emitln(`self.validate_minimum(self.${_varName(prop.name)}, '${_varName(prop.name)}', ${minimum[0].value})`, this.level);
|
|
547
554
|
}
|
|
548
555
|
this.levelDown();
|
|
549
556
|
haveValidate = true;
|
|
@@ -558,9 +565,9 @@ class Combinator extends CombinatorBase {
|
|
|
558
565
|
emitter.emit(emt.output);
|
|
559
566
|
}
|
|
560
567
|
} else if (prop.type.objectType === 'model') {
|
|
561
|
-
emitter.emitln(`if self.${
|
|
568
|
+
emitter.emitln(`if self.${_varName(prop.name)}:`, this.level);
|
|
562
569
|
this.levelUp();
|
|
563
|
-
emitter.emitln(`self.${
|
|
570
|
+
emitter.emitln(`self.${_varName(prop.name)}.validate()`, this.level);
|
|
564
571
|
this.levelDown();
|
|
565
572
|
haveValidate = true;
|
|
566
573
|
}
|
|
@@ -600,9 +607,9 @@ class Combinator extends CombinatorBase {
|
|
|
600
607
|
}
|
|
601
608
|
} else {
|
|
602
609
|
emitter.emitln(`result['${fieldName}'] = []`, this.level);
|
|
603
|
-
emitter.emitln(`if self.${
|
|
610
|
+
emitter.emitln(`if self.${_varName(name)} is not None:`, this.level);
|
|
604
611
|
this.levelUp();
|
|
605
|
-
emitter.emitln(`for k in self.${
|
|
612
|
+
emitter.emitln(`for k in self.${_varName(name)}:`, this.level);
|
|
606
613
|
this.levelUp();
|
|
607
614
|
if (type.itemType.valType || type.itemType.itemType) {
|
|
608
615
|
const propInfo = {
|
|
@@ -611,7 +618,7 @@ class Combinator extends CombinatorBase {
|
|
|
611
618
|
type: type.itemType,
|
|
612
619
|
parentType: type.lexeme
|
|
613
620
|
};
|
|
614
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
621
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
615
622
|
} else {
|
|
616
623
|
if (type.itemType.objectType === 'model') {
|
|
617
624
|
emitter.emitln(`result['${fieldName}'].append(k.to_map() if k else None)`, this.level);
|
|
@@ -644,9 +651,9 @@ class Combinator extends CombinatorBase {
|
|
|
644
651
|
}
|
|
645
652
|
} else {
|
|
646
653
|
emitter.emitln(`result['${fieldName}'] = {}`, this.level);
|
|
647
|
-
emitter.emitln(`if self.${
|
|
654
|
+
emitter.emitln(`if self.${_varName(name)} is not None:`, this.level);
|
|
648
655
|
this.levelUp();
|
|
649
|
-
emitter.emitln(`for k, v in self.${
|
|
656
|
+
emitter.emitln(`for k, v in self.${_varName(name)}.items():`, this.level);
|
|
650
657
|
this.levelUp();
|
|
651
658
|
if (type.valType.valType || type.valType.itemType) {
|
|
652
659
|
const propInfo = {
|
|
@@ -655,7 +662,7 @@ class Combinator extends CombinatorBase {
|
|
|
655
662
|
type: type.valType,
|
|
656
663
|
parentType: type.lexeme
|
|
657
664
|
};
|
|
658
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
665
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
659
666
|
} else {
|
|
660
667
|
if (type.valType.objectType === 'model') {
|
|
661
668
|
emitter.emitln(`result['${fieldName}'][k] = v.to_map()`, this.level);
|
|
@@ -703,19 +710,19 @@ class Combinator extends CombinatorBase {
|
|
|
703
710
|
if (emt.needSave === true) {
|
|
704
711
|
emitter.emit(emt.output);
|
|
705
712
|
} else {
|
|
706
|
-
emitter.emitln(`if self.${
|
|
713
|
+
emitter.emitln(`if self.${_varName(prop.name)} is not None:`, this.level);
|
|
707
714
|
this.levelUp();
|
|
708
|
-
emitter.emitln(`result['${name}'] = self.${
|
|
715
|
+
emitter.emitln(`result['${name}'] = self.${_varName(prop.name)}`, this.level);
|
|
709
716
|
this.levelDown();
|
|
710
717
|
}
|
|
711
718
|
|
|
712
719
|
} else {
|
|
713
|
-
emitter.emitln(`if self.${
|
|
720
|
+
emitter.emitln(`if self.${_varName(prop.name)} is not None:`, this.level);
|
|
714
721
|
this.levelUp();
|
|
715
722
|
if (prop.type.objectType === 'model') {
|
|
716
|
-
emitter.emitln(`result['${name}'] = self.${
|
|
723
|
+
emitter.emitln(`result['${name}'] = self.${_varName(prop.name)}.to_map()`, this.level);
|
|
717
724
|
} else {
|
|
718
|
-
emitter.emitln(`result['${name}'] = self.${
|
|
725
|
+
emitter.emitln(`result['${name}'] = self.${_varName(prop.name)}`, this.level);
|
|
719
726
|
}
|
|
720
727
|
this.levelDown();
|
|
721
728
|
}
|
|
@@ -753,7 +760,7 @@ class Combinator extends CombinatorBase {
|
|
|
753
760
|
emitter.emitln(`${carrier}['k${num}'] = l${depth}`, this.level);
|
|
754
761
|
}
|
|
755
762
|
} else {
|
|
756
|
-
emitter.emitln(`self.${
|
|
763
|
+
emitter.emitln(`self.${_varName(name)} = []`, this.level);
|
|
757
764
|
emitter.emitln(`if m.get('${fieldName}') is not None:`, this.level);
|
|
758
765
|
this.levelUp();
|
|
759
766
|
emitter.emitln(`for k in m.get('${fieldName}'):`, this.level);
|
|
@@ -765,11 +772,11 @@ class Combinator extends CombinatorBase {
|
|
|
765
772
|
type: type.itemType,
|
|
766
773
|
parentType: type.lexeme
|
|
767
774
|
};
|
|
768
|
-
this.emitComplexFromMap(emitter, propInfo, `self.${
|
|
775
|
+
this.emitComplexFromMap(emitter, propInfo, `self.${_varName(name)}`, depth + 1);
|
|
769
776
|
} else {
|
|
770
777
|
if (type.itemType.objectType === 'model') {
|
|
771
778
|
emitter.emitln(`temp_model = ${type.itemType.lexeme}()`, this.level);
|
|
772
|
-
emitter.emitln(`self.${
|
|
779
|
+
emitter.emitln(`self.${_varName(name)}.append(temp_model.from_map(k))`, this.level);
|
|
773
780
|
emitter.needSave = true;
|
|
774
781
|
} else {
|
|
775
782
|
emitter.needSave = false;
|
|
@@ -799,7 +806,7 @@ class Combinator extends CombinatorBase {
|
|
|
799
806
|
emitter.emitln(`${carrier}[k${num}] = d${depth}`, this.level);
|
|
800
807
|
}
|
|
801
808
|
} else {
|
|
802
|
-
emitter.emitln(`self.${
|
|
809
|
+
emitter.emitln(`self.${_varName(name)} = {}`, this.level);
|
|
803
810
|
emitter.emitln(`if m.get('${fieldName}') is not None:`, this.level);
|
|
804
811
|
this.levelUp();
|
|
805
812
|
emitter.emitln(`for k, v in m.get('${fieldName}').items():`, this.level);
|
|
@@ -811,11 +818,11 @@ class Combinator extends CombinatorBase {
|
|
|
811
818
|
type: type.valType,
|
|
812
819
|
parentType: type.lexeme
|
|
813
820
|
};
|
|
814
|
-
this.emitComplexFromMap(emitter, propInfo, `self.${
|
|
821
|
+
this.emitComplexFromMap(emitter, propInfo, `self.${_varName(name)}`, depth + 1);
|
|
815
822
|
} else {
|
|
816
823
|
if (type.valType.objectType === 'model') {
|
|
817
824
|
emitter.emitln(`temp_model = ${type.valType.lexeme}()`, this.level);
|
|
818
|
-
emitter.emitln(`self.${
|
|
825
|
+
emitter.emitln(`self.${_varName(name)}[k] = temp_model.from_map(v)`, this.level);
|
|
819
826
|
emitter.needSave = true;
|
|
820
827
|
} else {
|
|
821
828
|
emitter.needSave = false;
|
|
@@ -869,7 +876,7 @@ class Combinator extends CombinatorBase {
|
|
|
869
876
|
} else {
|
|
870
877
|
emitter.emitln(`if m.get('${name}') is not None:`, this.level);
|
|
871
878
|
this.levelUp();
|
|
872
|
-
emitter.emitln(`self.${
|
|
879
|
+
emitter.emitln(`self.${_varName(prop.name)} = m.get('${name}')`, this.level);
|
|
873
880
|
this.levelDown();
|
|
874
881
|
}
|
|
875
882
|
} else {
|
|
@@ -878,9 +885,9 @@ class Combinator extends CombinatorBase {
|
|
|
878
885
|
if (prop.type.objectType === 'model') {
|
|
879
886
|
let type = _type(prop.type);
|
|
880
887
|
emitter.emitln(`temp_model = ${type}()`, this.level);
|
|
881
|
-
emitter.emitln(`self.${
|
|
888
|
+
emitter.emitln(`self.${_varName(prop.name)} = temp_model.from_map(m['${name}'])`, this.level);
|
|
882
889
|
} else {
|
|
883
|
-
emitter.emitln(`self.${
|
|
890
|
+
emitter.emitln(`self.${_varName(prop.name)} = m.get('${name}')`, this.level);
|
|
884
891
|
}
|
|
885
892
|
this.levelDown();
|
|
886
893
|
}
|
|
@@ -896,9 +903,9 @@ class Combinator extends CombinatorBase {
|
|
|
896
903
|
let constructParams = [];
|
|
897
904
|
construct.params.forEach(param => {
|
|
898
905
|
if (param.value !== null && param.value !== 'null') {
|
|
899
|
-
constructParams.push(`${
|
|
906
|
+
constructParams.push(`${_varName(param.key)}=${param.value}`);
|
|
900
907
|
} else {
|
|
901
|
-
constructParams.push(`${
|
|
908
|
+
constructParams.push(`${_varName(param.key)}`);
|
|
902
909
|
}
|
|
903
910
|
});
|
|
904
911
|
emitter.emit('def __init__(self', this.level);
|
|
@@ -914,7 +921,7 @@ class Combinator extends CombinatorBase {
|
|
|
914
921
|
let curr_length = 0;
|
|
915
922
|
props.forEach((prop) => {
|
|
916
923
|
if (prop instanceof PropItem) {
|
|
917
|
-
let str = ` ${
|
|
924
|
+
let str = ` ${_varName(prop.name)}=None`;
|
|
918
925
|
if(curr_length+str.length>=max_length){
|
|
919
926
|
str = emitter.eol + emitter.indent(this.level + 3) + str;
|
|
920
927
|
curr_length = 0;
|
|
@@ -958,7 +965,7 @@ class Combinator extends CombinatorBase {
|
|
|
958
965
|
}
|
|
959
966
|
|
|
960
967
|
const fieldType = this.typeHint(prop.type);
|
|
961
|
-
emitter.emitln(`self.${
|
|
968
|
+
emitter.emitln(`self.${_varName(prop.name)} = ${_varName(prop.name)} # type: ${fieldType}`, this.level);
|
|
962
969
|
});
|
|
963
970
|
if (construct.body.length > 0) {
|
|
964
971
|
construct.body.forEach(gram => {
|
|
@@ -1014,17 +1021,17 @@ class Combinator extends CombinatorBase {
|
|
|
1014
1021
|
}
|
|
1015
1022
|
if (func.params.length > 0) {
|
|
1016
1023
|
let selfVar = this.func_static ? '' : 'self, ';
|
|
1017
|
-
emitter.emit(`def ${
|
|
1024
|
+
emitter.emit(`def ${_funcName(func.name)}(${selfVar}`, this.level);
|
|
1018
1025
|
if (func.params.length > 0) {
|
|
1019
1026
|
let params = [];
|
|
1020
1027
|
func.params.forEach(p => {
|
|
1021
|
-
params.push(`${
|
|
1028
|
+
params.push(`${_varName(p.key)}`);
|
|
1022
1029
|
});
|
|
1023
1030
|
emitter.emit(params.join(', '));
|
|
1024
1031
|
}
|
|
1025
1032
|
} else {
|
|
1026
1033
|
let selfVar = this.func_static ? '' : 'self';
|
|
1027
|
-
emitter.emit(`def ${
|
|
1034
|
+
emitter.emit(`def ${_funcName(func.name)}(${selfVar}`, this.level);
|
|
1028
1035
|
}
|
|
1029
1036
|
emitter.emitln('):');
|
|
1030
1037
|
this.levelUp();
|
|
@@ -1216,24 +1223,24 @@ class Combinator extends CombinatorBase {
|
|
|
1216
1223
|
pre += `.${_name(path.name)}`;
|
|
1217
1224
|
}
|
|
1218
1225
|
} else if (path.type === 'object' || path.type === 'object_async') {
|
|
1219
|
-
pre += `${
|
|
1226
|
+
pre += `${_varName(_convertStaticParam(pathName))}`;
|
|
1220
1227
|
} else if (path.type === 'object_static' || path.type === 'object_static_async') {
|
|
1221
1228
|
pre += `${_convertStaticParam(pathName)}`;
|
|
1222
1229
|
} else if (path.type === 'call' || path.type === 'call_static') {
|
|
1223
|
-
pre += `.${
|
|
1230
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1224
1231
|
} else if (path.type === 'call_async' || path.type === 'call_static_async') {
|
|
1225
|
-
pre += `.${
|
|
1232
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1226
1233
|
} else if (path.type === 'prop') {
|
|
1227
1234
|
pre += `.${_name(pathName)}`;
|
|
1228
1235
|
} else if (path.type === 'prop_static') {
|
|
1229
1236
|
pre += `.${_name(pathName)}`;
|
|
1230
1237
|
} else if (path.type === 'map') {
|
|
1231
|
-
pre += path.isVar ? `.get(${
|
|
1238
|
+
pre += path.isVar ? `.get(${_varName(pathName)})` : `.get('${pathName}')`;
|
|
1232
1239
|
} else if (path.type === 'map_set') {
|
|
1233
1240
|
const quote = this._adaptedQuotes(pathName, emitter);
|
|
1234
1241
|
pre += `[${quote}${pathName}${quote}]`;
|
|
1235
1242
|
} else if (path.type === 'list') {
|
|
1236
|
-
pre += path.isVar ? `[${
|
|
1243
|
+
pre += path.isVar ? `[${_varName(pathName)}]` : `[${pathName}]`;
|
|
1237
1244
|
} else {
|
|
1238
1245
|
debug.stack(gram);
|
|
1239
1246
|
}
|
|
@@ -1276,7 +1283,7 @@ class Combinator extends CombinatorBase {
|
|
|
1276
1283
|
emitter.emit(`${name}()`);
|
|
1277
1284
|
} else if (gram.varType === 'var' || gram.varType === 'const') {
|
|
1278
1285
|
const name = gram.name ? gram.name : gram.key;
|
|
1279
|
-
emitter.emit(`${_convertStaticParam(
|
|
1286
|
+
emitter.emit(`${_convertStaticParam(_varName(name))}`);
|
|
1280
1287
|
} else {
|
|
1281
1288
|
debug.stack(gram);
|
|
1282
1289
|
}
|
|
@@ -1288,7 +1295,7 @@ class Combinator extends CombinatorBase {
|
|
|
1288
1295
|
const quote = this._adaptedQuotes(gram.key, emitter);
|
|
1289
1296
|
emitter.emit(`${quote}${gram.key}${quote}: `);
|
|
1290
1297
|
} else {
|
|
1291
|
-
emitter.emit(`${
|
|
1298
|
+
emitter.emit(`${_varName(gram.key)}=`, this.level);
|
|
1292
1299
|
}
|
|
1293
1300
|
}
|
|
1294
1301
|
if (gram instanceof GrammerCall) {
|
|
@@ -1404,7 +1411,7 @@ class Combinator extends CombinatorBase {
|
|
|
1404
1411
|
const quote = this._adaptedQuotes(gram.value, emitter);
|
|
1405
1412
|
emitter.emit(`${quote}${gram.value}${quote}`);
|
|
1406
1413
|
} else if (gram.type === 'param') {
|
|
1407
|
-
emitter.emit(`${_convertStaticParam(
|
|
1414
|
+
emitter.emit(`${_convertStaticParam(_varName(gram.value))}`);
|
|
1408
1415
|
} else if (gram.type === 'call') {
|
|
1409
1416
|
this.grammerCall(emitter, gram.value);
|
|
1410
1417
|
} else if (gram.type === 'number') {
|
|
@@ -1618,7 +1625,7 @@ class Combinator extends CombinatorBase {
|
|
|
1618
1625
|
gram.params.forEach(p => {
|
|
1619
1626
|
let emit = new Emitter();
|
|
1620
1627
|
if (p.key) {
|
|
1621
|
-
emit.emit(`${
|
|
1628
|
+
emit.emit(`${_varName(p.key)}`);
|
|
1622
1629
|
emit.emit('=');
|
|
1623
1630
|
}
|
|
1624
1631
|
if (typeof (p.value) === 'string') {
|
|
@@ -1648,7 +1655,7 @@ class Combinator extends CombinatorBase {
|
|
|
1648
1655
|
this.grammerCall(emit, behavior.call);
|
|
1649
1656
|
|
|
1650
1657
|
if (behavior.isVar) {
|
|
1651
|
-
emitter.emit(`${emit.output}[${
|
|
1658
|
+
emitter.emit(`${emit.output}[${_varName(behavior.key)}] = `, this.level);
|
|
1652
1659
|
} else {
|
|
1653
1660
|
const quote = this._adaptedQuotes(behavior.key, emitter);
|
|
1654
1661
|
emitter.emit(`${emit.output}[${quote}${behavior.key}${quote}] = `, this.level);
|
|
@@ -6,40 +6,49 @@ module.exports = {
|
|
|
6
6
|
...defaultConfig,
|
|
7
7
|
indent: ' ',
|
|
8
8
|
ext: '.py',
|
|
9
|
-
keywords:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
9
|
+
keywords: {
|
|
10
|
+
general: [
|
|
11
|
+
'and',
|
|
12
|
+
'as',
|
|
13
|
+
'assert',
|
|
14
|
+
'break',
|
|
15
|
+
'class',
|
|
16
|
+
'continue',
|
|
17
|
+
'def',
|
|
18
|
+
'del',
|
|
19
|
+
'elif',
|
|
20
|
+
'else',
|
|
21
|
+
'except',
|
|
22
|
+
'finally',
|
|
23
|
+
'for',
|
|
24
|
+
'from',
|
|
25
|
+
'False',
|
|
26
|
+
'global',
|
|
27
|
+
'if',
|
|
28
|
+
'import',
|
|
29
|
+
'in',
|
|
30
|
+
'is',
|
|
31
|
+
'lambda',
|
|
32
|
+
'not',
|
|
33
|
+
'None',
|
|
34
|
+
'or',
|
|
35
|
+
'pass',
|
|
36
|
+
'raise',
|
|
37
|
+
'return',
|
|
38
|
+
'try',
|
|
39
|
+
'True',
|
|
40
|
+
'while',
|
|
41
|
+
'with',
|
|
42
|
+
'yield'
|
|
43
|
+
],
|
|
44
|
+
function: [],
|
|
45
|
+
class: [],
|
|
46
|
+
param_variables: [
|
|
47
|
+
'exec',
|
|
48
|
+
'print',
|
|
49
|
+
'self'
|
|
50
|
+
]
|
|
51
|
+
},
|
|
43
52
|
symbolMap: {
|
|
44
53
|
'ASSIGN': '=',
|
|
45
54
|
'EQ': '==',
|
package/src/lib/helper.js
CHANGED
|
@@ -53,7 +53,31 @@ function _deepClone(obj) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function _avoidKeywords(str) {
|
|
56
|
-
if (config.keywords.indexOf(str.toLowerCase()) > -1) {
|
|
56
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1) {
|
|
57
|
+
return str + '_';
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _avoidFuncKeywords(str) {
|
|
63
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
64
|
+
|| config.keywords.function.indexOf(str.toLowerCase()) > -1) {
|
|
65
|
+
return str + '_';
|
|
66
|
+
}
|
|
67
|
+
return str;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _avoidClassKeywords(str) {
|
|
71
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
72
|
+
|| config.keywords.class.indexOf(str.toLowerCase()) > -1) {
|
|
73
|
+
return str + '_';
|
|
74
|
+
}
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _avoidVarKeywords(str) {
|
|
79
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
80
|
+
|| config.keywords.param_variables.indexOf(str.toLowerCase()) > -1) {
|
|
57
81
|
return str + '_';
|
|
58
82
|
}
|
|
59
83
|
return str;
|
|
@@ -69,7 +93,7 @@ function _convertStaticParam(param) {
|
|
|
69
93
|
}
|
|
70
94
|
|
|
71
95
|
function _isKeywords(str) {
|
|
72
|
-
return config.keywords.indexOf(str.toLowerCase()) > -1;
|
|
96
|
+
return config.keywords.general.indexOf(str.toLowerCase()) > -1;
|
|
73
97
|
}
|
|
74
98
|
|
|
75
99
|
function _modify(modify) {
|
|
@@ -159,6 +183,9 @@ module.exports = {
|
|
|
159
183
|
_isBasicType,
|
|
160
184
|
_deepClone,
|
|
161
185
|
_avoidKeywords,
|
|
186
|
+
_avoidFuncKeywords,
|
|
187
|
+
_avoidClassKeywords,
|
|
188
|
+
_avoidVarKeywords,
|
|
162
189
|
_convertStaticParam,
|
|
163
190
|
_isKeywords,
|
|
164
191
|
_modify,
|
|
@@ -118,9 +118,33 @@ class ComplexRequestComplexList(TeaModel):
|
|
|
118
118
|
return self
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
class ComplexRequestComplexList2(TeaModel):
|
|
122
|
+
def __init__(self, any=None):
|
|
123
|
+
self.any = any # type: any
|
|
124
|
+
|
|
125
|
+
def validate(self):
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
def to_map(self):
|
|
129
|
+
_map = super(ComplexRequestComplexList2, self).to_map()
|
|
130
|
+
if _map is not None:
|
|
131
|
+
return _map
|
|
132
|
+
|
|
133
|
+
result = dict()
|
|
134
|
+
if self.any is not None:
|
|
135
|
+
result['Name'] = self.any
|
|
136
|
+
return result
|
|
137
|
+
|
|
138
|
+
def from_map(self, m=None):
|
|
139
|
+
m = m or dict()
|
|
140
|
+
if m.get('Name') is not None:
|
|
141
|
+
self.any = m.get('Name')
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
|
|
121
145
|
class ComplexRequest(TeaModel):
|
|
122
146
|
def __init__(self, access_key=None, body=None, strs=None, header=None, num=None, configs=None, part=None,
|
|
123
|
-
complex_list=None, complex_list_1=None, from_=None):
|
|
147
|
+
complex_list=None, complex_list_1=None, complex_list_2=None, from_=None, self_=None, print_=None, exec_=None):
|
|
124
148
|
self.access_key = access_key # type: str
|
|
125
149
|
# Body
|
|
126
150
|
self.body = body # type: READABLE
|
|
@@ -134,8 +158,15 @@ class ComplexRequest(TeaModel):
|
|
|
134
158
|
self.part = part # type: list[ComplexRequestPart]
|
|
135
159
|
self.complex_list = complex_list # type: list[list[list[ComplexRequestComplexList]]]
|
|
136
160
|
self.complex_list_1 = complex_list_1 # type: list[list[dict[str, str]]]
|
|
161
|
+
self.complex_list_2 = complex_list_2 # type: list[list[list[ComplexRequestComplexList2]]]
|
|
137
162
|
# test keywords
|
|
138
163
|
self.from_ = from_ # type: str
|
|
164
|
+
# test keywords
|
|
165
|
+
self.self_ = self_ # type: str
|
|
166
|
+
# test keywords
|
|
167
|
+
self.print_ = print_ # type: str
|
|
168
|
+
# test keywords
|
|
169
|
+
self.exec_ = exec_ # type: str
|
|
139
170
|
|
|
140
171
|
def validate(self):
|
|
141
172
|
self.validate_required(self.access_key, 'access_key')
|
|
@@ -160,7 +191,17 @@ class ComplexRequest(TeaModel):
|
|
|
160
191
|
if k2:
|
|
161
192
|
k2.validate()
|
|
162
193
|
self.validate_required(self.complex_list_1, 'complex_list_1')
|
|
194
|
+
self.validate_required(self.complex_list_2, 'complex_list_2')
|
|
195
|
+
if self.complex_list_2:
|
|
196
|
+
for k in self.complex_list_2:
|
|
197
|
+
for k1 in k:
|
|
198
|
+
for k2 in k1:
|
|
199
|
+
if k2:
|
|
200
|
+
k2.validate()
|
|
163
201
|
self.validate_required(self.from_, 'from_')
|
|
202
|
+
self.validate_required(self.self_, 'self_')
|
|
203
|
+
self.validate_required(self.print_, 'print_')
|
|
204
|
+
self.validate_required(self.exec_, 'exec_')
|
|
164
205
|
|
|
165
206
|
def to_map(self):
|
|
166
207
|
_map = super(ComplexRequest, self).to_map()
|
|
@@ -196,8 +237,24 @@ class ComplexRequest(TeaModel):
|
|
|
196
237
|
result['complexList'].append(l1)
|
|
197
238
|
if self.complex_list_1 is not None:
|
|
198
239
|
result['complexList1'] = self.complex_list_1
|
|
240
|
+
result['ComplexList2'] = []
|
|
241
|
+
if self.complex_list_2 is not None:
|
|
242
|
+
for k in self.complex_list_2:
|
|
243
|
+
l1 = []
|
|
244
|
+
for k1 in k:
|
|
245
|
+
l2 = []
|
|
246
|
+
for k2 in k1:
|
|
247
|
+
l2.append(k2.to_map() if k2 else None)
|
|
248
|
+
l1.append(l2)
|
|
249
|
+
result['ComplexList2'].append(l1)
|
|
199
250
|
if self.from_ is not None:
|
|
200
251
|
result['from'] = self.from_
|
|
252
|
+
if self.self_ is not None:
|
|
253
|
+
result['self'] = self.self_
|
|
254
|
+
if self.print_ is not None:
|
|
255
|
+
result['print'] = self.print_
|
|
256
|
+
if self.exec_ is not None:
|
|
257
|
+
result['exec'] = self.exec_
|
|
201
258
|
return result
|
|
202
259
|
|
|
203
260
|
def from_map(self, m=None):
|
|
@@ -234,8 +291,25 @@ class ComplexRequest(TeaModel):
|
|
|
234
291
|
self.complex_list.append(l1)
|
|
235
292
|
if m.get('complexList1') is not None:
|
|
236
293
|
self.complex_list_1 = m.get('complexList1')
|
|
294
|
+
self.complex_list_2 = []
|
|
295
|
+
if m.get('ComplexList2') is not None:
|
|
296
|
+
for k in m.get('ComplexList2'):
|
|
297
|
+
l1 = []
|
|
298
|
+
for k1 in k:
|
|
299
|
+
l2 = []
|
|
300
|
+
for k2 in k1:
|
|
301
|
+
temp_model = ComplexRequestComplexList2()
|
|
302
|
+
l2.append(temp_model.from_map(k2))
|
|
303
|
+
l1.append(l2)
|
|
304
|
+
self.complex_list_2.append(l1)
|
|
237
305
|
if m.get('from') is not None:
|
|
238
306
|
self.from_ = m.get('from')
|
|
307
|
+
if m.get('self') is not None:
|
|
308
|
+
self.self_ = m.get('self')
|
|
309
|
+
if m.get('print') is not None:
|
|
310
|
+
self.print_ = m.get('print')
|
|
311
|
+
if m.get('exec') is not None:
|
|
312
|
+
self.exec_ = m.get('exec')
|
|
239
313
|
return self
|
|
240
314
|
|
|
241
315
|
|