ether-code 0.8.7 → 0.8.9
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 +63 -3
- package/lexer/ether-lexer.js +387 -363
- package/package.json +1 -1
- package/parsers/ether-parser-base.js +8 -8
- 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
|
|
|
@@ -817,6 +869,14 @@ class PHPGenerator {
|
|
|
817
869
|
return `${object}[${index}]`
|
|
818
870
|
}
|
|
819
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
|
+
|
|
820
880
|
generateBinaryExpression(node) {
|
|
821
881
|
const left = this.generateNode(node.left)
|
|
822
882
|
const right = this.generateNode(node.right)
|