ether-code 0.8.6 → 0.8.8
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/cli/ether.js +1 -1
- package/generators/php-generator.js +81 -5
- package/lexer/ether-lexer.js +387 -363
- package/package.json +1 -1
- package/parsers/ether-parser-base.js +9 -9
- package/parsers/ether-parser-php.js +179 -11
package/cli/ether.js
CHANGED
|
@@ -31,14 +31,35 @@ class PHPGenerator {
|
|
|
31
31
|
if (!section[lang]) continue
|
|
32
32
|
|
|
33
33
|
for (const [etherWord, phpCode] of Object.entries(section[lang])) {
|
|
34
|
-
const
|
|
34
|
+
const fixed = this.normalizeUTF8(etherWord)
|
|
35
|
+
const normalizedKey = fixed.toLowerCase().trim()
|
|
35
36
|
const cleanPhp = this.cleanPhpValue(phpCode)
|
|
36
37
|
this.translationMap[normalizedKey] = cleanPhp
|
|
38
|
+
|
|
39
|
+
const withoutAccents = this.removeAccents(normalizedKey)
|
|
40
|
+
if (withoutAccents !== normalizedKey) {
|
|
41
|
+
this.translationMap[withoutAccents] = cleanPhp
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
|
|
48
|
+
normalizeUTF8(str) {
|
|
49
|
+
if (typeof str !== 'string') return String(str)
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const bytes = new Uint8Array(str.length)
|
|
53
|
+
for (let i = 0; i < str.length; i++) {
|
|
54
|
+
bytes[i] = str.charCodeAt(i)
|
|
55
|
+
}
|
|
56
|
+
const decoder = new TextDecoder('utf-8')
|
|
57
|
+
return decoder.decode(bytes)
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return str
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
42
63
|
cleanPhpValue(value) {
|
|
43
64
|
if (typeof value !== 'string') return value
|
|
44
65
|
let cleaned = value.replace(/\(\)$/, '')
|
|
@@ -60,6 +81,36 @@ class PHPGenerator {
|
|
|
60
81
|
return this.translationMap[withoutAccents]
|
|
61
82
|
}
|
|
62
83
|
|
|
84
|
+
if (normalized.includes(' ')) {
|
|
85
|
+
const words = normalized.split(' ')
|
|
86
|
+
|
|
87
|
+
for (let i = words.length - 1; i >= 1; i--) {
|
|
88
|
+
const partial = words.slice(0, i + 1).join(' ')
|
|
89
|
+
if (this.translationMap[partial]) {
|
|
90
|
+
return this.translationMap[partial]
|
|
91
|
+
}
|
|
92
|
+
const partialNoAccent = this.removeAccents(partial)
|
|
93
|
+
if (this.translationMap[partialNoAccent]) {
|
|
94
|
+
return this.translationMap[partialNoAccent]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const firstWord = words[0]
|
|
99
|
+
if (this.translationMap[firstWord]) {
|
|
100
|
+
const result = this.translationMap[firstWord]
|
|
101
|
+
if (!result.startsWith('__') && !result.startsWith('$')) {
|
|
102
|
+
return result
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const firstWordNoAccent = this.removeAccents(firstWord)
|
|
106
|
+
if (this.translationMap[firstWordNoAccent]) {
|
|
107
|
+
const result = this.translationMap[firstWordNoAccent]
|
|
108
|
+
if (!result.startsWith('__') && !result.startsWith('$')) {
|
|
109
|
+
return result
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
63
114
|
return word
|
|
64
115
|
}
|
|
65
116
|
|
|
@@ -158,6 +209,7 @@ class PHPGenerator {
|
|
|
158
209
|
'ThisExpression': () => '$this',
|
|
159
210
|
'StaticMemberExpression': () => this.generateStaticMemberExpression(node),
|
|
160
211
|
'IndexExpression': () => this.generateIndexExpression(node),
|
|
212
|
+
'YieldExpression': () => this.generateYieldExpression(node),
|
|
161
213
|
'EmptyStatement': () => '',
|
|
162
214
|
'Comment': () => ''
|
|
163
215
|
}
|
|
@@ -232,8 +284,8 @@ class PHPGenerator {
|
|
|
232
284
|
result += 'readonly '
|
|
233
285
|
}
|
|
234
286
|
|
|
235
|
-
const typeHint = p.typeHint || p.type
|
|
236
|
-
if (typeHint) {
|
|
287
|
+
const typeHint = p.typeHint || (p.type !== 'Parameter' ? p.type : null)
|
|
288
|
+
if (typeHint && typeHint !== 'Parameter') {
|
|
237
289
|
result += this.translateType(typeHint) + ' '
|
|
238
290
|
}
|
|
239
291
|
|
|
@@ -761,9 +813,11 @@ class PHPGenerator {
|
|
|
761
813
|
let property
|
|
762
814
|
|
|
763
815
|
if (typeof node.property === 'string') {
|
|
764
|
-
property = node.property
|
|
816
|
+
property = this.translateMethodName(node.property)
|
|
765
817
|
} else if (node.property && node.property.name) {
|
|
766
|
-
property = node.property.name
|
|
818
|
+
property = this.translateMethodName(node.property.name)
|
|
819
|
+
} else if (node.property && node.property.type === 'Identifier') {
|
|
820
|
+
property = this.translateMethodName(node.property.name || node.property.value)
|
|
767
821
|
} else {
|
|
768
822
|
property = this.generateNode(node.property)
|
|
769
823
|
}
|
|
@@ -780,6 +834,20 @@ class PHPGenerator {
|
|
|
780
834
|
return `${object}->${property}`
|
|
781
835
|
}
|
|
782
836
|
|
|
837
|
+
translateMethodName(name) {
|
|
838
|
+
if (!name) return name
|
|
839
|
+
const translated = this.translate(name)
|
|
840
|
+
if (translated.includes('->')) {
|
|
841
|
+
const parts = translated.split('->')
|
|
842
|
+
return parts[parts.length - 1].replace(/\(\)$/, '')
|
|
843
|
+
}
|
|
844
|
+
if (translated.includes('::')) {
|
|
845
|
+
const parts = translated.split('::')
|
|
846
|
+
return parts[parts.length - 1].replace(/\(\)$/, '')
|
|
847
|
+
}
|
|
848
|
+
return translated.replace(/\(\)$/, '')
|
|
849
|
+
}
|
|
850
|
+
|
|
783
851
|
generateStaticMemberExpression(node) {
|
|
784
852
|
const cls = this.generateNode(node.class)
|
|
785
853
|
let member
|
|
@@ -801,6 +869,14 @@ class PHPGenerator {
|
|
|
801
869
|
return `${object}[${index}]`
|
|
802
870
|
}
|
|
803
871
|
|
|
872
|
+
generateYieldExpression(node) {
|
|
873
|
+
const argument = node.argument ? this.generateNode(node.argument) : ''
|
|
874
|
+
if (node.delegate) {
|
|
875
|
+
return `yield from ${argument}`
|
|
876
|
+
}
|
|
877
|
+
return argument ? `yield ${argument}` : 'yield'
|
|
878
|
+
}
|
|
879
|
+
|
|
804
880
|
generateBinaryExpression(node) {
|
|
805
881
|
const left = this.generateNode(node.left)
|
|
806
882
|
const right = this.generateNode(node.right)
|