ether-code 0.7.5 → 0.7.7
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/ether-compiler.js +1 -1
- package/generators/js-generator.js +3 -2
- package/package.json +1 -1
- package/ether-parser.js +0 -4307
package/ether-parser.js
DELETED
|
@@ -1,4307 +0,0 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const { EtherLexer, Token, TokenType } = require('./lexer/ether-lexer')
|
|
3
|
-
|
|
4
|
-
class EtherParser {
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.tokens = []
|
|
7
|
-
this.pos = 0
|
|
8
|
-
this.currentIndent = 0
|
|
9
|
-
this.i18n = {}
|
|
10
|
-
this.reverseMaps = {}
|
|
11
|
-
this.targetLang = options.targetLang || 'auto'
|
|
12
|
-
|
|
13
|
-
this.loadAllI18n(options.i18nDir || './i18n')
|
|
14
|
-
this.initCompoundTerms()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
initCompoundTerms() {
|
|
18
|
-
this.compoundOperators = {
|
|
19
|
-
'strictement egal': '===',
|
|
20
|
-
'strictement égal': '===',
|
|
21
|
-
'strictement different': '!==',
|
|
22
|
-
'strictement différent': '!==',
|
|
23
|
-
'superieur ou egal': '>=',
|
|
24
|
-
'supérieur ou égal': '>=',
|
|
25
|
-
'inferieur ou egal': '<=',
|
|
26
|
-
'inférieur ou égal': '<=',
|
|
27
|
-
'coalescence nulle': '??',
|
|
28
|
-
'chainage optionnel': '?.',
|
|
29
|
-
'chaînage optionnel': '?.'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.compoundKeywords = {
|
|
33
|
-
'sinon si': 'else if',
|
|
34
|
-
'tant que': 'while',
|
|
35
|
-
'pour chaque': 'forEach',
|
|
36
|
-
'fonction asynchrone': 'async function',
|
|
37
|
-
'fonction async': 'async function',
|
|
38
|
-
'fonction generatrice': 'function*',
|
|
39
|
-
'fonction génératrice': 'function*',
|
|
40
|
-
'variable globale': 'var'
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.jsTranslations = {
|
|
44
|
-
'variable': 'let',
|
|
45
|
-
'constante': 'const',
|
|
46
|
-
'fonction': 'function',
|
|
47
|
-
'retourner': 'return',
|
|
48
|
-
'si': 'if',
|
|
49
|
-
'sinon': 'else',
|
|
50
|
-
'pour': 'for',
|
|
51
|
-
'de': 'of',
|
|
52
|
-
'dans': 'in',
|
|
53
|
-
'selon': 'switch',
|
|
54
|
-
'cas': 'case',
|
|
55
|
-
'defaut': 'default',
|
|
56
|
-
'sortir': 'break',
|
|
57
|
-
'continuer': 'continue',
|
|
58
|
-
'essayer': 'try',
|
|
59
|
-
'attraper': 'catch',
|
|
60
|
-
'finalement': 'finally',
|
|
61
|
-
'lancer': 'throw',
|
|
62
|
-
'nouveau': 'new',
|
|
63
|
-
'supprimer': 'delete',
|
|
64
|
-
'vrai': 'true',
|
|
65
|
-
'faux': 'false',
|
|
66
|
-
'nul': 'null',
|
|
67
|
-
'indefini': 'undefined',
|
|
68
|
-
'ceci': 'this',
|
|
69
|
-
'classe': 'class',
|
|
70
|
-
'etendre': 'extends',
|
|
71
|
-
'super': 'super',
|
|
72
|
-
'constructeur': 'constructor',
|
|
73
|
-
'statique': 'static',
|
|
74
|
-
'obtenir': 'get',
|
|
75
|
-
'definir': 'set',
|
|
76
|
-
'asynchrone': 'async',
|
|
77
|
-
'attendre': 'await',
|
|
78
|
-
'importer': 'import',
|
|
79
|
-
'exporter': 'export',
|
|
80
|
-
'depuis': 'from',
|
|
81
|
-
'comme': 'as',
|
|
82
|
-
'addition': '+',
|
|
83
|
-
'soustraction': '-',
|
|
84
|
-
'multiplication': '*',
|
|
85
|
-
'division': '/',
|
|
86
|
-
'modulo': '%',
|
|
87
|
-
'puissance': '**',
|
|
88
|
-
'increment': '++',
|
|
89
|
-
'decrement': '--',
|
|
90
|
-
'egal': '==',
|
|
91
|
-
'different': '!=',
|
|
92
|
-
'superieur': '>',
|
|
93
|
-
'inferieur': '<',
|
|
94
|
-
'et': '&&',
|
|
95
|
-
'ou': '||',
|
|
96
|
-
'non': '!',
|
|
97
|
-
'document': 'document',
|
|
98
|
-
'fenetre': 'window',
|
|
99
|
-
'console': 'console',
|
|
100
|
-
'journal': 'console.log',
|
|
101
|
-
'erreur': 'console.error',
|
|
102
|
-
'avertir': 'console.warn',
|
|
103
|
-
'info': 'console.info',
|
|
104
|
-
'promesse': 'Promise',
|
|
105
|
-
'resoudre': 'resolve',
|
|
106
|
-
'rejeter': 'reject',
|
|
107
|
-
'alors': 'then',
|
|
108
|
-
'tout': 'all',
|
|
109
|
-
'course': 'race',
|
|
110
|
-
'json': 'JSON',
|
|
111
|
-
'serialiser': 'stringify',
|
|
112
|
-
'analyser': 'parse',
|
|
113
|
-
'math': 'Math',
|
|
114
|
-
'aleatoire': 'random',
|
|
115
|
-
'arrondir': 'round',
|
|
116
|
-
'plancher': 'floor',
|
|
117
|
-
'plafond': 'ceil',
|
|
118
|
-
'absolu': 'abs',
|
|
119
|
-
'maximum': 'max',
|
|
120
|
-
'minimum': 'min',
|
|
121
|
-
|
|
122
|
-
'maintenant': 'now',
|
|
123
|
-
|
|
124
|
-
'ensemble': 'Set',
|
|
125
|
-
'symbole': 'Symbol',
|
|
126
|
-
'objet': 'Object',
|
|
127
|
-
'selecteur': 'querySelector',
|
|
128
|
-
'sur': 'addEventListener',
|
|
129
|
-
'longueur': 'length',
|
|
130
|
-
'taille': 'size',
|
|
131
|
-
'recuperer': 'fetch',
|
|
132
|
-
'transformer': 'map',
|
|
133
|
-
'filtrer': 'filter',
|
|
134
|
-
'reduire': 'reduce',
|
|
135
|
-
'trouver': 'find',
|
|
136
|
-
'certains': 'some',
|
|
137
|
-
'tous': 'every',
|
|
138
|
-
'inclut': 'includes',
|
|
139
|
-
'joindre': 'join',
|
|
140
|
-
'inverser': 'reverse',
|
|
141
|
-
'trier': 'sort',
|
|
142
|
-
'decouper': 'slice',
|
|
143
|
-
'concatener': 'concat',
|
|
144
|
-
'ajouter': 'push',
|
|
145
|
-
'retirer': 'pop',
|
|
146
|
-
'diviser': 'split',
|
|
147
|
-
'remplacer': 'replace',
|
|
148
|
-
'rogner': 'trim',
|
|
149
|
-
'repeter': 'repeat'
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
normalizeAccents(str) {
|
|
154
|
-
return str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
tryMatchCompoundOperator() {
|
|
158
|
-
const current = this.current()
|
|
159
|
-
if (!current || current.type !== TokenType.IDENTIFIER) return null
|
|
160
|
-
|
|
161
|
-
const val1 = this.normalizeAccents(String(current.value))
|
|
162
|
-
const next = this.peek(1)
|
|
163
|
-
const next2 = this.peek(2)
|
|
164
|
-
|
|
165
|
-
if (next && next.type === TokenType.IDENTIFIER) {
|
|
166
|
-
const val2 = this.normalizeAccents(String(next.value))
|
|
167
|
-
|
|
168
|
-
if (next2 && next2.type === TokenType.IDENTIFIER) {
|
|
169
|
-
const val3 = this.normalizeAccents(String(next2.value))
|
|
170
|
-
const compound3 = `${val1} ${val2} ${val3}`
|
|
171
|
-
if (this.compoundOperators[compound3]) {
|
|
172
|
-
this.advance()
|
|
173
|
-
this.advance()
|
|
174
|
-
this.advance()
|
|
175
|
-
return this.compoundOperators[compound3]
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const compound2 = `${val1} ${val2}`
|
|
180
|
-
if (this.compoundOperators[compound2]) {
|
|
181
|
-
this.advance()
|
|
182
|
-
this.advance()
|
|
183
|
-
return this.compoundOperators[compound2]
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return null
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
tryMatchCompoundKeyword() {
|
|
191
|
-
const current = this.current()
|
|
192
|
-
if (!current || current.type !== TokenType.IDENTIFIER) return null
|
|
193
|
-
|
|
194
|
-
const val1 = this.normalizeAccents(String(current.value))
|
|
195
|
-
const next = this.peek(1)
|
|
196
|
-
|
|
197
|
-
if (next && next.type === TokenType.IDENTIFIER) {
|
|
198
|
-
const val2 = this.normalizeAccents(String(next.value))
|
|
199
|
-
const compound2 = `${val1} ${val2}`
|
|
200
|
-
if (this.compoundKeywords[compound2]) {
|
|
201
|
-
this.advance()
|
|
202
|
-
this.advance()
|
|
203
|
-
return this.compoundKeywords[compound2]
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return null
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
translateJSIdentifier(word) {
|
|
211
|
-
if (!word) return word
|
|
212
|
-
const lower = this.normalizeAccents(String(word))
|
|
213
|
-
return this.jsTranslations[lower] || word
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
loadAllI18n(dir) {
|
|
217
|
-
const files = [
|
|
218
|
-
'i18n-css.json', 'i18n-html.json', 'i18n-js.json',
|
|
219
|
-
'i18n-php.json', 'i18n-python.json', 'i18n-sql.json',
|
|
220
|
-
'i18n-ruby.json', 'i18n-node.json', 'i18n-react.json',
|
|
221
|
-
'i18n-ts.json', 'i18n-graphql.json'
|
|
222
|
-
]
|
|
223
|
-
|
|
224
|
-
for (const file of files) {
|
|
225
|
-
const lang = file.replace('i18n-', '').replace('.json', '')
|
|
226
|
-
const path = `${dir}/${file}`
|
|
227
|
-
|
|
228
|
-
try {
|
|
229
|
-
if (fs.existsSync(path)) {
|
|
230
|
-
this.i18n[lang] = JSON.parse(fs.readFileSync(path, 'utf-8'))
|
|
231
|
-
this.buildReverseMap(lang)
|
|
232
|
-
}
|
|
233
|
-
} catch (e) {
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
buildReverseMap(lang) {
|
|
239
|
-
this.reverseMaps[lang] = {}
|
|
240
|
-
const data = this.i18n[lang]
|
|
241
|
-
|
|
242
|
-
const processSection = (section, targetKey = lang) => {
|
|
243
|
-
if (!section || typeof section !== 'object') return
|
|
244
|
-
|
|
245
|
-
for (const [key, translations] of Object.entries(section)) {
|
|
246
|
-
if (translations && typeof translations === 'object') {
|
|
247
|
-
if (translations.fr) {
|
|
248
|
-
const frTerms = Array.isArray(translations.fr) ? translations.fr : [translations.fr]
|
|
249
|
-
const target = translations[targetKey] || translations.css || translations.html || translations.js || translations.value
|
|
250
|
-
|
|
251
|
-
for (const term of frTerms) {
|
|
252
|
-
if (typeof term === 'string') {
|
|
253
|
-
this.reverseMaps[lang][term.toLowerCase()] = target
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
for (const [sectionName, sectionData] of Object.entries(data)) {
|
|
262
|
-
processSection(sectionData)
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
peek(offset = 0) {
|
|
267
|
-
const idx = this.pos + offset
|
|
268
|
-
return idx < this.tokens.length ? this.tokens[idx] : null
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
current() {
|
|
272
|
-
return this.tokens[this.pos] || null
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
advance() {
|
|
276
|
-
const token = this.tokens[this.pos]
|
|
277
|
-
this.pos++
|
|
278
|
-
return token
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
expect(type) {
|
|
282
|
-
const token = this.current()
|
|
283
|
-
if (!token || token.type !== type) {
|
|
284
|
-
throw new Error(`Attendu ${type}, reçu ${token ? token.type : 'EOF'}`)
|
|
285
|
-
}
|
|
286
|
-
return this.advance()
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
match(type) {
|
|
290
|
-
if (this.current() && this.current().type === type) {
|
|
291
|
-
return this.advance()
|
|
292
|
-
}
|
|
293
|
-
return null
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
matchValue(value) {
|
|
297
|
-
const token = this.current()
|
|
298
|
-
if (!token || token.value === null || token.value === undefined) return null
|
|
299
|
-
const tokenVal = String(token.value).toLowerCase()
|
|
300
|
-
const valueLower = value.toLowerCase()
|
|
301
|
-
|
|
302
|
-
if (tokenVal === valueLower) {
|
|
303
|
-
return this.advance()
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
if (valueLower.includes(' ')) {
|
|
307
|
-
const parts = valueLower.split(' ')
|
|
308
|
-
if (tokenVal === parts[0]) {
|
|
309
|
-
const savedPos = this.pos
|
|
310
|
-
const tokens = [this.advance()]
|
|
311
|
-
let matched = true
|
|
312
|
-
|
|
313
|
-
for (let i = 1; i < parts.length && matched; i++) {
|
|
314
|
-
const nextToken = this.current()
|
|
315
|
-
if (nextToken && String(nextToken.value).toLowerCase() === parts[i]) {
|
|
316
|
-
tokens.push(this.advance())
|
|
317
|
-
} else {
|
|
318
|
-
matched = false
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (matched) {
|
|
323
|
-
return tokens[tokens.length - 1]
|
|
324
|
-
} else {
|
|
325
|
-
this.pos = savedPos
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return null
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
isAtEnd() {
|
|
334
|
-
return this.pos >= this.tokens.length || (this.current() && this.current().type === TokenType.EOF)
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
skipNewlines() {
|
|
338
|
-
while (this.match(TokenType.NEWLINE)) {}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
detectTargetLanguage(source) {
|
|
342
|
-
const lower = source.toLowerCase()
|
|
343
|
-
|
|
344
|
-
const targetMatch = source.match(/\/\/\s*cible\s*:\s*(\w+)/i)
|
|
345
|
-
if (targetMatch) {
|
|
346
|
-
const target = targetMatch[1].toLowerCase()
|
|
347
|
-
const langMap = {
|
|
348
|
-
'js': 'js', 'javascript': 'js',
|
|
349
|
-
'css': 'css', 'style': 'css',
|
|
350
|
-
'html': 'html', 'page': 'html',
|
|
351
|
-
'ts': 'ts', 'typescript': 'ts',
|
|
352
|
-
'react': 'react', 'jsx': 'react',
|
|
353
|
-
'php': 'php',
|
|
354
|
-
'python': 'python', 'py': 'python',
|
|
355
|
-
'ruby': 'ruby', 'rb': 'ruby',
|
|
356
|
-
'sql': 'sql',
|
|
357
|
-
'node': 'node', 'nodejs': 'node',
|
|
358
|
-
'graphql': 'graphql', 'gql': 'graphql'
|
|
359
|
-
}
|
|
360
|
-
if (langMap[target]) {
|
|
361
|
-
return langMap[target]
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (/^\s*(document|page|<!doctype|<html|tete|corps|entete|navigation|section|article)/m.test(lower)) {
|
|
366
|
-
return 'html'
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (/^\s*(\.|#|@media|@keyframes|corps|html|body|fond|marge|remplissage|largeur|hauteur)/m.test(lower)) {
|
|
370
|
-
if (!/fonction|si\s|pour\s|tant que/.test(lower)) {
|
|
371
|
-
return 'css'
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (/^\s*(composant|etat|effet|memo|contexte|utiliser\s+(etat|effet|memo)|retourner\s*\(?\s*<)/m.test(lower)) {
|
|
376
|
-
return 'react'
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (/<[a-z]+|jsx|tsx/i.test(lower) && /fonction|composant/.test(lower)) {
|
|
380
|
-
return 'react'
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (/^\s*(creer table|inserer|selectionner|mettre a jour|supprimer|table|base de donnees)/m.test(lower)) {
|
|
384
|
-
return 'sql'
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (/^\s*(type|interface|enum|generique|<[A-Z]\w*>)/m.test(lower)) {
|
|
388
|
-
return 'ts'
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (/^\s*(schema|type\s+\w+\s*{|query|mutation|subscription|input\s+\w+)/m.test(lower)) {
|
|
392
|
-
return 'graphql'
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (/^\s*(<\?php|\$\w+|echo|inclure|require)/m.test(lower)) {
|
|
396
|
-
return 'php'
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
if (/^\s*(def\s+\w+|classe\s+\w+|importer\s|de\s+\w+\s+importer)/m.test(lower) && !/fin\s*$|faire\s*$/m.test(lower)) {
|
|
400
|
-
return 'python'
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (/^\s*(classe\s+\w+|def\s+\w+|fin\s*$|faire\s*$|module\s+\w+)/m.test(lower)) {
|
|
404
|
-
return 'ruby'
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
if (/^\s*(const\s+\w+\s*=\s*require|module\.exports|exporter\s+defaut)/m.test(lower)) {
|
|
408
|
-
return 'node'
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (/fonction|variable|constante|si\s|pour\s|tant que|retourner/.test(lower)) {
|
|
412
|
-
return 'js'
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return 'js'
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
parse(source, targetLang = null) {
|
|
419
|
-
const lexer = new EtherLexer(source)
|
|
420
|
-
this.tokens = lexer.tokenize()
|
|
421
|
-
this.pos = 0
|
|
422
|
-
|
|
423
|
-
const detectedLang = targetLang || this.targetLang
|
|
424
|
-
const lang = detectedLang === 'auto' ? this.detectTargetLanguage(source) : detectedLang
|
|
425
|
-
|
|
426
|
-
switch (lang) {
|
|
427
|
-
case 'css':
|
|
428
|
-
return this.parseCSS()
|
|
429
|
-
case 'html':
|
|
430
|
-
return this.parseHTML()
|
|
431
|
-
case 'js':
|
|
432
|
-
case 'javascript':
|
|
433
|
-
return this.parseJS()
|
|
434
|
-
case 'ts':
|
|
435
|
-
case 'typescript':
|
|
436
|
-
return this.parseTS()
|
|
437
|
-
case 'react':
|
|
438
|
-
case 'jsx':
|
|
439
|
-
return this.parseReact()
|
|
440
|
-
case 'php':
|
|
441
|
-
return this.parsePHP()
|
|
442
|
-
case 'python':
|
|
443
|
-
case 'py':
|
|
444
|
-
return this.parsePython()
|
|
445
|
-
case 'ruby':
|
|
446
|
-
case 'rb':
|
|
447
|
-
return this.parseRuby()
|
|
448
|
-
case 'sql':
|
|
449
|
-
return this.parseSQL()
|
|
450
|
-
case 'node':
|
|
451
|
-
case 'nodejs':
|
|
452
|
-
return this.parseNode()
|
|
453
|
-
case 'graphql':
|
|
454
|
-
case 'gql':
|
|
455
|
-
return this.parseGraphQL()
|
|
456
|
-
default:
|
|
457
|
-
return this.parseJS()
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
parseCSS() {
|
|
462
|
-
const stylesheet = {
|
|
463
|
-
type: 'StyleSheet',
|
|
464
|
-
rules: []
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
this.skipNewlines()
|
|
468
|
-
|
|
469
|
-
while (!this.isAtEnd()) {
|
|
470
|
-
const startPos = this.pos
|
|
471
|
-
const rule = this.parseCSSRule()
|
|
472
|
-
if (rule) {
|
|
473
|
-
stylesheet.rules.push(rule)
|
|
474
|
-
}
|
|
475
|
-
this.skipNewlines()
|
|
476
|
-
if (this.pos === startPos && !this.isAtEnd()) {
|
|
477
|
-
this.advance()
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
return stylesheet
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
parseCSSRule() {
|
|
485
|
-
this.skipNewlines()
|
|
486
|
-
const token = this.current()
|
|
487
|
-
if (!token || token.type === TokenType.EOF) return null
|
|
488
|
-
|
|
489
|
-
if (token.type === TokenType.AT) {
|
|
490
|
-
return this.parseCSSAtRule()
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const selector = this.parseCSSSelector()
|
|
494
|
-
if (!selector) return null
|
|
495
|
-
|
|
496
|
-
this.skipNewlines()
|
|
497
|
-
this.match(TokenType.INDENT)
|
|
498
|
-
|
|
499
|
-
const declarations = []
|
|
500
|
-
const nestedRules = []
|
|
501
|
-
|
|
502
|
-
while (!this.isAtEnd()) {
|
|
503
|
-
const current = this.current()
|
|
504
|
-
|
|
505
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
506
|
-
this.advance()
|
|
507
|
-
break
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
511
|
-
this.advance()
|
|
512
|
-
continue
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
if (!current || current.type === TokenType.EOF) break
|
|
516
|
-
|
|
517
|
-
if (current.type === TokenType.IDENTIFIER) {
|
|
518
|
-
const value = current.value.toLowerCase()
|
|
519
|
-
|
|
520
|
-
if (value.startsWith('au ') || value === 'au survol' || value === 'au clic' ||
|
|
521
|
-
value === 'au focus' || value === 'actif' || value === 'visite' ||
|
|
522
|
-
value.startsWith('premier') || value.startsWith('dernier') ||
|
|
523
|
-
value.startsWith('avant') || value.startsWith('apres')) {
|
|
524
|
-
const pseudoRule = this.parseCSSPseudoBlock(selector)
|
|
525
|
-
if (pseudoRule) nestedRules.push(pseudoRule)
|
|
526
|
-
continue
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
const decl = this.parseCSSDeclaration()
|
|
531
|
-
if (decl) {
|
|
532
|
-
declarations.push(decl)
|
|
533
|
-
} else {
|
|
534
|
-
this.advance()
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
return {
|
|
539
|
-
type: 'Rule',
|
|
540
|
-
selector: selector,
|
|
541
|
-
declarations: declarations,
|
|
542
|
-
nestedRules: nestedRules
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
parseCSSSelector() {
|
|
547
|
-
const parts = []
|
|
548
|
-
|
|
549
|
-
while (!this.isAtEnd()) {
|
|
550
|
-
const token = this.current()
|
|
551
|
-
|
|
552
|
-
if (!token || token.type === TokenType.NEWLINE || token.type === TokenType.INDENT ||
|
|
553
|
-
token.type === TokenType.EOF) {
|
|
554
|
-
break
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
if (token.type === TokenType.DOUBLE_COLON) {
|
|
558
|
-
this.advance()
|
|
559
|
-
const pseudoName = this.current()
|
|
560
|
-
if (pseudoName && pseudoName.type === TokenType.IDENTIFIER) {
|
|
561
|
-
parts.push('::' + pseudoName.value)
|
|
562
|
-
this.advance()
|
|
563
|
-
}
|
|
564
|
-
} else if (token.type === TokenType.COLON) {
|
|
565
|
-
this.advance()
|
|
566
|
-
const next = this.current()
|
|
567
|
-
if (next && next.type === TokenType.COLON) {
|
|
568
|
-
this.advance()
|
|
569
|
-
const pseudoName = this.current()
|
|
570
|
-
if (pseudoName && pseudoName.type === TokenType.IDENTIFIER) {
|
|
571
|
-
parts.push('::' + pseudoName.value)
|
|
572
|
-
this.advance()
|
|
573
|
-
}
|
|
574
|
-
} else if (next && next.type === TokenType.IDENTIFIER) {
|
|
575
|
-
parts.push(':' + next.value)
|
|
576
|
-
this.advance()
|
|
577
|
-
} else {
|
|
578
|
-
break
|
|
579
|
-
}
|
|
580
|
-
} else if (token.type === TokenType.DOT) {
|
|
581
|
-
this.advance()
|
|
582
|
-
const name = this.current()
|
|
583
|
-
if (name && name.type === TokenType.IDENTIFIER) {
|
|
584
|
-
parts.push('.' + name.value)
|
|
585
|
-
this.advance()
|
|
586
|
-
}
|
|
587
|
-
} else if (token.type === TokenType.HASH) {
|
|
588
|
-
this.advance()
|
|
589
|
-
const name = this.current()
|
|
590
|
-
if (name && name.type === TokenType.IDENTIFIER) {
|
|
591
|
-
parts.push('#' + name.value)
|
|
592
|
-
this.advance()
|
|
593
|
-
}
|
|
594
|
-
} else if (token.type === TokenType.IDENTIFIER) {
|
|
595
|
-
parts.push(this.translateCSSSelector(token.value))
|
|
596
|
-
this.advance()
|
|
597
|
-
} else if (token.type === TokenType.STAR) {
|
|
598
|
-
parts.push('*')
|
|
599
|
-
this.advance()
|
|
600
|
-
} else if (token.type === TokenType.COMMA) {
|
|
601
|
-
parts.push(',')
|
|
602
|
-
this.advance()
|
|
603
|
-
} else if (token.type === TokenType.GT) {
|
|
604
|
-
parts.push('>')
|
|
605
|
-
this.advance()
|
|
606
|
-
} else if (token.type === TokenType.PLUS) {
|
|
607
|
-
parts.push('+')
|
|
608
|
-
this.advance()
|
|
609
|
-
} else if (token.type === TokenType.TILDE) {
|
|
610
|
-
parts.push('~')
|
|
611
|
-
this.advance()
|
|
612
|
-
} else if (token.type === TokenType.LBRACKET) {
|
|
613
|
-
let attrSelector = '['
|
|
614
|
-
this.advance()
|
|
615
|
-
while (!this.isAtEnd()) {
|
|
616
|
-
const attrToken = this.current()
|
|
617
|
-
if (!attrToken || attrToken.type === TokenType.RBRACKET) {
|
|
618
|
-
attrSelector += ']'
|
|
619
|
-
this.advance()
|
|
620
|
-
break
|
|
621
|
-
}
|
|
622
|
-
attrSelector += attrToken.value
|
|
623
|
-
this.advance()
|
|
624
|
-
}
|
|
625
|
-
parts.push(attrSelector)
|
|
626
|
-
} else if (token.type === TokenType.EQUALS) {
|
|
627
|
-
break
|
|
628
|
-
} else {
|
|
629
|
-
break
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
return parts.join(' ').replace(/\s+([,>+~])\s+/g, ' $1 ').replace(/\s+(::?)/g, '$1').trim()
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
translateCSSSelector(selector) {
|
|
637
|
-
const map = this.reverseMaps.css || {}
|
|
638
|
-
const lower = selector.toLowerCase()
|
|
639
|
-
|
|
640
|
-
const selectorTranslations = {
|
|
641
|
-
'corps': 'body',
|
|
642
|
-
'html': 'html',
|
|
643
|
-
'document': 'html',
|
|
644
|
-
'tete': 'head',
|
|
645
|
-
'titre': 'title',
|
|
646
|
-
'titre1': 'h1',
|
|
647
|
-
'titre2': 'h2',
|
|
648
|
-
'titre3': 'h3',
|
|
649
|
-
'titre4': 'h4',
|
|
650
|
-
'titre5': 'h5',
|
|
651
|
-
'titre6': 'h6',
|
|
652
|
-
'paragraphe': 'p',
|
|
653
|
-
'lien': 'a',
|
|
654
|
-
'ressource': 'link',
|
|
655
|
-
'lien externe': 'link',
|
|
656
|
-
'image': 'img',
|
|
657
|
-
'bouton': 'button',
|
|
658
|
-
'formulaire': 'form',
|
|
659
|
-
'champ': 'input',
|
|
660
|
-
'liste': 'ul',
|
|
661
|
-
'liste ordonnee': 'ol',
|
|
662
|
-
'element liste': 'li',
|
|
663
|
-
'tableau': 'table',
|
|
664
|
-
'ligne': 'tr',
|
|
665
|
-
'cellule': 'td',
|
|
666
|
-
'entete': 'header',
|
|
667
|
-
'piedpage': 'footer',
|
|
668
|
-
'navigation': 'nav',
|
|
669
|
-
'section': 'section',
|
|
670
|
-
'article': 'article',
|
|
671
|
-
'cote': 'aside',
|
|
672
|
-
'principal': 'main',
|
|
673
|
-
'division': 'div',
|
|
674
|
-
'portee': 'span'
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return selectorTranslations[lower] || map[lower] || selector
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
parseCSSDeclaration() {
|
|
681
|
-
this.skipNewlines()
|
|
682
|
-
const token = this.current()
|
|
683
|
-
if (!token || token.type !== TokenType.IDENTIFIER) return null
|
|
684
|
-
|
|
685
|
-
const compoundProperties = {
|
|
686
|
-
'marge': ['dedans', 'autour', 'haut', 'bas', 'gauche', 'droite'],
|
|
687
|
-
'marge dedans': ['haut', 'bas', 'gauche', 'droite'],
|
|
688
|
-
'marge autour': ['haut', 'bas', 'gauche', 'droite'],
|
|
689
|
-
'remplissage': ['haut', 'bas', 'gauche', 'droite'],
|
|
690
|
-
'taille': ['police'],
|
|
691
|
-
'poids': ['police'],
|
|
692
|
-
'style': ['police', 'liste'],
|
|
693
|
-
'hauteur': ['ligne', 'min', 'max', 'minimum', 'maximum'],
|
|
694
|
-
'largeur': ['min', 'max', 'minimum', 'maximum'],
|
|
695
|
-
'alignement': ['texte'],
|
|
696
|
-
'decoration': ['texte'],
|
|
697
|
-
'transformation': ['texte'],
|
|
698
|
-
'ombre': ['texte', 'boite', 'boîte'],
|
|
699
|
-
'espacement': ['lettres'],
|
|
700
|
-
'bordure': ['haut', 'bas', 'gauche', 'droite', 'couleur', 'style', 'largeur', 'arrondi'],
|
|
701
|
-
'couleur': ['bordure', 'fond', 'texte', 'remplissage'],
|
|
702
|
-
'arrondi': ['haut', 'bas'],
|
|
703
|
-
'arrondi haut': ['gauche', 'droite'],
|
|
704
|
-
'arrondi bas': ['gauche', 'droite'],
|
|
705
|
-
'fond': ['couleur', 'image', 'position', 'taille', 'repetition', 'attachement'],
|
|
706
|
-
'direction': ['flex'],
|
|
707
|
-
'enveloppe': ['flex'],
|
|
708
|
-
'justifier': ['contenu'],
|
|
709
|
-
'aligner': ['elements', 'éléments', 'contenu'],
|
|
710
|
-
'colonnes': ['grille'],
|
|
711
|
-
'lignes': ['grille'],
|
|
712
|
-
'espace': ['ligne', 'colonne', 'blanc'],
|
|
713
|
-
'débordement': ['x', 'y'],
|
|
714
|
-
'debordement': ['x', 'y'],
|
|
715
|
-
'événements': ['pointeur'],
|
|
716
|
-
'evenements': ['pointeur'],
|
|
717
|
-
'modèle': ['boite', 'boîte'],
|
|
718
|
-
'modele': ['boite', 'boîte'],
|
|
719
|
-
'filtre': ['fond'],
|
|
720
|
-
'decoupe': ['fond'],
|
|
721
|
-
'découpe': ['fond'],
|
|
722
|
-
'origine': ['transformation', 'perspective'],
|
|
723
|
-
'liste': ['style', 'type', 'position', 'image'],
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
let property = token.value
|
|
727
|
-
this.advance()
|
|
728
|
-
|
|
729
|
-
let nextToken = this.current()
|
|
730
|
-
while (nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
731
|
-
const propLower = property.toLowerCase()
|
|
732
|
-
if (compoundProperties[propLower] && compoundProperties[propLower].includes(nextToken.value.toLowerCase())) {
|
|
733
|
-
property = property + ' ' + nextToken.value
|
|
734
|
-
this.advance()
|
|
735
|
-
nextToken = this.current()
|
|
736
|
-
} else {
|
|
737
|
-
break
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
let hasColon = this.match(TokenType.COLON)
|
|
742
|
-
let hasEquals = !hasColon && this.match(TokenType.EQUALS)
|
|
743
|
-
|
|
744
|
-
if (!hasColon && !hasEquals) {
|
|
745
|
-
return null
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
const valueParts = []
|
|
749
|
-
let lastType = null
|
|
750
|
-
|
|
751
|
-
while (!this.isAtEnd()) {
|
|
752
|
-
const current = this.current()
|
|
753
|
-
|
|
754
|
-
if (!current || current.type === TokenType.NEWLINE ||
|
|
755
|
-
current.type === TokenType.DEDENT || current.type === TokenType.EOF) {
|
|
756
|
-
break
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
let needsSpace = valueParts.length > 0
|
|
760
|
-
|
|
761
|
-
if (current.type === TokenType.LPAREN || current.type === TokenType.COMMA ||
|
|
762
|
-
current.type === TokenType.RPAREN || current.type === TokenType.PERCENT ||
|
|
763
|
-
lastType === TokenType.LPAREN || lastType === TokenType.MINUS ||
|
|
764
|
-
lastType === TokenType.HASH || lastType === TokenType.COLON) {
|
|
765
|
-
needsSpace = false
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
if (lastType === TokenType.NUMBER || lastType === TokenType.INTEGER || lastType === TokenType.FLOAT) {
|
|
769
|
-
if (current.type === TokenType.IDENTIFIER) {
|
|
770
|
-
const units = ['px', 'em', 'rem', '%', 'vw', 'vh', 'vmin', 'vmax', 'ch', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', 'deg', 'rad', 'turn', 'ms', 's', 'fr', 'cqw', 'cqh']
|
|
771
|
-
if (units.includes(current.value.toLowerCase())) {
|
|
772
|
-
needsSpace = false
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
if (current.type === TokenType.IDENTIFIER) {
|
|
778
|
-
if (needsSpace) valueParts.push(' ')
|
|
779
|
-
valueParts.push(current.value)
|
|
780
|
-
} else if (current.type === TokenType.NUMBER || current.type === TokenType.INTEGER ||
|
|
781
|
-
current.type === TokenType.FLOAT) {
|
|
782
|
-
if (needsSpace && lastType !== TokenType.HASH) valueParts.push(' ')
|
|
783
|
-
valueParts.push(current.value)
|
|
784
|
-
} else if (current.type === TokenType.STRING) {
|
|
785
|
-
if (needsSpace) valueParts.push(' ')
|
|
786
|
-
valueParts.push('"' + current.value + '"')
|
|
787
|
-
} else if (current.type === TokenType.HEX) {
|
|
788
|
-
if (needsSpace) valueParts.push(' ')
|
|
789
|
-
valueParts.push(current.value)
|
|
790
|
-
} else if (current.type === TokenType.HASH) {
|
|
791
|
-
if (needsSpace) valueParts.push(' ')
|
|
792
|
-
valueParts.push('#')
|
|
793
|
-
} else if (current.type === TokenType.COMMA) {
|
|
794
|
-
valueParts.push(',')
|
|
795
|
-
} else if (current.type === TokenType.LPAREN) {
|
|
796
|
-
valueParts.push('(')
|
|
797
|
-
} else if (current.type === TokenType.RPAREN) {
|
|
798
|
-
valueParts.push(')')
|
|
799
|
-
} else if (current.type === TokenType.PERCENT) {
|
|
800
|
-
valueParts.push('%')
|
|
801
|
-
} else if (current.type === TokenType.SLASH) {
|
|
802
|
-
if (needsSpace) valueParts.push(' ')
|
|
803
|
-
valueParts.push('/')
|
|
804
|
-
} else if (current.type === TokenType.MINUS) {
|
|
805
|
-
if (current.value === '--') {
|
|
806
|
-
valueParts.push('--')
|
|
807
|
-
} else if (lastType === TokenType.LPAREN) {
|
|
808
|
-
valueParts.push(current.value)
|
|
809
|
-
} else {
|
|
810
|
-
valueParts.push(' ' + current.value)
|
|
811
|
-
}
|
|
812
|
-
} else if (current.type === TokenType.PLUS) {
|
|
813
|
-
valueParts.push(' +')
|
|
814
|
-
} else if (current.type === TokenType.COLON) {
|
|
815
|
-
valueParts.push(':')
|
|
816
|
-
} else if (current.type === TokenType.DOT) {
|
|
817
|
-
valueParts.push('.')
|
|
818
|
-
} else {
|
|
819
|
-
break
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
lastType = current.type
|
|
823
|
-
this.advance()
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
return {
|
|
827
|
-
type: 'Declaration',
|
|
828
|
-
property: property,
|
|
829
|
-
value: valueParts.join('')
|
|
830
|
-
.replace(/,\s*/g, ', ')
|
|
831
|
-
.replace(/\s+/g, ' ')
|
|
832
|
-
.trim()
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
parseCSSPseudoBlock(parentSelector) {
|
|
837
|
-
const pseudoToken = this.current()
|
|
838
|
-
const pseudoClass = this.translatePseudoClass(pseudoToken.value)
|
|
839
|
-
this.advance()
|
|
840
|
-
|
|
841
|
-
this.skipNewlines()
|
|
842
|
-
this.match(TokenType.INDENT)
|
|
843
|
-
|
|
844
|
-
const declarations = []
|
|
845
|
-
|
|
846
|
-
while (!this.isAtEnd()) {
|
|
847
|
-
const current = this.current()
|
|
848
|
-
|
|
849
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
850
|
-
this.advance()
|
|
851
|
-
break
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
855
|
-
this.advance()
|
|
856
|
-
continue
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
if (!current || current.type === TokenType.EOF) break
|
|
860
|
-
|
|
861
|
-
const decl = this.parseCSSDeclaration()
|
|
862
|
-
if (decl) {
|
|
863
|
-
declarations.push(decl)
|
|
864
|
-
} else {
|
|
865
|
-
this.advance()
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
return {
|
|
870
|
-
type: 'Rule',
|
|
871
|
-
selector: `${parentSelector}${pseudoClass}`,
|
|
872
|
-
declarations: declarations
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
translatePseudoClass(value) {
|
|
877
|
-
const map = {
|
|
878
|
-
'au survol': ':hover',
|
|
879
|
-
'au clic': ':active',
|
|
880
|
-
'actif': ':active',
|
|
881
|
-
'au focus': ':focus',
|
|
882
|
-
'focus': ':focus',
|
|
883
|
-
'visite': ':visited',
|
|
884
|
-
'premier enfant': ':first-child',
|
|
885
|
-
'dernier enfant': ':last-child',
|
|
886
|
-
'premier de type': ':first-of-type',
|
|
887
|
-
'dernier de type': ':last-of-type',
|
|
888
|
-
'enfant unique': ':only-child',
|
|
889
|
-
'unique de type': ':only-of-type',
|
|
890
|
-
'vide': ':empty',
|
|
891
|
-
'cible': ':target',
|
|
892
|
-
'coche': ':checked',
|
|
893
|
-
'desactive': ':disabled',
|
|
894
|
-
'active': ':enabled',
|
|
895
|
-
'requis': ':required',
|
|
896
|
-
'optionnel': ':optional',
|
|
897
|
-
'valide': ':valid',
|
|
898
|
-
'invalide': ':invalid',
|
|
899
|
-
'lecture seule': ':read-only',
|
|
900
|
-
'lecture ecriture': ':read-write',
|
|
901
|
-
'avant': '::before',
|
|
902
|
-
'apres': '::after',
|
|
903
|
-
'premiere lettre': '::first-letter',
|
|
904
|
-
'premiere ligne': '::first-line',
|
|
905
|
-
'selection': '::selection',
|
|
906
|
-
'placeholder': '::placeholder',
|
|
907
|
-
'marqueur': '::marker'
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
const lower = value.toLowerCase()
|
|
911
|
-
return map[lower] || ':' + lower.replace(/\s+/g, '-')
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
parseCSSAtRule() {
|
|
915
|
-
this.advance()
|
|
916
|
-
const nameToken = this.current()
|
|
917
|
-
|
|
918
|
-
if (!nameToken) return null
|
|
919
|
-
|
|
920
|
-
const name = nameToken.value.toLowerCase()
|
|
921
|
-
this.advance()
|
|
922
|
-
|
|
923
|
-
if (name === 'media' || name === 'requete media' || name === 'ecran' || name === 'si') {
|
|
924
|
-
return this.parseCSSMediaQuery()
|
|
925
|
-
}
|
|
926
|
-
|
|
927
|
-
if (name === 'keyframes' || name === 'images cles' || name === 'animation') {
|
|
928
|
-
return this.parseCSSKeyframes()
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
if (name === 'import' || name === 'importer') {
|
|
932
|
-
return this.parseCSSImport()
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
if (name === 'font-face' || name === 'police') {
|
|
936
|
-
return this.parseCSSFontFace()
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
return null
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
parseCSSMediaQuery() {
|
|
943
|
-
const queryParts = []
|
|
944
|
-
|
|
945
|
-
while (!this.isAtEnd()) {
|
|
946
|
-
const token = this.current()
|
|
947
|
-
|
|
948
|
-
if (!token || token.type === TokenType.NEWLINE || token.type === TokenType.INDENT) {
|
|
949
|
-
break
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
queryParts.push(token.value)
|
|
953
|
-
this.advance()
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
this.skipNewlines()
|
|
957
|
-
this.match(TokenType.INDENT)
|
|
958
|
-
|
|
959
|
-
const rules = []
|
|
960
|
-
|
|
961
|
-
while (!this.isAtEnd()) {
|
|
962
|
-
const current = this.current()
|
|
963
|
-
|
|
964
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
965
|
-
this.advance()
|
|
966
|
-
break
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
const rule = this.parseCSSRule()
|
|
970
|
-
if (rule) {
|
|
971
|
-
rules.push(rule)
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
this.skipNewlines()
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
return {
|
|
978
|
-
type: 'MediaQuery',
|
|
979
|
-
query: this.translateMediaQuery(queryParts.join(' ')),
|
|
980
|
-
rules: rules
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
translateMediaQuery(query) {
|
|
985
|
-
let result = query
|
|
986
|
-
|
|
987
|
-
result = result.replace(/ecran\s+tres\s+petit/gi, 'screen and (max-width: 480px)')
|
|
988
|
-
result = result.replace(/ecran\s+petit/gi, 'screen and (max-width: 768px)')
|
|
989
|
-
result = result.replace(/ecran\s+moyen/gi, 'screen and (max-width: 1024px)')
|
|
990
|
-
result = result.replace(/ecran\s+large/gi, 'screen and (min-width: 1025px) and (max-width: 1280px)')
|
|
991
|
-
result = result.replace(/ecran\s+tres\s+large/gi, 'screen and (min-width: 1281px)')
|
|
992
|
-
|
|
993
|
-
result = result
|
|
994
|
-
.replace(/ecran/gi, 'screen')
|
|
995
|
-
.replace(/imprimante/gi, 'print')
|
|
996
|
-
.replace(/tous/gi, 'all')
|
|
997
|
-
.replace(/largeur\s+min/gi, 'min-width')
|
|
998
|
-
.replace(/largeur\s+max/gi, 'max-width')
|
|
999
|
-
.replace(/hauteur\s+min/gi, 'min-height')
|
|
1000
|
-
.replace(/hauteur\s+max/gi, 'max-height')
|
|
1001
|
-
.replace(/orientation/gi, 'orientation')
|
|
1002
|
-
.replace(/paysage/gi, 'landscape')
|
|
1003
|
-
.replace(/portrait/gi, 'portrait')
|
|
1004
|
-
.replace(/\bet\b/gi, 'and')
|
|
1005
|
-
.replace(/\bou\b/gi, 'or')
|
|
1006
|
-
.replace(/\bpas\b/gi, 'not')
|
|
1007
|
-
|
|
1008
|
-
return result
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
parseCSSKeyframes() {
|
|
1012
|
-
const nameToken = this.current()
|
|
1013
|
-
const name = nameToken ? nameToken.value : 'animation'
|
|
1014
|
-
if (nameToken) this.advance()
|
|
1015
|
-
|
|
1016
|
-
this.skipNewlines()
|
|
1017
|
-
this.match(TokenType.INDENT)
|
|
1018
|
-
|
|
1019
|
-
const keyframes = []
|
|
1020
|
-
|
|
1021
|
-
while (!this.isAtEnd()) {
|
|
1022
|
-
const current = this.current()
|
|
1023
|
-
|
|
1024
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
1025
|
-
this.advance()
|
|
1026
|
-
break
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
1030
|
-
this.advance()
|
|
1031
|
-
continue
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
const keyframe = this.parseCSSKeyframe()
|
|
1035
|
-
if (keyframe) {
|
|
1036
|
-
keyframes.push(keyframe)
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
return {
|
|
1041
|
-
type: 'Keyframes',
|
|
1042
|
-
name: name,
|
|
1043
|
-
keyframes: keyframes
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
parseCSSKeyframe() {
|
|
1048
|
-
const token = this.current()
|
|
1049
|
-
if (!token) return null
|
|
1050
|
-
|
|
1051
|
-
let selector = token.value
|
|
1052
|
-
|
|
1053
|
-
const selectorMap = {
|
|
1054
|
-
'debut': 'from',
|
|
1055
|
-
'fin': 'to',
|
|
1056
|
-
'de': 'from',
|
|
1057
|
-
'a': 'to',
|
|
1058
|
-
'vers': 'to'
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
selector = selectorMap[selector.toLowerCase()] || selector
|
|
1062
|
-
this.advance()
|
|
1063
|
-
|
|
1064
|
-
this.skipNewlines()
|
|
1065
|
-
this.match(TokenType.INDENT)
|
|
1066
|
-
|
|
1067
|
-
const declarations = []
|
|
1068
|
-
|
|
1069
|
-
while (!this.isAtEnd()) {
|
|
1070
|
-
const current = this.current()
|
|
1071
|
-
|
|
1072
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
1073
|
-
this.advance()
|
|
1074
|
-
break
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
1078
|
-
this.advance()
|
|
1079
|
-
continue
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
const decl = this.parseCSSDeclaration()
|
|
1083
|
-
if (decl) {
|
|
1084
|
-
declarations.push(decl)
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
return {
|
|
1089
|
-
type: 'Keyframe',
|
|
1090
|
-
selector: selector,
|
|
1091
|
-
declarations: declarations
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
parseCSSImport() {
|
|
1096
|
-
const urlToken = this.current()
|
|
1097
|
-
const url = urlToken ? urlToken.value.replace(/['"]/g, '') : ''
|
|
1098
|
-
if (urlToken) this.advance()
|
|
1099
|
-
|
|
1100
|
-
return {
|
|
1101
|
-
type: 'Import',
|
|
1102
|
-
url: url
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
parseCSSFontFace() {
|
|
1107
|
-
this.skipNewlines()
|
|
1108
|
-
this.match(TokenType.INDENT)
|
|
1109
|
-
|
|
1110
|
-
const declarations = []
|
|
1111
|
-
|
|
1112
|
-
while (!this.isAtEnd()) {
|
|
1113
|
-
const current = this.current()
|
|
1114
|
-
|
|
1115
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
1116
|
-
this.advance()
|
|
1117
|
-
break
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
1121
|
-
this.advance()
|
|
1122
|
-
continue
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
const decl = this.parseCSSDeclaration()
|
|
1126
|
-
if (decl) {
|
|
1127
|
-
declarations.push(decl)
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
return {
|
|
1132
|
-
type: 'FontFace',
|
|
1133
|
-
declarations: declarations
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
parseHTML() {
|
|
1138
|
-
const document = {
|
|
1139
|
-
type: 'Document',
|
|
1140
|
-
children: []
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
this.skipNewlines()
|
|
1144
|
-
|
|
1145
|
-
while (!this.isAtEnd()) {
|
|
1146
|
-
const node = this.parseHTMLNode()
|
|
1147
|
-
if (node) {
|
|
1148
|
-
document.children.push(node)
|
|
1149
|
-
}
|
|
1150
|
-
this.skipNewlines()
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
return document
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
parseHTMLNode() {
|
|
1157
|
-
this.skipNewlines()
|
|
1158
|
-
const token = this.current()
|
|
1159
|
-
|
|
1160
|
-
if (!token || token.type === TokenType.EOF) return null
|
|
1161
|
-
|
|
1162
|
-
if (token.type === TokenType.IDENTIFIER) {
|
|
1163
|
-
return this.parseHTMLElement()
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
if (token.type === TokenType.STRING) {
|
|
1167
|
-
this.advance()
|
|
1168
|
-
return {
|
|
1169
|
-
type: 'Text',
|
|
1170
|
-
content: token.value.replace(/^["']|["']$/g, '')
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
|
|
1174
|
-
this.advance()
|
|
1175
|
-
return null
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
parseHTMLElement() {
|
|
1179
|
-
const tagToken = this.current()
|
|
1180
|
-
let tagName = this.normalizeAccents(tagToken.value)
|
|
1181
|
-
const originalTagName = tagName
|
|
1182
|
-
this.advance()
|
|
1183
|
-
|
|
1184
|
-
const includeKeywords = ['inclure', 'requiert', 'include', 'require', 'importer']
|
|
1185
|
-
if (includeKeywords.includes(tagName)) {
|
|
1186
|
-
let includePath = null
|
|
1187
|
-
|
|
1188
|
-
if (this.current() && this.current().type === TokenType.COLON) {
|
|
1189
|
-
this.advance()
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
const pathToken = this.current()
|
|
1193
|
-
if (pathToken && pathToken.type === TokenType.STRING) {
|
|
1194
|
-
includePath = pathToken.value.replace(/^["']|["']$/g, '')
|
|
1195
|
-
this.advance()
|
|
1196
|
-
} else if (pathToken && pathToken.type === TokenType.IDENTIFIER) {
|
|
1197
|
-
let pathParts = [pathToken.value]
|
|
1198
|
-
this.advance()
|
|
1199
|
-
while (this.current() && (this.current().type === TokenType.SLASH || this.current().type === TokenType.DOT || this.current().type === TokenType.IDENTIFIER)) {
|
|
1200
|
-
if (this.current().type === TokenType.SLASH) {
|
|
1201
|
-
pathParts.push('/')
|
|
1202
|
-
} else if (this.current().type === TokenType.DOT) {
|
|
1203
|
-
pathParts.push('.')
|
|
1204
|
-
} else {
|
|
1205
|
-
pathParts.push(this.current().value)
|
|
1206
|
-
}
|
|
1207
|
-
this.advance()
|
|
1208
|
-
}
|
|
1209
|
-
includePath = pathParts.join('')
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
this.skipNewlines()
|
|
1213
|
-
|
|
1214
|
-
return {
|
|
1215
|
-
type: 'Include',
|
|
1216
|
-
path: includePath,
|
|
1217
|
-
resolved: false
|
|
1218
|
-
}
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
const nextToken = this.current()
|
|
1222
|
-
if ((tagName === 'titre' || tagName === 'heading') && nextToken && (nextToken.type === TokenType.NUMBER || nextToken.type === TokenType.INTEGER)) {
|
|
1223
|
-
const num = parseInt(nextToken.value)
|
|
1224
|
-
if (num >= 1 && num <= 6) {
|
|
1225
|
-
tagName = `titre${num}`
|
|
1226
|
-
this.advance()
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
if ((tagName === 'liste' || tagName === 'list') && nextToken) {
|
|
1231
|
-
if (nextToken.type === TokenType.IDENTIFIER) {
|
|
1232
|
-
const nextVal = this.normalizeAccents(nextToken.value)
|
|
1233
|
-
if (nextVal === 'ordonnee' || nextVal === 'ordered') {
|
|
1234
|
-
tagName = 'liste ordonnee'
|
|
1235
|
-
this.advance()
|
|
1236
|
-
} else if (nextVal === 'non') {
|
|
1237
|
-
this.advance()
|
|
1238
|
-
const thirdToken = this.current()
|
|
1239
|
-
if (thirdToken && thirdToken.type === TokenType.IDENTIFIER && this.normalizeAccents(thirdToken.value) === 'ordonnee') {
|
|
1240
|
-
tagName = 'liste non ordonnee'
|
|
1241
|
-
this.advance()
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
if ((tagName === 'element' || tagName === 'item') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1248
|
-
if (this.normalizeAccents(nextToken.value) === 'liste' || this.normalizeAccents(nextToken.value) === 'list') {
|
|
1249
|
-
tagName = 'element liste'
|
|
1250
|
-
this.advance()
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
if ((tagName === 'zone' || tagName === 'area') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1255
|
-
if (this.normalizeAccents(nextToken.value) === 'texte' || this.normalizeAccents(nextToken.value) === 'text') {
|
|
1256
|
-
tagName = 'zone texte'
|
|
1257
|
-
this.advance()
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
if ((tagName === 'retour' || tagName === 'saut') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1262
|
-
if (this.normalizeAccents(nextToken.value) === 'ligne' || this.normalizeAccents(nextToken.value) === 'line') {
|
|
1263
|
-
tagName = 'retour ligne'
|
|
1264
|
-
this.advance()
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
if (tagName === 'ligne' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1269
|
-
if (this.normalizeAccents(nextToken.value) === 'horizontale') {
|
|
1270
|
-
tagName = 'ligne horizontale'
|
|
1271
|
-
this.advance()
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
if ((tagName === 'cellule' || tagName === 'cell') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1276
|
-
if (this.normalizeAccents(nextToken.value) === 'entete' || this.normalizeAccents(nextToken.value) === 'header') {
|
|
1277
|
-
tagName = 'entete cellule'
|
|
1278
|
-
this.advance()
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
if (tagName === 'groupe' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1283
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1284
|
-
if (next === 'titres') {
|
|
1285
|
-
tagName = 'groupe titres'
|
|
1286
|
-
this.advance()
|
|
1287
|
-
} else if (next === 'options') {
|
|
1288
|
-
tagName = 'groupe options'
|
|
1289
|
-
this.advance()
|
|
1290
|
-
} else if (next === 'colonnes') {
|
|
1291
|
-
tagName = 'groupe colonnes'
|
|
1292
|
-
this.advance()
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
if (tagName === 'entete' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1297
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1298
|
-
if (next === 'tableau' || next === 'table') {
|
|
1299
|
-
tagName = 'entete tableau'
|
|
1300
|
-
this.advance()
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
if (tagName === 'corps' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1305
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1306
|
-
if (next === 'tableau' || next === 'table') {
|
|
1307
|
-
tagName = 'corps tableau'
|
|
1308
|
-
this.advance()
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
if (tagName === 'pied' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1313
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1314
|
-
if (next === 'tableau' || next === 'table') {
|
|
1315
|
-
tagName = 'pied tableau'
|
|
1316
|
-
this.advance()
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
if (tagName === 'legende' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1321
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1322
|
-
if (next === 'tableau' || next === 'table') {
|
|
1323
|
-
tagName = 'legende tableau'
|
|
1324
|
-
this.advance()
|
|
1325
|
-
} else if (next === 'figure') {
|
|
1326
|
-
tagName = 'legende figure'
|
|
1327
|
-
this.advance()
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
if (tagName === 'ensemble' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1332
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1333
|
-
if (next === 'champs' || next === 'fields') {
|
|
1334
|
-
tagName = 'ensemble champs'
|
|
1335
|
-
this.advance()
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
if (tagName === 'liste' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1340
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1341
|
-
if (next === 'donnees' || next === 'data') {
|
|
1342
|
-
tagName = 'liste donnees'
|
|
1343
|
-
this.advance()
|
|
1344
|
-
} else if (next === 'description') {
|
|
1345
|
-
tagName = 'liste description'
|
|
1346
|
-
this.advance()
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
if (tagName === 'image' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1351
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1352
|
-
if (next === 'reactive' || next === 'responsive') {
|
|
1353
|
-
tagName = 'image reactive'
|
|
1354
|
-
this.advance()
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
if (tagName === 'cadre' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1359
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1360
|
-
if (next === 'en') {
|
|
1361
|
-
this.advance()
|
|
1362
|
-
const thirdToken = this.current()
|
|
1363
|
-
if (thirdToken && thirdToken.type === TokenType.IDENTIFIER && thirdToken.value.toLowerCase() === 'ligne') {
|
|
1364
|
-
tagName = 'cadre en ligne'
|
|
1365
|
-
this.advance()
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
if (tagName === 'citation' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1371
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1372
|
-
if (next === 'bloc' || next === 'block') {
|
|
1373
|
-
tagName = 'citation bloc'
|
|
1374
|
-
this.advance()
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
if (tagName === 'reference' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1379
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1380
|
-
if (next === 'citation') {
|
|
1381
|
-
tagName = 'reference citation'
|
|
1382
|
-
this.advance()
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
if (tagName === 'sans' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1387
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1388
|
-
if (next === 'script') {
|
|
1389
|
-
tagName = 'sans script'
|
|
1390
|
-
this.advance()
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
if (tagName === 'isolation' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1395
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1396
|
-
if (next === 'bidi') {
|
|
1397
|
-
tagName = 'isolation bidi'
|
|
1398
|
-
this.advance()
|
|
1399
|
-
}
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
if (tagName === 'remplacement' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1403
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1404
|
-
if (next === 'bidi') {
|
|
1405
|
-
tagName = 'remplacement bidi'
|
|
1406
|
-
this.advance()
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
if (tagName === 'annotation' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1411
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1412
|
-
if (next === 'ruby' || next === 'rubis') {
|
|
1413
|
-
tagName = 'annotation ruby'
|
|
1414
|
-
this.advance()
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
|
|
1418
|
-
if ((tagName === 'parentheses' || tagName === 'parenthèses') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1419
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1420
|
-
if (next === 'ruby' || next === 'rubis') {
|
|
1421
|
-
tagName = 'parentheses ruby'
|
|
1422
|
-
this.advance()
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
|
|
1426
|
-
if (tagName === 'carte' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1427
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1428
|
-
if (next === 'image') {
|
|
1429
|
-
tagName = 'carte image'
|
|
1430
|
-
this.advance()
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
|
|
1434
|
-
if ((tagName === 'texte' || tagName === 'text') && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1435
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1436
|
-
if (next === 'alternatif' || next === 'alt') {
|
|
1437
|
-
tagName = 'texte alternatif'
|
|
1438
|
-
this.advance()
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
if (tagName === 'entree' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1443
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1444
|
-
if (next === 'clavier') {
|
|
1445
|
-
tagName = 'entree clavier'
|
|
1446
|
-
this.advance()
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
|
-
if (tagName === 'sortie' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1451
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1452
|
-
if (next === 'exemple') {
|
|
1453
|
-
tagName = 'sortie exemple'
|
|
1454
|
-
this.advance()
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1458
|
-
if (tagName === 'definition' && nextToken && nextToken.type === TokenType.IDENTIFIER) {
|
|
1459
|
-
const next = this.normalizeAccents(nextToken.value)
|
|
1460
|
-
if (next === 'description') {
|
|
1461
|
-
tagName = 'definition description'
|
|
1462
|
-
this.advance()
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
const tag = this.translateHTMLTag(tagName)
|
|
1467
|
-
|
|
1468
|
-
const attributes = {}
|
|
1469
|
-
let inlineText = null
|
|
1470
|
-
|
|
1471
|
-
const compoundAttrs = {
|
|
1472
|
-
'texte': ['alternatif'],
|
|
1473
|
-
'longueur': ['max', 'min'],
|
|
1474
|
-
'valeur': ['max', 'min'],
|
|
1475
|
-
'zone': ['depot'],
|
|
1476
|
-
'mode': ['saisie'],
|
|
1477
|
-
'verification': ['orthographe'],
|
|
1478
|
-
'ordre': ['tabulation'],
|
|
1479
|
-
'action': ['formulaire'],
|
|
1480
|
-
'methode': ['formulaire'],
|
|
1481
|
-
'encodage': ['formulaire'],
|
|
1482
|
-
'validation': ['formulaire', 'auto'],
|
|
1483
|
-
'cible': ['formulaire', 'popover'],
|
|
1484
|
-
'lecture': ['seule', 'auto'],
|
|
1485
|
-
'nouvelle': ['fenetre'],
|
|
1486
|
-
'a': ['popup'],
|
|
1487
|
-
'jeu': ['caracteres', 'caractères'],
|
|
1488
|
-
'equivalent': ['http'],
|
|
1489
|
-
'équivalent': ['http'],
|
|
1490
|
-
'fusion': ['colonnes', 'lignes'],
|
|
1491
|
-
'plein': ['ecran', 'écran'],
|
|
1492
|
-
'bac': ['sable'],
|
|
1493
|
-
'origine': ['croisee', 'croisée'],
|
|
1494
|
-
'sources': ['reactives', 'réactives']
|
|
1495
|
-
}
|
|
1496
|
-
|
|
1497
|
-
while (!this.isAtEnd()) {
|
|
1498
|
-
const current = this.current()
|
|
1499
|
-
|
|
1500
|
-
if (!current || current.type === TokenType.NEWLINE ||
|
|
1501
|
-
current.type === TokenType.INDENT || current.type === TokenType.EOF) {
|
|
1502
|
-
break
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
if (current.type === TokenType.STRING) {
|
|
1506
|
-
inlineText = current.value.replace(/^["']|["']$/g, '')
|
|
1507
|
-
this.advance()
|
|
1508
|
-
break
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
if (current.type === TokenType.IDENTIFIER) {
|
|
1512
|
-
let attrName = current.value.toLowerCase()
|
|
1513
|
-
this.advance()
|
|
1514
|
-
|
|
1515
|
-
if (compoundAttrs[attrName]) {
|
|
1516
|
-
const nextTok = this.current()
|
|
1517
|
-
if (nextTok && nextTok.type === TokenType.IDENTIFIER) {
|
|
1518
|
-
const nextVal = nextTok.value.toLowerCase()
|
|
1519
|
-
if (compoundAttrs[attrName].includes(nextVal)) {
|
|
1520
|
-
attrName = attrName + ' ' + nextVal
|
|
1521
|
-
this.advance()
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
const nextToken = this.current()
|
|
1527
|
-
|
|
1528
|
-
if (nextToken && (nextToken.type === TokenType.EQUALS || nextToken.type === TokenType.COLON)) {
|
|
1529
|
-
this.advance()
|
|
1530
|
-
const valueToken = this.current()
|
|
1531
|
-
if (valueToken) {
|
|
1532
|
-
if (valueToken.type === TokenType.STRING) {
|
|
1533
|
-
attributes[attrName] = valueToken.value.replace(/^["']|["']$/g, '')
|
|
1534
|
-
} else if (valueToken.type === TokenType.IDENTIFIER ||
|
|
1535
|
-
valueToken.type === TokenType.NUMBER || valueToken.type === TokenType.INTEGER) {
|
|
1536
|
-
attributes[attrName] = valueToken.value
|
|
1537
|
-
}
|
|
1538
|
-
this.advance()
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
if (this.current() && this.current().type === TokenType.COMMA) {
|
|
1542
|
-
this.advance()
|
|
1543
|
-
}
|
|
1544
|
-
} else {
|
|
1545
|
-
attributes[attrName] = true
|
|
1546
|
-
|
|
1547
|
-
if (this.current() && this.current().type === TokenType.COMMA) {
|
|
1548
|
-
this.advance()
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
} else if (current.type === TokenType.COMMA) {
|
|
1552
|
-
this.advance()
|
|
1553
|
-
} else {
|
|
1554
|
-
break
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
|
|
1558
|
-
this.skipNewlines()
|
|
1559
|
-
|
|
1560
|
-
const children = []
|
|
1561
|
-
|
|
1562
|
-
if (inlineText) {
|
|
1563
|
-
children.push({
|
|
1564
|
-
type: 'Text',
|
|
1565
|
-
content: inlineText
|
|
1566
|
-
})
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
const rawContentTags = ['script', 'style']
|
|
1570
|
-
const isRawContent = rawContentTags.includes(tag)
|
|
1571
|
-
const isScript = tag === 'script'
|
|
1572
|
-
|
|
1573
|
-
if (this.match(TokenType.INDENT)) {
|
|
1574
|
-
if (isRawContent) {
|
|
1575
|
-
let rawText = []
|
|
1576
|
-
while (!this.isAtEnd()) {
|
|
1577
|
-
const current = this.current()
|
|
1578
|
-
|
|
1579
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
1580
|
-
this.advance()
|
|
1581
|
-
break
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
1585
|
-
rawText.push('\n')
|
|
1586
|
-
this.advance()
|
|
1587
|
-
continue
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
if (current && current.type === TokenType.INDENT) {
|
|
1591
|
-
this.advance()
|
|
1592
|
-
continue
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
if (current && current.type === TokenType.STRING) {
|
|
1596
|
-
if (isScript) {
|
|
1597
|
-
rawText.push("'" + current.value.replace(/'/g, "\\'") + "'")
|
|
1598
|
-
} else {
|
|
1599
|
-
rawText.push(current.value)
|
|
1600
|
-
}
|
|
1601
|
-
this.advance()
|
|
1602
|
-
continue
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
if (current && current.type === TokenType.LPAREN) {
|
|
1606
|
-
rawText.push('(')
|
|
1607
|
-
this.advance()
|
|
1608
|
-
continue
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
|
-
if (current && current.type === TokenType.RPAREN) {
|
|
1612
|
-
rawText.push(')')
|
|
1613
|
-
this.advance()
|
|
1614
|
-
continue
|
|
1615
|
-
}
|
|
1616
|
-
|
|
1617
|
-
if (current && current.type === TokenType.LBRACKET) {
|
|
1618
|
-
rawText.push('[')
|
|
1619
|
-
this.advance()
|
|
1620
|
-
continue
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
if (current && current.type === TokenType.RBRACKET) {
|
|
1624
|
-
rawText.push(']')
|
|
1625
|
-
this.advance()
|
|
1626
|
-
continue
|
|
1627
|
-
}
|
|
1628
|
-
|
|
1629
|
-
if (current && current.type === TokenType.LBRACE) {
|
|
1630
|
-
rawText.push('{')
|
|
1631
|
-
this.advance()
|
|
1632
|
-
continue
|
|
1633
|
-
}
|
|
1634
|
-
|
|
1635
|
-
if (current && current.type === TokenType.RBRACE) {
|
|
1636
|
-
rawText.push('}')
|
|
1637
|
-
this.advance()
|
|
1638
|
-
continue
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1641
|
-
if (current && current.type === TokenType.DOT) {
|
|
1642
|
-
rawText.push('.')
|
|
1643
|
-
this.advance()
|
|
1644
|
-
continue
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
if (current && current.type === TokenType.COMMA) {
|
|
1648
|
-
rawText.push(',')
|
|
1649
|
-
this.advance()
|
|
1650
|
-
continue
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
if (current && current.type === TokenType.COLON) {
|
|
1654
|
-
rawText.push(':')
|
|
1655
|
-
this.advance()
|
|
1656
|
-
continue
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
if (current && current.type === TokenType.EQUALS) {
|
|
1660
|
-
rawText.push('=')
|
|
1661
|
-
this.advance()
|
|
1662
|
-
continue
|
|
1663
|
-
}
|
|
1664
|
-
|
|
1665
|
-
if (current && current.type === TokenType.DOUBLE_EQUALS) {
|
|
1666
|
-
rawText.push('==')
|
|
1667
|
-
this.advance()
|
|
1668
|
-
continue
|
|
1669
|
-
}
|
|
1670
|
-
|
|
1671
|
-
if (current && current.type === TokenType.NOT_EQUALS) {
|
|
1672
|
-
rawText.push('!=')
|
|
1673
|
-
this.advance()
|
|
1674
|
-
continue
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
if (current && current.type === TokenType.BANG) {
|
|
1678
|
-
rawText.push('!')
|
|
1679
|
-
this.advance()
|
|
1680
|
-
continue
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
if (current && current.type === TokenType.PLUS) {
|
|
1684
|
-
rawText.push(current.value)
|
|
1685
|
-
this.advance()
|
|
1686
|
-
continue
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
if (current && current.type === TokenType.MINUS) {
|
|
1690
|
-
rawText.push(current.value)
|
|
1691
|
-
this.advance()
|
|
1692
|
-
continue
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
if (current && current.type === TokenType.STAR) {
|
|
1696
|
-
rawText.push(current.value)
|
|
1697
|
-
this.advance()
|
|
1698
|
-
continue
|
|
1699
|
-
}
|
|
1700
|
-
|
|
1701
|
-
if (current && current.type === TokenType.SLASH) {
|
|
1702
|
-
rawText.push('/')
|
|
1703
|
-
this.advance()
|
|
1704
|
-
continue
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
if (current && current.type === TokenType.PERCENT) {
|
|
1708
|
-
rawText.push('%')
|
|
1709
|
-
this.advance()
|
|
1710
|
-
continue
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
if (current && current.type === TokenType.AMPERSAND) {
|
|
1714
|
-
rawText.push('&')
|
|
1715
|
-
this.advance()
|
|
1716
|
-
continue
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
if (current && current.type === TokenType.DOUBLE_AMPERSAND) {
|
|
1720
|
-
rawText.push('&&')
|
|
1721
|
-
this.advance()
|
|
1722
|
-
continue
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
if (current && current.type === TokenType.PIPE) {
|
|
1726
|
-
rawText.push('|')
|
|
1727
|
-
this.advance()
|
|
1728
|
-
continue
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
if (current && current.type === TokenType.DOUBLE_PIPE) {
|
|
1732
|
-
rawText.push('||')
|
|
1733
|
-
this.advance()
|
|
1734
|
-
continue
|
|
1735
|
-
}
|
|
1736
|
-
|
|
1737
|
-
if (current && current.type === TokenType.LT) {
|
|
1738
|
-
rawText.push('<')
|
|
1739
|
-
this.advance()
|
|
1740
|
-
continue
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
if (current && current.type === TokenType.GT) {
|
|
1744
|
-
rawText.push('>')
|
|
1745
|
-
this.advance()
|
|
1746
|
-
continue
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
|
-
if (current && current.type === TokenType.LTE) {
|
|
1750
|
-
rawText.push('<=')
|
|
1751
|
-
this.advance()
|
|
1752
|
-
continue
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
if (current && current.type === TokenType.GTE) {
|
|
1756
|
-
rawText.push('>=')
|
|
1757
|
-
this.advance()
|
|
1758
|
-
continue
|
|
1759
|
-
}
|
|
1760
|
-
|
|
1761
|
-
if (current && current.type === TokenType.QUESTION) {
|
|
1762
|
-
rawText.push('?')
|
|
1763
|
-
this.advance()
|
|
1764
|
-
continue
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
if (current && current.type === TokenType.FAT_ARROW) {
|
|
1768
|
-
rawText.push('=>')
|
|
1769
|
-
this.advance()
|
|
1770
|
-
continue
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
if (current && current.type === TokenType.ARROW) {
|
|
1774
|
-
rawText.push('->')
|
|
1775
|
-
this.advance()
|
|
1776
|
-
continue
|
|
1777
|
-
}
|
|
1778
|
-
|
|
1779
|
-
if (current && current.type === TokenType.SEMICOLON) {
|
|
1780
|
-
rawText.push(';')
|
|
1781
|
-
this.advance()
|
|
1782
|
-
continue
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
if (current) {
|
|
1786
|
-
rawText.push(String(current.value))
|
|
1787
|
-
this.advance()
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
const textContent = rawText.join('').trim()
|
|
1792
|
-
if (textContent) {
|
|
1793
|
-
children.push({
|
|
1794
|
-
type: 'Text',
|
|
1795
|
-
content: textContent
|
|
1796
|
-
})
|
|
1797
|
-
}
|
|
1798
|
-
} else {
|
|
1799
|
-
while (!this.isAtEnd()) {
|
|
1800
|
-
const current = this.current()
|
|
1801
|
-
|
|
1802
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
1803
|
-
this.advance()
|
|
1804
|
-
break
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
const child = this.parseHTMLNode()
|
|
1808
|
-
if (child) {
|
|
1809
|
-
children.push(child)
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
this.skipNewlines()
|
|
1813
|
-
}
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
|
|
1817
|
-
if (originalTagName === 'document') {
|
|
1818
|
-
return {
|
|
1819
|
-
type: 'Doctype',
|
|
1820
|
-
children: children
|
|
1821
|
-
}
|
|
1822
|
-
}
|
|
1823
|
-
|
|
1824
|
-
return {
|
|
1825
|
-
type: 'Element',
|
|
1826
|
-
tag: tag,
|
|
1827
|
-
attributes: attributes,
|
|
1828
|
-
children: children
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
translateHTMLTag(tag) {
|
|
1833
|
-
const map = this.reverseMaps.html || {}
|
|
1834
|
-
const lower = this.normalizeAccents(tag)
|
|
1835
|
-
const withSpaces = lower.replace(/-/g, ' ')
|
|
1836
|
-
|
|
1837
|
-
const translations = {
|
|
1838
|
-
'document': 'html',
|
|
1839
|
-
'page': 'html',
|
|
1840
|
-
'tete': 'head',
|
|
1841
|
-
'corps': 'body',
|
|
1842
|
-
'entete': 'header',
|
|
1843
|
-
'piedpage': 'footer',
|
|
1844
|
-
'pied': 'footer',
|
|
1845
|
-
'navigation': 'nav',
|
|
1846
|
-
'nav': 'nav',
|
|
1847
|
-
'principal': 'main',
|
|
1848
|
-
'section': 'section',
|
|
1849
|
-
'article': 'article',
|
|
1850
|
-
'cote': 'aside',
|
|
1851
|
-
'aside': 'aside',
|
|
1852
|
-
'titre': 'title',
|
|
1853
|
-
'titre1': 'h1',
|
|
1854
|
-
'titre2': 'h2',
|
|
1855
|
-
'titre3': 'h3',
|
|
1856
|
-
'titre4': 'h4',
|
|
1857
|
-
'titre5': 'h5',
|
|
1858
|
-
'titre6': 'h6',
|
|
1859
|
-
'titre 1': 'h1',
|
|
1860
|
-
'titre 2': 'h2',
|
|
1861
|
-
'titre 3': 'h3',
|
|
1862
|
-
'titre 4': 'h4',
|
|
1863
|
-
'titre 5': 'h5',
|
|
1864
|
-
'titre 6': 'h6',
|
|
1865
|
-
'heading 1': 'h1',
|
|
1866
|
-
'heading 2': 'h2',
|
|
1867
|
-
'heading 3': 'h3',
|
|
1868
|
-
'heading 4': 'h4',
|
|
1869
|
-
'heading 5': 'h5',
|
|
1870
|
-
'heading 6': 'h6',
|
|
1871
|
-
'groupe titres': 'hgroup',
|
|
1872
|
-
'heading group': 'hgroup',
|
|
1873
|
-
'sous titre': 'h2',
|
|
1874
|
-
'paragraphe': 'p',
|
|
1875
|
-
'texte': 'span',
|
|
1876
|
-
'division': 'div',
|
|
1877
|
-
'div': 'div',
|
|
1878
|
-
'bloc': 'div',
|
|
1879
|
-
'span': 'span',
|
|
1880
|
-
'lien': 'a',
|
|
1881
|
-
'ressource': 'link',
|
|
1882
|
-
'lien externe': 'link',
|
|
1883
|
-
'image': 'img',
|
|
1884
|
-
'liste': 'ul',
|
|
1885
|
-
'liste ordonnee': 'ol',
|
|
1886
|
-
'liste non ordonnee': 'ul',
|
|
1887
|
-
'element': 'li',
|
|
1888
|
-
'element liste': 'li',
|
|
1889
|
-
'tableau': 'table',
|
|
1890
|
-
'ligne': 'tr',
|
|
1891
|
-
'cellule': 'td',
|
|
1892
|
-
'entete cellule': 'th',
|
|
1893
|
-
'formulaire': 'form',
|
|
1894
|
-
'champ': 'input',
|
|
1895
|
-
'entree': 'input',
|
|
1896
|
-
'input': 'input',
|
|
1897
|
-
'zone texte': 'textarea',
|
|
1898
|
-
'bouton': 'button',
|
|
1899
|
-
'selection': 'select',
|
|
1900
|
-
'option': 'option',
|
|
1901
|
-
'etiquette': 'label',
|
|
1902
|
-
'gras': 'strong',
|
|
1903
|
-
'fort': 'strong',
|
|
1904
|
-
'italique': 'em',
|
|
1905
|
-
'emphase': 'em',
|
|
1906
|
-
'souligne': 'u',
|
|
1907
|
-
'barre': 's',
|
|
1908
|
-
'code': 'code',
|
|
1909
|
-
'pre': 'pre',
|
|
1910
|
-
'preformate': 'pre',
|
|
1911
|
-
'citation': 'blockquote',
|
|
1912
|
-
'retour ligne': 'br',
|
|
1913
|
-
'saut ligne': 'br',
|
|
1914
|
-
'br': 'br',
|
|
1915
|
-
'ligne horizontale': 'hr',
|
|
1916
|
-
'hr': 'hr',
|
|
1917
|
-
'video': 'video',
|
|
1918
|
-
'audio': 'audio',
|
|
1919
|
-
'source': 'source',
|
|
1920
|
-
'cadre': 'iframe',
|
|
1921
|
-
'canvas': 'canvas',
|
|
1922
|
-
'toile': 'canvas',
|
|
1923
|
-
'figure': 'figure',
|
|
1924
|
-
'legende': 'legend',
|
|
1925
|
-
'legende figure': 'figcaption',
|
|
1926
|
-
'legende tableau': 'caption',
|
|
1927
|
-
'legende ensemble': 'legend',
|
|
1928
|
-
'figure caption': 'figcaption',
|
|
1929
|
-
'table caption': 'caption',
|
|
1930
|
-
'entete tableau': 'thead',
|
|
1931
|
-
'table header': 'thead',
|
|
1932
|
-
'corps tableau': 'tbody',
|
|
1933
|
-
'table body': 'tbody',
|
|
1934
|
-
'pied tableau': 'tfoot',
|
|
1935
|
-
'table footer': 'tfoot',
|
|
1936
|
-
'ensemble champs': 'fieldset',
|
|
1937
|
-
'fieldset': 'fieldset',
|
|
1938
|
-
'liste donnees': 'datalist',
|
|
1939
|
-
'datalist': 'datalist',
|
|
1940
|
-
'liste description': 'dl',
|
|
1941
|
-
'description list': 'dl',
|
|
1942
|
-
'definition description': 'dd',
|
|
1943
|
-
'image reactive': 'picture',
|
|
1944
|
-
'picture': 'picture',
|
|
1945
|
-
'cadre en ligne': 'iframe',
|
|
1946
|
-
'inline frame': 'iframe',
|
|
1947
|
-
'iframe': 'iframe',
|
|
1948
|
-
'citation bloc': 'blockquote',
|
|
1949
|
-
'blockquote': 'blockquote',
|
|
1950
|
-
'reference citation': 'cite',
|
|
1951
|
-
'groupe options': 'optgroup',
|
|
1952
|
-
'option group': 'optgroup',
|
|
1953
|
-
'groupe colonnes': 'colgroup',
|
|
1954
|
-
'column group': 'colgroup',
|
|
1955
|
-
'colonne': 'col',
|
|
1956
|
-
'column': 'col',
|
|
1957
|
-
'entree clavier': 'kbd',
|
|
1958
|
-
'keyboard input': 'kbd',
|
|
1959
|
-
'sortie exemple': 'samp',
|
|
1960
|
-
'sample output': 'samp',
|
|
1961
|
-
'texte alternatif': 'alt',
|
|
1962
|
-
'resultat': 'output',
|
|
1963
|
-
'result': 'output',
|
|
1964
|
-
'piste': 'track',
|
|
1965
|
-
'track': 'track',
|
|
1966
|
-
'insere': 'ins',
|
|
1967
|
-
'inserted': 'ins',
|
|
1968
|
-
'supprime': 'del',
|
|
1969
|
-
'deleted': 'del',
|
|
1970
|
-
'donnee': 'data',
|
|
1971
|
-
'retour ligne possible': 'wbr',
|
|
1972
|
-
'word break': 'wbr',
|
|
1973
|
-
'carte image': 'map',
|
|
1974
|
-
'image map': 'map',
|
|
1975
|
-
'script': 'script',
|
|
1976
|
-
'details': 'details',
|
|
1977
|
-
'resume': 'summary',
|
|
1978
|
-
'dialogue': 'dialog',
|
|
1979
|
-
'modele': 'template',
|
|
1980
|
-
'emplacement': 'slot',
|
|
1981
|
-
'temps': 'time',
|
|
1982
|
-
'marque': 'mark',
|
|
1983
|
-
'metre': 'meter',
|
|
1984
|
-
'progression': 'progress',
|
|
1985
|
-
'sortie': 'output',
|
|
1986
|
-
'donnees': 'data',
|
|
1987
|
-
'clavier': 'kbd',
|
|
1988
|
-
'exemple': 'samp',
|
|
1989
|
-
'variable': 'var',
|
|
1990
|
-
'abreviation': 'abbr',
|
|
1991
|
-
'indice': 'sub',
|
|
1992
|
-
'exposant': 'sup',
|
|
1993
|
-
'petit': 'small',
|
|
1994
|
-
'cite': 'cite',
|
|
1995
|
-
'definition': 'dfn',
|
|
1996
|
-
'adresse': 'address',
|
|
1997
|
-
'rubis': 'ruby',
|
|
1998
|
-
'texte rubis': 'rt',
|
|
1999
|
-
'parenthese rubis': 'rp',
|
|
2000
|
-
'bidirectionnel': 'bdi',
|
|
2001
|
-
'direction': 'bdo',
|
|
2002
|
-
'cesure': 'wbr',
|
|
2003
|
-
'noscript': 'noscript',
|
|
2004
|
-
'sans script': 'noscript',
|
|
2005
|
-
'isolation bidi': 'bdi',
|
|
2006
|
-
'remplacement bidi': 'bdo',
|
|
2007
|
-
'annotation ruby': 'rt',
|
|
2008
|
-
'annotation rubis': 'rt',
|
|
2009
|
-
'parentheses ruby': 'rp',
|
|
2010
|
-
'parenthèses ruby': 'rp',
|
|
2011
|
-
'parentheses rubis': 'rp',
|
|
2012
|
-
'terme': 'dt',
|
|
2013
|
-
'menu': 'menu',
|
|
2014
|
-
'recherche': 'search',
|
|
2015
|
-
'objet': 'object',
|
|
2016
|
-
'integrer': 'embed',
|
|
2017
|
-
'svg': 'svg',
|
|
2018
|
-
'math': 'math',
|
|
2019
|
-
|
|
2020
|
-
'zone': 'area'
|
|
2021
|
-
}
|
|
2022
|
-
|
|
2023
|
-
const result = translations[lower] || translations[withSpaces] || map[lower] || map[withSpaces] || tag
|
|
2024
|
-
return result.replace(/^<!DOCTYPE\s+/i, '').replace(/^<|>$/g, '').trim() || 'div'
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
parseJS() {
|
|
2028
|
-
return this.parseProgram('js')
|
|
2029
|
-
}
|
|
2030
|
-
|
|
2031
|
-
parseTS() {
|
|
2032
|
-
return this.parseProgram('ts')
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
parseReact() {
|
|
2036
|
-
return this.parseProgram('react')
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
parsePHP() {
|
|
2040
|
-
return this.parseProgram('php')
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
parsePython() {
|
|
2044
|
-
return this.parseProgram('python')
|
|
2045
|
-
}
|
|
2046
|
-
|
|
2047
|
-
parseRuby() {
|
|
2048
|
-
return this.parseProgram('ruby')
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
parseNode() {
|
|
2052
|
-
return this.parseProgram('node')
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
parseSQL() {
|
|
2056
|
-
return this.parseSQLProgram()
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
parseGraphQL() {
|
|
2060
|
-
return this.parseGraphQLProgram()
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
|
-
parseProgram(lang) {
|
|
2064
|
-
const program = {
|
|
2065
|
-
type: 'Program',
|
|
2066
|
-
lang: lang,
|
|
2067
|
-
body: []
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
this.skipNewlines()
|
|
2071
|
-
|
|
2072
|
-
while (!this.isAtEnd()) {
|
|
2073
|
-
const statement = this.parseStatement(lang)
|
|
2074
|
-
if (statement) {
|
|
2075
|
-
program.body.push(statement)
|
|
2076
|
-
}
|
|
2077
|
-
this.skipNewlines()
|
|
2078
|
-
}
|
|
2079
|
-
|
|
2080
|
-
return program
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
parseStatement(lang) {
|
|
2084
|
-
this.skipNewlines()
|
|
2085
|
-
const token = this.current()
|
|
2086
|
-
|
|
2087
|
-
if (!token || token.type === TokenType.EOF) return null
|
|
2088
|
-
|
|
2089
|
-
const value = token.value != null ? String(token.value).toLowerCase() : ''
|
|
2090
|
-
|
|
2091
|
-
if (this.isVariableDeclaration(value)) {
|
|
2092
|
-
return this.parseVariableDeclaration(lang)
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
if (this.isFunctionDeclaration(value)) {
|
|
2096
|
-
return this.parseFunctionDeclaration(lang)
|
|
2097
|
-
}
|
|
2098
|
-
|
|
2099
|
-
if (this.isClassDeclaration(value)) {
|
|
2100
|
-
return this.parseClassDeclaration(lang)
|
|
2101
|
-
}
|
|
2102
|
-
|
|
2103
|
-
if (this.isConditional(value)) {
|
|
2104
|
-
return this.parseConditional(lang)
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
if (this.isLoop(value)) {
|
|
2108
|
-
return this.parseLoop(lang)
|
|
2109
|
-
}
|
|
2110
|
-
|
|
2111
|
-
if (this.isReturn(value)) {
|
|
2112
|
-
return this.parseReturn(lang)
|
|
2113
|
-
}
|
|
2114
|
-
|
|
2115
|
-
if (this.isImport(value)) {
|
|
2116
|
-
return this.parseImport(lang)
|
|
2117
|
-
}
|
|
2118
|
-
|
|
2119
|
-
if (this.isExport(value)) {
|
|
2120
|
-
return this.parseExport(lang)
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
const expr = this.parseExpression(lang)
|
|
2124
|
-
if (expr) {
|
|
2125
|
-
return {
|
|
2126
|
-
type: 'ExpressionStatement',
|
|
2127
|
-
expression: expr
|
|
2128
|
-
}
|
|
2129
|
-
}
|
|
2130
|
-
return null
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
isVariableDeclaration(value) {
|
|
2134
|
-
const keywords = ['variable', 'var', 'constante', 'const', 'soit', 'let', 'definir']
|
|
2135
|
-
return keywords.includes(value)
|
|
2136
|
-
}
|
|
2137
|
-
|
|
2138
|
-
isFunctionDeclaration(value) {
|
|
2139
|
-
const keywords = ['fonction', 'func', 'fn', 'methode', 'def', 'procedure']
|
|
2140
|
-
return keywords.includes(value)
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
isClassDeclaration(value) {
|
|
2144
|
-
const keywords = ['classe', 'class', 'type', 'interface', 'struct', 'structure']
|
|
2145
|
-
return keywords.includes(value)
|
|
2146
|
-
}
|
|
2147
|
-
|
|
2148
|
-
isConditional(value) {
|
|
2149
|
-
const keywords = ['si', 'if', 'sinon', 'else', 'sinon si', 'elif', 'selon', 'switch', 'cas', 'case']
|
|
2150
|
-
return keywords.includes(value)
|
|
2151
|
-
}
|
|
2152
|
-
|
|
2153
|
-
isLoop(value) {
|
|
2154
|
-
const keywords = ['pour', 'for', 'tant que', 'while', 'faire', 'do', 'repeter', 'boucle', 'loop', 'chaque', 'each', 'pour chaque', 'foreach']
|
|
2155
|
-
return keywords.includes(value)
|
|
2156
|
-
}
|
|
2157
|
-
|
|
2158
|
-
isReturn(value) {
|
|
2159
|
-
const keywords = ['retourner', 'return', 'renvoyer', 'rendre']
|
|
2160
|
-
return keywords.includes(value)
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
isImport(value) {
|
|
2164
|
-
const keywords = ['importer', 'import', 'depuis', 'from', 'require', 'inclure', 'include', 'utiliser', 'use']
|
|
2165
|
-
return keywords.includes(value)
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
isExport(value) {
|
|
2169
|
-
const keywords = ['exporter', 'export', 'publier', 'public']
|
|
2170
|
-
return keywords.includes(value)
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
|
-
parseVariableDeclaration(lang) {
|
|
2174
|
-
const kindToken = this.advance()
|
|
2175
|
-
const kind = this.translateVariableKind(kindToken.value, lang)
|
|
2176
|
-
|
|
2177
|
-
const nameToken = this.current()
|
|
2178
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
2179
|
-
return null
|
|
2180
|
-
}
|
|
2181
|
-
const name = nameToken.value
|
|
2182
|
-
this.advance()
|
|
2183
|
-
|
|
2184
|
-
let typeAnnotation = null
|
|
2185
|
-
if (this.match(TokenType.COLON)) {
|
|
2186
|
-
typeAnnotation = this.parseType(lang)
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
let init = null
|
|
2190
|
-
if (this.match(TokenType.EQUALS)) {
|
|
2191
|
-
init = this.parseExpression(lang)
|
|
2192
|
-
}
|
|
2193
|
-
|
|
2194
|
-
return {
|
|
2195
|
-
type: 'VariableDeclaration',
|
|
2196
|
-
kind: kind,
|
|
2197
|
-
name: name,
|
|
2198
|
-
typeAnnotation: typeAnnotation,
|
|
2199
|
-
init: init
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
translateVariableKind(value, lang) {
|
|
2204
|
-
const lower = value.toLowerCase()
|
|
2205
|
-
|
|
2206
|
-
if (lower === 'constante' || lower === 'const') {
|
|
2207
|
-
return 'const'
|
|
2208
|
-
}
|
|
2209
|
-
if (lower === 'variable' || lower === 'var') {
|
|
2210
|
-
if (lang === 'js' || lang === 'ts' || lang === 'react') {
|
|
2211
|
-
return 'let'
|
|
2212
|
-
}
|
|
2213
|
-
return 'var'
|
|
2214
|
-
}
|
|
2215
|
-
if (lower === 'soit' || lower === 'let') {
|
|
2216
|
-
return 'let'
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
return 'let'
|
|
2220
|
-
}
|
|
2221
|
-
|
|
2222
|
-
parseFunctionDeclaration(lang) {
|
|
2223
|
-
this.advance()
|
|
2224
|
-
|
|
2225
|
-
const nameToken = this.current()
|
|
2226
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
2227
|
-
return null
|
|
2228
|
-
}
|
|
2229
|
-
const name = nameToken.value
|
|
2230
|
-
this.advance()
|
|
2231
|
-
|
|
2232
|
-
const params = []
|
|
2233
|
-
if (this.match(TokenType.LPAREN)) {
|
|
2234
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
2235
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2236
|
-
if (this.check(TokenType.RPAREN)) break
|
|
2237
|
-
const param = this.parseParameter(lang)
|
|
2238
|
-
if (param) {
|
|
2239
|
-
params.push(param)
|
|
2240
|
-
}
|
|
2241
|
-
this.match(TokenType.COMMA)
|
|
2242
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2243
|
-
}
|
|
2244
|
-
} else {
|
|
2245
|
-
while (!this.isAtEnd()) {
|
|
2246
|
-
const token = this.current()
|
|
2247
|
-
if (!token || token.type === TokenType.NEWLINE || token.type === TokenType.COLON || token.type === TokenType.ARROW) {
|
|
2248
|
-
break
|
|
2249
|
-
}
|
|
2250
|
-
if (token.type === TokenType.IDENTIFIER) {
|
|
2251
|
-
const param = this.parseParameter(lang)
|
|
2252
|
-
if (param) {
|
|
2253
|
-
params.push(param)
|
|
2254
|
-
}
|
|
2255
|
-
} else {
|
|
2256
|
-
break
|
|
2257
|
-
}
|
|
2258
|
-
this.match(TokenType.COMMA)
|
|
2259
|
-
}
|
|
2260
|
-
}
|
|
2261
|
-
|
|
2262
|
-
let returnType = null
|
|
2263
|
-
if (this.match(TokenType.COLON) || this.match(TokenType.ARROW)) {
|
|
2264
|
-
returnType = this.parseType(lang)
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
this.skipNewlines()
|
|
2268
|
-
const body = this.parseBlock(lang)
|
|
2269
|
-
|
|
2270
|
-
return {
|
|
2271
|
-
type: 'FunctionDeclaration',
|
|
2272
|
-
name: name,
|
|
2273
|
-
params: params,
|
|
2274
|
-
returnType: returnType,
|
|
2275
|
-
body: body
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
parseFunctionExpression(lang) {
|
|
2280
|
-
this.advance()
|
|
2281
|
-
|
|
2282
|
-
let name = null
|
|
2283
|
-
const nameToken = this.current()
|
|
2284
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER && !this.check(TokenType.LPAREN)) {
|
|
2285
|
-
const nextToken = this.peek(1)
|
|
2286
|
-
if (nextToken && nextToken.type === TokenType.LPAREN) {
|
|
2287
|
-
name = nameToken.value
|
|
2288
|
-
this.advance()
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
|
|
2292
|
-
const params = []
|
|
2293
|
-
if (this.match(TokenType.LPAREN)) {
|
|
2294
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
2295
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2296
|
-
if (this.check(TokenType.RPAREN)) break
|
|
2297
|
-
const param = this.parseParameter(lang)
|
|
2298
|
-
if (param) {
|
|
2299
|
-
params.push(param)
|
|
2300
|
-
}
|
|
2301
|
-
this.match(TokenType.COMMA)
|
|
2302
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
let returnType = null
|
|
2307
|
-
if (this.match(TokenType.COLON) || this.match(TokenType.ARROW)) {
|
|
2308
|
-
returnType = this.parseType(lang)
|
|
2309
|
-
}
|
|
2310
|
-
|
|
2311
|
-
this.skipNewlines()
|
|
2312
|
-
const body = this.parseBlock(lang)
|
|
2313
|
-
|
|
2314
|
-
return {
|
|
2315
|
-
type: 'FunctionExpression',
|
|
2316
|
-
name: name,
|
|
2317
|
-
params: params,
|
|
2318
|
-
returnType: returnType,
|
|
2319
|
-
body: body
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
|
|
2323
|
-
parseParameter(lang) {
|
|
2324
|
-
const nameToken = this.current()
|
|
2325
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
2326
|
-
return null
|
|
2327
|
-
}
|
|
2328
|
-
const name = nameToken.value
|
|
2329
|
-
this.advance()
|
|
2330
|
-
|
|
2331
|
-
let typeAnnotation = null
|
|
2332
|
-
if (this.match(TokenType.COLON)) {
|
|
2333
|
-
typeAnnotation = this.parseType(lang)
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
let defaultValue = null
|
|
2337
|
-
if (this.match(TokenType.EQUALS)) {
|
|
2338
|
-
defaultValue = this.parseExpression(lang)
|
|
2339
|
-
}
|
|
2340
|
-
|
|
2341
|
-
return {
|
|
2342
|
-
type: 'Parameter',
|
|
2343
|
-
name: name,
|
|
2344
|
-
typeAnnotation: typeAnnotation,
|
|
2345
|
-
default: defaultValue
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
parseType(lang) {
|
|
2350
|
-
const token = this.current()
|
|
2351
|
-
if (!token) return null
|
|
2352
|
-
|
|
2353
|
-
const typeName = this.translateType(token.value, lang)
|
|
2354
|
-
this.advance()
|
|
2355
|
-
|
|
2356
|
-
let generic = null
|
|
2357
|
-
if (this.match(TokenType.LT)) {
|
|
2358
|
-
generic = []
|
|
2359
|
-
while (!this.isAtEnd() && !this.match(TokenType.GT)) {
|
|
2360
|
-
const innerType = this.parseType(lang)
|
|
2361
|
-
if (innerType) {
|
|
2362
|
-
generic.push(innerType)
|
|
2363
|
-
}
|
|
2364
|
-
this.match(TokenType.COMMA)
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
|
|
2368
|
-
let isArray = false
|
|
2369
|
-
if (this.match(TokenType.LBRACKET)) {
|
|
2370
|
-
this.match(TokenType.RBRACKET)
|
|
2371
|
-
isArray = true
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
return {
|
|
2375
|
-
type: 'TypeAnnotation',
|
|
2376
|
-
name: typeName,
|
|
2377
|
-
generic: generic,
|
|
2378
|
-
isArray: isArray
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
|
|
2382
|
-
translateType(value, lang) {
|
|
2383
|
-
const lower = value.toLowerCase()
|
|
2384
|
-
|
|
2385
|
-
const types = {
|
|
2386
|
-
'chaine': 'string',
|
|
2387
|
-
'texte': 'string',
|
|
2388
|
-
'nombre': 'number',
|
|
2389
|
-
'entier': lang === 'ts' ? 'number' : 'int',
|
|
2390
|
-
'decimal': lang === 'ts' ? 'number' : 'float',
|
|
2391
|
-
'flottant': lang === 'ts' ? 'number' : 'float',
|
|
2392
|
-
'booleen': 'boolean',
|
|
2393
|
-
'bool': 'boolean',
|
|
2394
|
-
'vrai faux': 'boolean',
|
|
2395
|
-
'tableau': 'Array',
|
|
2396
|
-
'liste': lang === 'python' ? 'list' : 'Array',
|
|
2397
|
-
'objet': 'object',
|
|
2398
|
-
'dictionnaire': lang === 'python' ? 'dict' : 'object',
|
|
2399
|
-
'nul': 'null',
|
|
2400
|
-
'rien': 'void',
|
|
2401
|
-
'vide': 'void',
|
|
2402
|
-
'indefini': 'undefined',
|
|
2403
|
-
'quelconque': 'any',
|
|
2404
|
-
'jamais': 'never',
|
|
2405
|
-
'inconnu': 'unknown',
|
|
2406
|
-
'symbole': 'symbol',
|
|
2407
|
-
|
|
2408
|
-
'promesse': 'Promise',
|
|
2409
|
-
'fonction': 'Function'
|
|
2410
|
-
}
|
|
2411
|
-
|
|
2412
|
-
return types[lower] || value
|
|
2413
|
-
}
|
|
2414
|
-
|
|
2415
|
-
parseClassDeclaration(lang) {
|
|
2416
|
-
this.advance()
|
|
2417
|
-
|
|
2418
|
-
const nameToken = this.current()
|
|
2419
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
2420
|
-
return null
|
|
2421
|
-
}
|
|
2422
|
-
const name = nameToken.value
|
|
2423
|
-
this.advance()
|
|
2424
|
-
|
|
2425
|
-
let extends_ = null
|
|
2426
|
-
if (this.matchValue('etend') || this.matchValue('herite') || this.matchValue('extends')) {
|
|
2427
|
-
const parentToken = this.current()
|
|
2428
|
-
if (parentToken) {
|
|
2429
|
-
extends_ = parentToken.value
|
|
2430
|
-
this.advance()
|
|
2431
|
-
}
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
let implements_ = []
|
|
2435
|
-
if (this.matchValue('implemente') || this.matchValue('implements')) {
|
|
2436
|
-
while (!this.isAtEnd()) {
|
|
2437
|
-
const implToken = this.current()
|
|
2438
|
-
if (!implToken || implToken.type !== TokenType.IDENTIFIER) break
|
|
2439
|
-
implements_.push(implToken.value)
|
|
2440
|
-
this.advance()
|
|
2441
|
-
if (!this.match(TokenType.COMMA)) break
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
|
|
2445
|
-
this.skipNewlines()
|
|
2446
|
-
const body = this.parseBlock(lang)
|
|
2447
|
-
|
|
2448
|
-
return {
|
|
2449
|
-
type: 'ClassDeclaration',
|
|
2450
|
-
name: name,
|
|
2451
|
-
extends: extends_,
|
|
2452
|
-
implements: implements_,
|
|
2453
|
-
body: body
|
|
2454
|
-
}
|
|
2455
|
-
}
|
|
2456
|
-
|
|
2457
|
-
parseConditional(lang, isElseIf = false) {
|
|
2458
|
-
if (!isElseIf) {
|
|
2459
|
-
this.advance()
|
|
2460
|
-
}
|
|
2461
|
-
const condition = this.parseExpression(lang)
|
|
2462
|
-
|
|
2463
|
-
this.skipNewlines()
|
|
2464
|
-
const consequent = this.parseBlock(lang)
|
|
2465
|
-
|
|
2466
|
-
let alternate = null
|
|
2467
|
-
this.skipNewlines()
|
|
2468
|
-
|
|
2469
|
-
if (this.matchValue('sinon')) {
|
|
2470
|
-
if (this.matchValue('si')) {
|
|
2471
|
-
alternate = this.parseConditional(lang, true)
|
|
2472
|
-
} else {
|
|
2473
|
-
this.skipNewlines()
|
|
2474
|
-
alternate = this.parseBlock(lang)
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
|
|
2478
|
-
return {
|
|
2479
|
-
type: 'IfStatement',
|
|
2480
|
-
condition: condition,
|
|
2481
|
-
consequent: consequent,
|
|
2482
|
-
alternate: alternate
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
parseLoop(lang) {
|
|
2487
|
-
const keyword = this.advance()
|
|
2488
|
-
const keywordValue = keyword.value.toLowerCase()
|
|
2489
|
-
|
|
2490
|
-
if (keywordValue === 'pour' || keywordValue === 'for' || keywordValue === 'pour chaque' || keywordValue === 'chaque') {
|
|
2491
|
-
return this.parseForLoop(lang)
|
|
2492
|
-
}
|
|
2493
|
-
|
|
2494
|
-
if (keywordValue === 'tant que' || keywordValue === 'while') {
|
|
2495
|
-
return this.parseWhileLoop(lang)
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
if (keywordValue === 'faire' || keywordValue === 'do') {
|
|
2499
|
-
return this.parseDoWhileLoop(lang)
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
return this.parseWhileLoop(lang)
|
|
2503
|
-
}
|
|
2504
|
-
|
|
2505
|
-
parseForLoop(lang) {
|
|
2506
|
-
let variable = null
|
|
2507
|
-
let iterable = null
|
|
2508
|
-
let start = null
|
|
2509
|
-
let end = null
|
|
2510
|
-
let step = null
|
|
2511
|
-
|
|
2512
|
-
const varToken = this.current()
|
|
2513
|
-
if (varToken && varToken.type === TokenType.IDENTIFIER) {
|
|
2514
|
-
variable = varToken.value
|
|
2515
|
-
this.advance()
|
|
2516
|
-
}
|
|
2517
|
-
|
|
2518
|
-
if (this.matchValue('dans') || this.matchValue('de') || this.matchValue('in')) {
|
|
2519
|
-
iterable = this.parseExpression(lang)
|
|
2520
|
-
} else if (this.matchValue('de') || this.matchValue('from')) {
|
|
2521
|
-
start = this.parseExpression(lang)
|
|
2522
|
-
|
|
2523
|
-
if (this.matchValue('a') || this.matchValue('jusque') || this.matchValue('to')) {
|
|
2524
|
-
end = this.parseExpression(lang)
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
if (this.matchValue('par') || this.matchValue('step')) {
|
|
2528
|
-
step = this.parseExpression(lang)
|
|
2529
|
-
}
|
|
2530
|
-
}
|
|
2531
|
-
|
|
2532
|
-
this.skipNewlines()
|
|
2533
|
-
const body = this.parseBlock(lang)
|
|
2534
|
-
|
|
2535
|
-
return {
|
|
2536
|
-
type: 'ForStatement',
|
|
2537
|
-
variable: variable,
|
|
2538
|
-
iterable: iterable,
|
|
2539
|
-
start: start,
|
|
2540
|
-
end: end,
|
|
2541
|
-
step: step,
|
|
2542
|
-
body: body
|
|
2543
|
-
}
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
parseWhileLoop(lang) {
|
|
2547
|
-
const condition = this.parseExpression(lang)
|
|
2548
|
-
|
|
2549
|
-
this.skipNewlines()
|
|
2550
|
-
const body = this.parseBlock(lang)
|
|
2551
|
-
|
|
2552
|
-
return {
|
|
2553
|
-
type: 'WhileStatement',
|
|
2554
|
-
condition: condition,
|
|
2555
|
-
body: body
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
parseDoWhileLoop(lang) {
|
|
2560
|
-
this.skipNewlines()
|
|
2561
|
-
const body = this.parseBlock(lang)
|
|
2562
|
-
|
|
2563
|
-
this.skipNewlines()
|
|
2564
|
-
if (this.matchValue('tant que') || this.matchValue('while')) {
|
|
2565
|
-
const condition = this.parseExpression(lang)
|
|
2566
|
-
|
|
2567
|
-
return {
|
|
2568
|
-
type: 'DoWhileStatement',
|
|
2569
|
-
condition: condition,
|
|
2570
|
-
body: body
|
|
2571
|
-
}
|
|
2572
|
-
}
|
|
2573
|
-
|
|
2574
|
-
return {
|
|
2575
|
-
type: 'DoWhileStatement',
|
|
2576
|
-
condition: { type: 'Literal', value: true },
|
|
2577
|
-
body: body
|
|
2578
|
-
}
|
|
2579
|
-
}
|
|
2580
|
-
|
|
2581
|
-
parseReturn(lang) {
|
|
2582
|
-
this.advance()
|
|
2583
|
-
|
|
2584
|
-
const value = this.parseExpression(lang)
|
|
2585
|
-
|
|
2586
|
-
return {
|
|
2587
|
-
type: 'ReturnStatement',
|
|
2588
|
-
value: value
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2591
|
-
|
|
2592
|
-
parseImport(lang) {
|
|
2593
|
-
const importToken = this.current()
|
|
2594
|
-
const importKeyword = importToken ? importToken.value.toLowerCase() : ''
|
|
2595
|
-
this.advance()
|
|
2596
|
-
|
|
2597
|
-
const includeKeywords = ['inclure', 'requiert', 'include', 'require']
|
|
2598
|
-
|
|
2599
|
-
if (this.current() && this.current().type === TokenType.COLON) {
|
|
2600
|
-
this.advance()
|
|
2601
|
-
}
|
|
2602
|
-
|
|
2603
|
-
const nextToken = this.current()
|
|
2604
|
-
if (includeKeywords.includes(importKeyword) && nextToken && nextToken.type === TokenType.STRING) {
|
|
2605
|
-
const includePath = nextToken.value.replace(/^["']|["']$/g, '')
|
|
2606
|
-
this.advance()
|
|
2607
|
-
|
|
2608
|
-
if (includePath.endsWith('.eth') || includePath.endsWith('.ether') ||
|
|
2609
|
-
!includePath.includes('.') || includePath.match(/\.(html|php|js|css)$/i)) {
|
|
2610
|
-
return {
|
|
2611
|
-
type: 'Include',
|
|
2612
|
-
path: includePath,
|
|
2613
|
-
resolved: false
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
const imports = []
|
|
2619
|
-
let source = null
|
|
2620
|
-
let defaultImport = null
|
|
2621
|
-
|
|
2622
|
-
const token = this.current()
|
|
2623
|
-
|
|
2624
|
-
if (token && token.type === TokenType.LBRACE) {
|
|
2625
|
-
this.advance()
|
|
2626
|
-
while (!this.isAtEnd() && !this.match(TokenType.RBRACE)) {
|
|
2627
|
-
const nameToken = this.current()
|
|
2628
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
2629
|
-
let imported = nameToken.value
|
|
2630
|
-
let local = imported
|
|
2631
|
-
this.advance()
|
|
2632
|
-
|
|
2633
|
-
if (this.matchValue('comme') || this.matchValue('as')) {
|
|
2634
|
-
const aliasToken = this.current()
|
|
2635
|
-
if (aliasToken && aliasToken.type === TokenType.IDENTIFIER) {
|
|
2636
|
-
local = aliasToken.value
|
|
2637
|
-
this.advance()
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
|
|
2641
|
-
imports.push({ imported, local })
|
|
2642
|
-
}
|
|
2643
|
-
this.match(TokenType.COMMA)
|
|
2644
|
-
}
|
|
2645
|
-
} else if (token && token.type === TokenType.IDENTIFIER) {
|
|
2646
|
-
defaultImport = token.value
|
|
2647
|
-
this.advance()
|
|
2648
|
-
} else if (token && token.type === TokenType.STRING) {
|
|
2649
|
-
source = token.value.replace(/^["']|["']$/g, '')
|
|
2650
|
-
this.advance()
|
|
2651
|
-
|
|
2652
|
-
if (includeKeywords.includes(importKeyword)) {
|
|
2653
|
-
if (source.endsWith('.eth') || source.endsWith('.ether') ||
|
|
2654
|
-
!source.includes('.') || source.match(/\.(html|php|js|css)$/i)) {
|
|
2655
|
-
return {
|
|
2656
|
-
type: 'Include',
|
|
2657
|
-
path: source,
|
|
2658
|
-
resolved: false
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
}
|
|
2663
|
-
|
|
2664
|
-
if (this.matchValue('depuis') || this.matchValue('de') || this.matchValue('from')) {
|
|
2665
|
-
const sourceToken = this.current()
|
|
2666
|
-
if (sourceToken && sourceToken.type === TokenType.STRING) {
|
|
2667
|
-
source = sourceToken.value.replace(/^["']|["']$/g, '')
|
|
2668
|
-
this.advance()
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
return {
|
|
2673
|
-
type: 'ImportDeclaration',
|
|
2674
|
-
imports: imports,
|
|
2675
|
-
defaultImport: defaultImport,
|
|
2676
|
-
source: source
|
|
2677
|
-
}
|
|
2678
|
-
}
|
|
2679
|
-
|
|
2680
|
-
parseExport(lang) {
|
|
2681
|
-
this.advance()
|
|
2682
|
-
|
|
2683
|
-
let isDefault = false
|
|
2684
|
-
if (this.matchValue('defaut') || this.matchValue('default')) {
|
|
2685
|
-
isDefault = true
|
|
2686
|
-
}
|
|
2687
|
-
|
|
2688
|
-
const declaration = this.parseStatement(lang)
|
|
2689
|
-
|
|
2690
|
-
return {
|
|
2691
|
-
type: 'ExportDeclaration',
|
|
2692
|
-
isDefault: isDefault,
|
|
2693
|
-
declaration: declaration
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
|
|
2697
|
-
parseBlock(lang) {
|
|
2698
|
-
const body = []
|
|
2699
|
-
|
|
2700
|
-
const hasBrace = this.match(TokenType.LBRACE)
|
|
2701
|
-
this.skipNewlines()
|
|
2702
|
-
|
|
2703
|
-
if (hasBrace) {
|
|
2704
|
-
this.match(TokenType.INDENT)
|
|
2705
|
-
}
|
|
2706
|
-
|
|
2707
|
-
if (hasBrace || this.match(TokenType.INDENT)) {
|
|
2708
|
-
while (!this.isAtEnd()) {
|
|
2709
|
-
this.skipNewlines()
|
|
2710
|
-
|
|
2711
|
-
const current = this.current()
|
|
2712
|
-
|
|
2713
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
2714
|
-
this.advance()
|
|
2715
|
-
if (hasBrace) {
|
|
2716
|
-
this.skipNewlines()
|
|
2717
|
-
this.match(TokenType.RBRACE)
|
|
2718
|
-
}
|
|
2719
|
-
break
|
|
2720
|
-
}
|
|
2721
|
-
|
|
2722
|
-
if (hasBrace && current && current.type === TokenType.RBRACE) {
|
|
2723
|
-
this.advance()
|
|
2724
|
-
break
|
|
2725
|
-
}
|
|
2726
|
-
|
|
2727
|
-
if (current && current.type === TokenType.COMMA) {
|
|
2728
|
-
break
|
|
2729
|
-
}
|
|
2730
|
-
|
|
2731
|
-
if (current && current.type === TokenType.RPAREN) {
|
|
2732
|
-
break
|
|
2733
|
-
}
|
|
2734
|
-
|
|
2735
|
-
if (current && (current.type === TokenType.INDENT || current.type === TokenType.NEWLINE)) {
|
|
2736
|
-
this.advance()
|
|
2737
|
-
continue
|
|
2738
|
-
}
|
|
2739
|
-
|
|
2740
|
-
const statement = this.parseStatement(lang)
|
|
2741
|
-
if (statement && statement.expression?.value !== null) {
|
|
2742
|
-
body.push(statement)
|
|
2743
|
-
} else if (statement && statement.type !== 'ExpressionStatement') {
|
|
2744
|
-
body.push(statement)
|
|
2745
|
-
}
|
|
2746
|
-
|
|
2747
|
-
this.skipNewlines()
|
|
2748
|
-
}
|
|
2749
|
-
}
|
|
2750
|
-
|
|
2751
|
-
return {
|
|
2752
|
-
type: 'BlockStatement',
|
|
2753
|
-
body: body
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
|
|
2757
|
-
parseExpression(lang) {
|
|
2758
|
-
return this.parseAssignment(lang)
|
|
2759
|
-
}
|
|
2760
|
-
|
|
2761
|
-
parseAssignment(lang) {
|
|
2762
|
-
const left = this.parseLogicalOr(lang)
|
|
2763
|
-
|
|
2764
|
-
if (this.match(TokenType.EQUALS)) {
|
|
2765
|
-
const right = this.parseAssignment(lang)
|
|
2766
|
-
return {
|
|
2767
|
-
type: 'AssignmentExpression',
|
|
2768
|
-
operator: '=',
|
|
2769
|
-
left: left,
|
|
2770
|
-
right: right
|
|
2771
|
-
}
|
|
2772
|
-
}
|
|
2773
|
-
|
|
2774
|
-
return left
|
|
2775
|
-
}
|
|
2776
|
-
|
|
2777
|
-
parseLogicalOr(lang) {
|
|
2778
|
-
let left = this.parseLogicalAnd(lang)
|
|
2779
|
-
|
|
2780
|
-
while (this.match(TokenType.DOUBLE_PIPE) || this.matchValue('ou')) {
|
|
2781
|
-
const right = this.parseLogicalAnd(lang)
|
|
2782
|
-
left = {
|
|
2783
|
-
type: 'BinaryExpression',
|
|
2784
|
-
operator: '||',
|
|
2785
|
-
left: left,
|
|
2786
|
-
right: right
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
|
|
2790
|
-
return left
|
|
2791
|
-
}
|
|
2792
|
-
|
|
2793
|
-
parseLogicalAnd(lang) {
|
|
2794
|
-
let left = this.parseEquality(lang)
|
|
2795
|
-
|
|
2796
|
-
while (this.match(TokenType.DOUBLE_AMPERSAND) || this.matchValue('et')) {
|
|
2797
|
-
const right = this.parseEquality(lang)
|
|
2798
|
-
left = {
|
|
2799
|
-
type: 'BinaryExpression',
|
|
2800
|
-
operator: '&&',
|
|
2801
|
-
left: left,
|
|
2802
|
-
right: right
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
|
|
2806
|
-
return left
|
|
2807
|
-
}
|
|
2808
|
-
|
|
2809
|
-
parseEquality(lang) {
|
|
2810
|
-
let left = this.parseComparison(lang)
|
|
2811
|
-
|
|
2812
|
-
while (true) {
|
|
2813
|
-
if (this.matchValue('strictement egal') || this.matchValue('strictement égal')) {
|
|
2814
|
-
const right = this.parseComparison(lang)
|
|
2815
|
-
left = { type: 'BinaryExpression', operator: '===', left, right }
|
|
2816
|
-
} else if (this.matchValue('strictement different') || this.matchValue('strictement différent')) {
|
|
2817
|
-
const right = this.parseComparison(lang)
|
|
2818
|
-
left = { type: 'BinaryExpression', operator: '!==', left, right }
|
|
2819
|
-
} else if (this.match(TokenType.DOUBLE_EQUALS) || this.matchValue('egal') || this.matchValue('egale') || this.matchValue('égal')) {
|
|
2820
|
-
const right = this.parseComparison(lang)
|
|
2821
|
-
left = { type: 'BinaryExpression', operator: '===', left, right }
|
|
2822
|
-
} else if (this.match(TokenType.NOT_EQUALS) || this.matchValue('different') || this.matchValue('différent')) {
|
|
2823
|
-
const right = this.parseComparison(lang)
|
|
2824
|
-
left = { type: 'BinaryExpression', operator: '!==', left, right }
|
|
2825
|
-
} else {
|
|
2826
|
-
break
|
|
2827
|
-
}
|
|
2828
|
-
}
|
|
2829
|
-
|
|
2830
|
-
return left
|
|
2831
|
-
}
|
|
2832
|
-
|
|
2833
|
-
parseComparison(lang) {
|
|
2834
|
-
let left = this.parseAdditive(lang)
|
|
2835
|
-
|
|
2836
|
-
while (true) {
|
|
2837
|
-
if (this.matchValue('superieur ou egal') || this.matchValue('supérieur ou égal') || this.match(TokenType.GTE)) {
|
|
2838
|
-
const right = this.parseAdditive(lang)
|
|
2839
|
-
left = { type: 'BinaryExpression', operator: '>=', left, right }
|
|
2840
|
-
} else if (this.matchValue('inferieur ou egal') || this.matchValue('inférieur ou égal') || this.match(TokenType.LTE)) {
|
|
2841
|
-
const right = this.parseAdditive(lang)
|
|
2842
|
-
left = { type: 'BinaryExpression', operator: '<=', left, right }
|
|
2843
|
-
} else if (this.match(TokenType.LT) || this.matchValue('inferieur') || this.matchValue('inférieur')) {
|
|
2844
|
-
const right = this.parseAdditive(lang)
|
|
2845
|
-
left = { type: 'BinaryExpression', operator: '<', left, right }
|
|
2846
|
-
} else if (this.match(TokenType.GT) || this.matchValue('superieur') || this.matchValue('supérieur')) {
|
|
2847
|
-
const right = this.parseAdditive(lang)
|
|
2848
|
-
left = { type: 'BinaryExpression', operator: '>', left, right }
|
|
2849
|
-
} else {
|
|
2850
|
-
break
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
|
|
2854
|
-
return left
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
parseAdditive(lang) {
|
|
2858
|
-
let left = this.parseMultiplicative(lang)
|
|
2859
|
-
|
|
2860
|
-
while (true) {
|
|
2861
|
-
if (this.match(TokenType.PLUS) || this.matchValue('plus') || this.matchValue('addition')) {
|
|
2862
|
-
const right = this.parseMultiplicative(lang)
|
|
2863
|
-
left = { type: 'BinaryExpression', operator: '+', left, right }
|
|
2864
|
-
} else if (this.match(TokenType.MINUS) || this.matchValue('moins') || this.matchValue('soustraction')) {
|
|
2865
|
-
const right = this.parseMultiplicative(lang)
|
|
2866
|
-
left = { type: 'BinaryExpression', operator: '-', left, right }
|
|
2867
|
-
} else {
|
|
2868
|
-
break
|
|
2869
|
-
}
|
|
2870
|
-
}
|
|
2871
|
-
|
|
2872
|
-
return left
|
|
2873
|
-
}
|
|
2874
|
-
|
|
2875
|
-
parseMultiplicative(lang) {
|
|
2876
|
-
let left = this.parseUnary(lang)
|
|
2877
|
-
|
|
2878
|
-
while (true) {
|
|
2879
|
-
if (this.match(TokenType.STAR) || this.matchValue('fois') || this.matchValue('multiplie') || this.matchValue('multiplication')) {
|
|
2880
|
-
const right = this.parseUnary(lang)
|
|
2881
|
-
left = { type: 'BinaryExpression', operator: '*', left, right }
|
|
2882
|
-
} else if (this.match(TokenType.SLASH) || this.matchValue('divise') || this.matchValue('division')) {
|
|
2883
|
-
const right = this.parseUnary(lang)
|
|
2884
|
-
left = { type: 'BinaryExpression', operator: '/', left, right }
|
|
2885
|
-
} else if (this.match(TokenType.PERCENT) || this.matchValue('modulo')) {
|
|
2886
|
-
const right = this.parseUnary(lang)
|
|
2887
|
-
left = { type: 'BinaryExpression', operator: '%', left, right }
|
|
2888
|
-
} else {
|
|
2889
|
-
break
|
|
2890
|
-
}
|
|
2891
|
-
}
|
|
2892
|
-
|
|
2893
|
-
return left
|
|
2894
|
-
}
|
|
2895
|
-
|
|
2896
|
-
parseUnary(lang) {
|
|
2897
|
-
if (this.match(TokenType.BANG) || this.matchValue('non') || this.matchValue('pas')) {
|
|
2898
|
-
const operand = this.parseUnary(lang)
|
|
2899
|
-
return { type: 'UnaryExpression', operator: '!', operand }
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
if (this.match(TokenType.MINUS)) {
|
|
2903
|
-
const operand = this.parseUnary(lang)
|
|
2904
|
-
return { type: 'UnaryExpression', operator: '-', operand }
|
|
2905
|
-
}
|
|
2906
|
-
|
|
2907
|
-
if (this.matchValue('nouveau') || this.matchValue('new')) {
|
|
2908
|
-
const callee = this.parseCall(lang)
|
|
2909
|
-
if (callee.type === 'CallExpression') {
|
|
2910
|
-
return { type: 'NewExpression', callee: callee.callee, arguments: callee.arguments }
|
|
2911
|
-
}
|
|
2912
|
-
return { type: 'NewExpression', callee, arguments: [] }
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
return this.parseCall(lang)
|
|
2916
|
-
}
|
|
2917
|
-
|
|
2918
|
-
parseCall(lang) {
|
|
2919
|
-
let expr = this.parsePrimary(lang)
|
|
2920
|
-
|
|
2921
|
-
while (true) {
|
|
2922
|
-
if (this.match(TokenType.LPAREN)) {
|
|
2923
|
-
const args = []
|
|
2924
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
2925
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2926
|
-
if (this.check(TokenType.RPAREN)) break
|
|
2927
|
-
args.push(this.parseExpression(lang))
|
|
2928
|
-
this.match(TokenType.COMMA)
|
|
2929
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
2930
|
-
}
|
|
2931
|
-
expr = { type: 'CallExpression', callee: expr, arguments: args }
|
|
2932
|
-
} else if (this.match(TokenType.DOT)) {
|
|
2933
|
-
const property = this.current()
|
|
2934
|
-
if (property && property.type === TokenType.IDENTIFIER) {
|
|
2935
|
-
this.advance()
|
|
2936
|
-
expr = { type: 'MemberExpression', object: expr, property: { type: 'Identifier', name: property.value } }
|
|
2937
|
-
}
|
|
2938
|
-
} else if (this.match(TokenType.LBRACKET)) {
|
|
2939
|
-
const index = this.parseExpression(lang)
|
|
2940
|
-
this.expect(TokenType.RBRACKET)
|
|
2941
|
-
expr = { type: 'IndexExpression', object: expr, index }
|
|
2942
|
-
} else {
|
|
2943
|
-
break
|
|
2944
|
-
}
|
|
2945
|
-
}
|
|
2946
|
-
|
|
2947
|
-
return expr
|
|
2948
|
-
}
|
|
2949
|
-
|
|
2950
|
-
parsePrimary(lang) {
|
|
2951
|
-
const token = this.current()
|
|
2952
|
-
|
|
2953
|
-
if (!token) {
|
|
2954
|
-
return { type: 'Literal', value: null }
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
if (token.type === TokenType.NUMBER || token.type === TokenType.INTEGER || token.type === TokenType.FLOAT) {
|
|
2958
|
-
this.advance()
|
|
2959
|
-
return { type: 'Literal', value: parseFloat(token.value) }
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2962
|
-
if (token.type === TokenType.STRING) {
|
|
2963
|
-
this.advance()
|
|
2964
|
-
return { type: 'Literal', value: token.value.replace(/^["']|["']$/g, '') }
|
|
2965
|
-
}
|
|
2966
|
-
|
|
2967
|
-
if (token.type === TokenType.IDENTIFIER) {
|
|
2968
|
-
const value = token.value.toLowerCase()
|
|
2969
|
-
|
|
2970
|
-
if (value === 'fonction' || value === 'function') {
|
|
2971
|
-
return this.parseFunctionExpression(lang)
|
|
2972
|
-
}
|
|
2973
|
-
|
|
2974
|
-
if (value === 'vrai' || value === 'true') {
|
|
2975
|
-
this.advance()
|
|
2976
|
-
return { type: 'Literal', value: true }
|
|
2977
|
-
}
|
|
2978
|
-
|
|
2979
|
-
if (value === 'faux' || value === 'false') {
|
|
2980
|
-
this.advance()
|
|
2981
|
-
return { type: 'Literal', value: false }
|
|
2982
|
-
}
|
|
2983
|
-
|
|
2984
|
-
if (value === 'nul' || value === 'null' || value === 'rien') {
|
|
2985
|
-
this.advance()
|
|
2986
|
-
return { type: 'Literal', value: null }
|
|
2987
|
-
}
|
|
2988
|
-
|
|
2989
|
-
if (value === 'indefini' || value === 'undefined') {
|
|
2990
|
-
this.advance()
|
|
2991
|
-
return { type: 'Literal', value: undefined }
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
const translated = this.translateJSIdentifier(token.value)
|
|
2995
|
-
this.advance()
|
|
2996
|
-
|
|
2997
|
-
if (translated && translated.includes('.')) {
|
|
2998
|
-
const parts = translated.split('.')
|
|
2999
|
-
let expr = { type: 'Identifier', name: parts[0] }
|
|
3000
|
-
for (let i = 1; i < parts.length; i++) {
|
|
3001
|
-
expr = { type: 'MemberExpression', object: expr, property: { type: 'Identifier', name: parts[i] } }
|
|
3002
|
-
}
|
|
3003
|
-
return expr
|
|
3004
|
-
}
|
|
3005
|
-
|
|
3006
|
-
return { type: 'Identifier', name: translated || token.value }
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
if (token.type === TokenType.LBRACKET) {
|
|
3010
|
-
return this.parseArrayLiteral(lang)
|
|
3011
|
-
}
|
|
3012
|
-
|
|
3013
|
-
if (token.type === TokenType.LBRACE) {
|
|
3014
|
-
return this.parseObjectLiteral(lang)
|
|
3015
|
-
}
|
|
3016
|
-
|
|
3017
|
-
if (token.type === TokenType.LPAREN) {
|
|
3018
|
-
this.advance()
|
|
3019
|
-
const expr = this.parseExpression(lang)
|
|
3020
|
-
this.expect(TokenType.RPAREN)
|
|
3021
|
-
expr.parenthesized = true
|
|
3022
|
-
return expr
|
|
3023
|
-
}
|
|
3024
|
-
|
|
3025
|
-
this.advance()
|
|
3026
|
-
return { type: 'Literal', value: null }
|
|
3027
|
-
}
|
|
3028
|
-
|
|
3029
|
-
parseArrayLiteral(lang) {
|
|
3030
|
-
this.expect(TokenType.LBRACKET)
|
|
3031
|
-
const elements = []
|
|
3032
|
-
|
|
3033
|
-
while (!this.isAtEnd() && !this.match(TokenType.RBRACKET)) {
|
|
3034
|
-
elements.push(this.parseExpression(lang))
|
|
3035
|
-
this.match(TokenType.COMMA)
|
|
3036
|
-
}
|
|
3037
|
-
|
|
3038
|
-
return { type: 'ArrayExpression', elements }
|
|
3039
|
-
}
|
|
3040
|
-
|
|
3041
|
-
parseObjectLiteral(lang) {
|
|
3042
|
-
this.expect(TokenType.LBRACE)
|
|
3043
|
-
const properties = []
|
|
3044
|
-
|
|
3045
|
-
this.skipWhitespace()
|
|
3046
|
-
|
|
3047
|
-
while (!this.isAtEnd() && !this.check(TokenType.RBRACE)) {
|
|
3048
|
-
this.skipWhitespace()
|
|
3049
|
-
|
|
3050
|
-
const keyToken = this.current()
|
|
3051
|
-
if (!keyToken || keyToken.type === TokenType.RBRACE) break
|
|
3052
|
-
|
|
3053
|
-
let key
|
|
3054
|
-
if (keyToken.type === TokenType.STRING) {
|
|
3055
|
-
const keyValue = keyToken.value.replace(/^["']|["']$/g, '')
|
|
3056
|
-
key = { type: 'Literal', value: keyValue }
|
|
3057
|
-
this.advance()
|
|
3058
|
-
} else if (keyToken.type === TokenType.IDENTIFIER) {
|
|
3059
|
-
key = { type: 'Identifier', name: keyToken.value }
|
|
3060
|
-
this.advance()
|
|
3061
|
-
} else {
|
|
3062
|
-
break
|
|
3063
|
-
}
|
|
3064
|
-
|
|
3065
|
-
this.match(TokenType.COLON) || this.match(TokenType.EQUALS)
|
|
3066
|
-
|
|
3067
|
-
const value = this.parseExpression(lang)
|
|
3068
|
-
properties.push({ key, value })
|
|
3069
|
-
|
|
3070
|
-
this.match(TokenType.COMMA)
|
|
3071
|
-
this.skipWhitespace()
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
this.match(TokenType.RBRACE)
|
|
3075
|
-
|
|
3076
|
-
return { type: 'ObjectExpression', properties }
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
skipWhitespace() {
|
|
3080
|
-
while (this.match(TokenType.NEWLINE) || this.match(TokenType.INDENT) || this.match(TokenType.DEDENT)) {}
|
|
3081
|
-
}
|
|
3082
|
-
|
|
3083
|
-
check(type) {
|
|
3084
|
-
const token = this.current()
|
|
3085
|
-
return token && token.type === type
|
|
3086
|
-
}
|
|
3087
|
-
|
|
3088
|
-
parseSQLProgram() {
|
|
3089
|
-
const program = {
|
|
3090
|
-
type: 'SQLProgram',
|
|
3091
|
-
statements: []
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
this.skipNewlines()
|
|
3095
|
-
|
|
3096
|
-
while (!this.isAtEnd()) {
|
|
3097
|
-
const statement = this.parseSQLStatement()
|
|
3098
|
-
if (statement) {
|
|
3099
|
-
program.statements.push(statement)
|
|
3100
|
-
}
|
|
3101
|
-
this.skipNewlines()
|
|
3102
|
-
}
|
|
3103
|
-
|
|
3104
|
-
return program
|
|
3105
|
-
}
|
|
3106
|
-
|
|
3107
|
-
parseSQLStatement() {
|
|
3108
|
-
this.skipNewlines()
|
|
3109
|
-
const token = this.current()
|
|
3110
|
-
|
|
3111
|
-
if (!token || token.type === TokenType.EOF) return null
|
|
3112
|
-
|
|
3113
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3114
|
-
|
|
3115
|
-
if (value === 'selectionner' || value === 'select' || value === 'choisir') {
|
|
3116
|
-
return this.parseSQLSelect()
|
|
3117
|
-
}
|
|
3118
|
-
|
|
3119
|
-
if (value === 'inserer' || value === 'insert' || value === 'ajouter') {
|
|
3120
|
-
return this.parseSQLInsert()
|
|
3121
|
-
}
|
|
3122
|
-
|
|
3123
|
-
if (value === 'mettre' || value === 'update' || value === 'modifier') {
|
|
3124
|
-
return this.parseSQLUpdate()
|
|
3125
|
-
}
|
|
3126
|
-
|
|
3127
|
-
if (value === 'supprimer' || value === 'delete' || value === 'effacer') {
|
|
3128
|
-
return this.parseSQLDelete()
|
|
3129
|
-
}
|
|
3130
|
-
|
|
3131
|
-
if (value === 'creer' || value === 'create') {
|
|
3132
|
-
return this.parseSQLCreate()
|
|
3133
|
-
}
|
|
3134
|
-
|
|
3135
|
-
if (value === 'detruire' || value === 'drop') {
|
|
3136
|
-
return this.parseSQLDrop()
|
|
3137
|
-
}
|
|
3138
|
-
|
|
3139
|
-
if (value === 'modifier' || value === 'alter') {
|
|
3140
|
-
return this.parseSQLAlter()
|
|
3141
|
-
}
|
|
3142
|
-
|
|
3143
|
-
this.advance()
|
|
3144
|
-
return null
|
|
3145
|
-
}
|
|
3146
|
-
|
|
3147
|
-
parseSQLSelect() {
|
|
3148
|
-
this.advance()
|
|
3149
|
-
|
|
3150
|
-
const columns = []
|
|
3151
|
-
|
|
3152
|
-
while (!this.isAtEnd()) {
|
|
3153
|
-
const token = this.current()
|
|
3154
|
-
|
|
3155
|
-
if (!token || token.type === TokenType.EOF) break
|
|
3156
|
-
|
|
3157
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3158
|
-
if (value === 'depuis' || value === 'de' || value === 'from') break
|
|
3159
|
-
|
|
3160
|
-
if (token.type === TokenType.STAR) {
|
|
3161
|
-
columns.push('*')
|
|
3162
|
-
this.advance()
|
|
3163
|
-
} else if (token.type === TokenType.IDENTIFIER) {
|
|
3164
|
-
columns.push(token.value)
|
|
3165
|
-
this.advance()
|
|
3166
|
-
} else if (token.type === TokenType.COMMA) {
|
|
3167
|
-
this.advance()
|
|
3168
|
-
} else {
|
|
3169
|
-
break
|
|
3170
|
-
}
|
|
3171
|
-
}
|
|
3172
|
-
|
|
3173
|
-
let table = null
|
|
3174
|
-
if (this.matchValue('depuis') || this.matchValue('de') || this.matchValue('from')) {
|
|
3175
|
-
const tableToken = this.current()
|
|
3176
|
-
if (tableToken && tableToken.type === TokenType.IDENTIFIER) {
|
|
3177
|
-
table = tableToken.value
|
|
3178
|
-
this.advance()
|
|
3179
|
-
}
|
|
3180
|
-
}
|
|
3181
|
-
|
|
3182
|
-
let where = null
|
|
3183
|
-
if (this.matchValue('ou') || this.matchValue('where')) {
|
|
3184
|
-
where = this.parseSQLWhere()
|
|
3185
|
-
}
|
|
3186
|
-
|
|
3187
|
-
let orderBy = null
|
|
3188
|
-
if (this.matchValue('trier') || this.matchValue('ordonner') || this.matchValue('order')) {
|
|
3189
|
-
if (this.matchValue('par') || this.matchValue('by')) {
|
|
3190
|
-
orderBy = this.parseSQLOrderBy()
|
|
3191
|
-
}
|
|
3192
|
-
}
|
|
3193
|
-
|
|
3194
|
-
let limit = null
|
|
3195
|
-
if (this.matchValue('limiter') || this.matchValue('limit')) {
|
|
3196
|
-
const limitToken = this.current()
|
|
3197
|
-
if (limitToken && (limitToken.type === TokenType.NUMBER || limitToken.type === TokenType.INTEGER)) {
|
|
3198
|
-
limit = parseInt(limitToken.value)
|
|
3199
|
-
this.advance()
|
|
3200
|
-
}
|
|
3201
|
-
}
|
|
3202
|
-
|
|
3203
|
-
return {
|
|
3204
|
-
type: 'SelectStatement',
|
|
3205
|
-
columns: columns,
|
|
3206
|
-
table: table,
|
|
3207
|
-
where: where,
|
|
3208
|
-
orderBy: orderBy,
|
|
3209
|
-
limit: limit
|
|
3210
|
-
}
|
|
3211
|
-
}
|
|
3212
|
-
|
|
3213
|
-
parseSQLWhere() {
|
|
3214
|
-
const conditions = []
|
|
3215
|
-
|
|
3216
|
-
while (!this.isAtEnd()) {
|
|
3217
|
-
const token = this.current()
|
|
3218
|
-
|
|
3219
|
-
if (!token || token.type === TokenType.EOF) break
|
|
3220
|
-
|
|
3221
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3222
|
-
if (value === 'trier' || value === 'ordonner' || value === 'order' ||
|
|
3223
|
-
value === 'limiter' || value === 'limit' || value === 'grouper') break
|
|
3224
|
-
|
|
3225
|
-
if (token.type === TokenType.IDENTIFIER) {
|
|
3226
|
-
const field = token.value
|
|
3227
|
-
this.advance()
|
|
3228
|
-
|
|
3229
|
-
const opToken = this.current()
|
|
3230
|
-
let operator = '='
|
|
3231
|
-
|
|
3232
|
-
if (opToken) {
|
|
3233
|
-
if (opToken.type === TokenType.EQUALS || opToken.type === TokenType.DOUBLE_EQUALS) {
|
|
3234
|
-
operator = '='
|
|
3235
|
-
this.advance()
|
|
3236
|
-
} else if (opToken.type === TokenType.NOT_EQUALS) {
|
|
3237
|
-
operator = '<>'
|
|
3238
|
-
this.advance()
|
|
3239
|
-
} else if (opToken.type === TokenType.LT) {
|
|
3240
|
-
operator = '<'
|
|
3241
|
-
this.advance()
|
|
3242
|
-
} else if (opToken.type === TokenType.GT) {
|
|
3243
|
-
operator = '>'
|
|
3244
|
-
this.advance()
|
|
3245
|
-
} else if (opToken.type === TokenType.LTE) {
|
|
3246
|
-
operator = '<='
|
|
3247
|
-
this.advance()
|
|
3248
|
-
} else if (opToken.type === TokenType.GTE) {
|
|
3249
|
-
operator = '>='
|
|
3250
|
-
this.advance()
|
|
3251
|
-
} else if (opToken.value && opToken.value.toLowerCase() === 'egal') {
|
|
3252
|
-
operator = '='
|
|
3253
|
-
this.advance()
|
|
3254
|
-
}
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
const valueToken = this.current()
|
|
3258
|
-
let condValue = null
|
|
3259
|
-
|
|
3260
|
-
if (valueToken) {
|
|
3261
|
-
if (valueToken.type === TokenType.STRING) {
|
|
3262
|
-
condValue = valueToken.value
|
|
3263
|
-
} else if (valueToken.type === TokenType.NUMBER || valueToken.type === TokenType.INTEGER) {
|
|
3264
|
-
condValue = parseFloat(valueToken.value)
|
|
3265
|
-
} else if (valueToken.type === TokenType.IDENTIFIER) {
|
|
3266
|
-
condValue = valueToken.value
|
|
3267
|
-
}
|
|
3268
|
-
this.advance()
|
|
3269
|
-
}
|
|
3270
|
-
|
|
3271
|
-
conditions.push({ field, operator, value: condValue })
|
|
3272
|
-
} else if (value === 'et' || value === 'and') {
|
|
3273
|
-
conditions.push({ type: 'AND' })
|
|
3274
|
-
this.advance()
|
|
3275
|
-
} else if (value === 'ou' || value === 'or') {
|
|
3276
|
-
conditions.push({ type: 'OR' })
|
|
3277
|
-
this.advance()
|
|
3278
|
-
} else {
|
|
3279
|
-
this.advance()
|
|
3280
|
-
}
|
|
3281
|
-
}
|
|
3282
|
-
|
|
3283
|
-
return conditions
|
|
3284
|
-
}
|
|
3285
|
-
|
|
3286
|
-
parseSQLOrderBy() {
|
|
3287
|
-
const orders = []
|
|
3288
|
-
|
|
3289
|
-
while (!this.isAtEnd()) {
|
|
3290
|
-
const token = this.current()
|
|
3291
|
-
|
|
3292
|
-
if (!token || token.type === TokenType.EOF) break
|
|
3293
|
-
|
|
3294
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3295
|
-
if (value === 'limiter' || value === 'limit' || value === 'grouper') break
|
|
3296
|
-
|
|
3297
|
-
if (token.type === TokenType.IDENTIFIER) {
|
|
3298
|
-
const field = token.value
|
|
3299
|
-
this.advance()
|
|
3300
|
-
|
|
3301
|
-
let direction = 'ASC'
|
|
3302
|
-
const dirToken = this.current()
|
|
3303
|
-
|
|
3304
|
-
if (dirToken) {
|
|
3305
|
-
const dirValue = dirToken.value ? dirToken.value.toLowerCase() : ''
|
|
3306
|
-
if (dirValue === 'desc' || dirValue === 'descendant' || dirValue === 'decroissant') {
|
|
3307
|
-
direction = 'DESC'
|
|
3308
|
-
this.advance()
|
|
3309
|
-
} else if (dirValue === 'asc' || dirValue === 'ascendant' || dirValue === 'croissant') {
|
|
3310
|
-
direction = 'ASC'
|
|
3311
|
-
this.advance()
|
|
3312
|
-
}
|
|
3313
|
-
}
|
|
3314
|
-
|
|
3315
|
-
orders.push({ field, direction })
|
|
3316
|
-
} else if (token.type === TokenType.COMMA) {
|
|
3317
|
-
this.advance()
|
|
3318
|
-
} else {
|
|
3319
|
-
break
|
|
3320
|
-
}
|
|
3321
|
-
}
|
|
3322
|
-
|
|
3323
|
-
return orders
|
|
3324
|
-
}
|
|
3325
|
-
|
|
3326
|
-
parseSQLInsert() {
|
|
3327
|
-
this.advance()
|
|
3328
|
-
|
|
3329
|
-
if (this.matchValue('dans') || this.matchValue('into') || this.matchValue('in')) {
|
|
3330
|
-
}
|
|
3331
|
-
|
|
3332
|
-
const tableToken = this.current()
|
|
3333
|
-
let table = null
|
|
3334
|
-
if (tableToken && tableToken.type === TokenType.IDENTIFIER) {
|
|
3335
|
-
table = tableToken.value
|
|
3336
|
-
this.advance()
|
|
3337
|
-
}
|
|
3338
|
-
|
|
3339
|
-
const columns = []
|
|
3340
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3341
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
3342
|
-
const colToken = this.current()
|
|
3343
|
-
if (colToken && colToken.type === TokenType.IDENTIFIER) {
|
|
3344
|
-
columns.push(colToken.value)
|
|
3345
|
-
this.advance()
|
|
3346
|
-
}
|
|
3347
|
-
this.match(TokenType.COMMA)
|
|
3348
|
-
}
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
const values = []
|
|
3352
|
-
if (this.matchValue('valeurs') || this.matchValue('values')) {
|
|
3353
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3354
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
3355
|
-
const valToken = this.current()
|
|
3356
|
-
if (valToken) {
|
|
3357
|
-
if (valToken.type === TokenType.STRING) {
|
|
3358
|
-
values.push(valToken.value)
|
|
3359
|
-
} else if (valToken.type === TokenType.NUMBER || valToken.type === TokenType.INTEGER) {
|
|
3360
|
-
values.push(parseFloat(valToken.value))
|
|
3361
|
-
} else if (valToken.type === TokenType.IDENTIFIER) {
|
|
3362
|
-
const v = valToken.value.toLowerCase()
|
|
3363
|
-
if (v === 'vrai' || v === 'true') values.push(true)
|
|
3364
|
-
else if (v === 'faux' || v === 'false') values.push(false)
|
|
3365
|
-
else if (v === 'nul' || v === 'null') values.push(null)
|
|
3366
|
-
else values.push(valToken.value)
|
|
3367
|
-
}
|
|
3368
|
-
this.advance()
|
|
3369
|
-
}
|
|
3370
|
-
this.match(TokenType.COMMA)
|
|
3371
|
-
}
|
|
3372
|
-
}
|
|
3373
|
-
}
|
|
3374
|
-
|
|
3375
|
-
return {
|
|
3376
|
-
type: 'InsertStatement',
|
|
3377
|
-
table: table,
|
|
3378
|
-
columns: columns,
|
|
3379
|
-
values: values
|
|
3380
|
-
}
|
|
3381
|
-
}
|
|
3382
|
-
|
|
3383
|
-
parseSQLUpdate() {
|
|
3384
|
-
this.advance()
|
|
3385
|
-
|
|
3386
|
-
if (this.matchValue('a jour') || this.matchValue('jour')) {
|
|
3387
|
-
}
|
|
3388
|
-
|
|
3389
|
-
const tableToken = this.current()
|
|
3390
|
-
let table = null
|
|
3391
|
-
if (tableToken && tableToken.type === TokenType.IDENTIFIER) {
|
|
3392
|
-
table = tableToken.value
|
|
3393
|
-
this.advance()
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
const assignments = []
|
|
3397
|
-
if (this.matchValue('definir') || this.matchValue('set') || this.matchValue('avec')) {
|
|
3398
|
-
while (!this.isAtEnd()) {
|
|
3399
|
-
const colToken = this.current()
|
|
3400
|
-
|
|
3401
|
-
if (!colToken || colToken.type === TokenType.EOF) break
|
|
3402
|
-
|
|
3403
|
-
const value = colToken.value ? colToken.value.toLowerCase() : ''
|
|
3404
|
-
if (value === 'ou' || value === 'where') break
|
|
3405
|
-
|
|
3406
|
-
if (colToken.type === TokenType.IDENTIFIER) {
|
|
3407
|
-
const column = colToken.value
|
|
3408
|
-
this.advance()
|
|
3409
|
-
|
|
3410
|
-
if (this.match(TokenType.EQUALS) || this.match(TokenType.COLON)) {
|
|
3411
|
-
const valToken = this.current()
|
|
3412
|
-
let val = null
|
|
3413
|
-
|
|
3414
|
-
if (valToken) {
|
|
3415
|
-
if (valToken.type === TokenType.STRING) {
|
|
3416
|
-
val = valToken.value
|
|
3417
|
-
} else if (valToken.type === TokenType.NUMBER || valToken.type === TokenType.INTEGER) {
|
|
3418
|
-
val = parseFloat(valToken.value)
|
|
3419
|
-
} else if (valToken.type === TokenType.IDENTIFIER) {
|
|
3420
|
-
val = valToken.value
|
|
3421
|
-
}
|
|
3422
|
-
this.advance()
|
|
3423
|
-
}
|
|
3424
|
-
|
|
3425
|
-
assignments.push({ column, value: val })
|
|
3426
|
-
}
|
|
3427
|
-
}
|
|
3428
|
-
|
|
3429
|
-
this.match(TokenType.COMMA)
|
|
3430
|
-
}
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
|
-
let where = null
|
|
3434
|
-
if (this.matchValue('ou') || this.matchValue('where')) {
|
|
3435
|
-
where = this.parseSQLWhere()
|
|
3436
|
-
}
|
|
3437
|
-
|
|
3438
|
-
return {
|
|
3439
|
-
type: 'UpdateStatement',
|
|
3440
|
-
table: table,
|
|
3441
|
-
assignments: assignments,
|
|
3442
|
-
where: where
|
|
3443
|
-
}
|
|
3444
|
-
}
|
|
3445
|
-
|
|
3446
|
-
parseSQLDelete() {
|
|
3447
|
-
this.advance()
|
|
3448
|
-
|
|
3449
|
-
if (this.matchValue('de') || this.matchValue('depuis') || this.matchValue('from')) {
|
|
3450
|
-
}
|
|
3451
|
-
|
|
3452
|
-
const tableToken = this.current()
|
|
3453
|
-
let table = null
|
|
3454
|
-
if (tableToken && tableToken.type === TokenType.IDENTIFIER) {
|
|
3455
|
-
table = tableToken.value
|
|
3456
|
-
this.advance()
|
|
3457
|
-
}
|
|
3458
|
-
|
|
3459
|
-
let where = null
|
|
3460
|
-
if (this.matchValue('ou') || this.matchValue('where')) {
|
|
3461
|
-
where = this.parseSQLWhere()
|
|
3462
|
-
}
|
|
3463
|
-
|
|
3464
|
-
return {
|
|
3465
|
-
type: 'DeleteStatement',
|
|
3466
|
-
table: table,
|
|
3467
|
-
where: where
|
|
3468
|
-
}
|
|
3469
|
-
}
|
|
3470
|
-
|
|
3471
|
-
parseSQLCreate() {
|
|
3472
|
-
this.advance()
|
|
3473
|
-
|
|
3474
|
-
if (this.matchValue('table')) {
|
|
3475
|
-
return this.parseSQLCreateTable()
|
|
3476
|
-
}
|
|
3477
|
-
|
|
3478
|
-
if (this.matchValue('base') || this.matchValue('database')) {
|
|
3479
|
-
this.matchValue('de')
|
|
3480
|
-
this.matchValue('donnees')
|
|
3481
|
-
return this.parseSQLCreateDatabase()
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
|
-
if (this.matchValue('index')) {
|
|
3485
|
-
return this.parseSQLCreateIndex()
|
|
3486
|
-
}
|
|
3487
|
-
|
|
3488
|
-
return null
|
|
3489
|
-
}
|
|
3490
|
-
|
|
3491
|
-
parseSQLCreateTable() {
|
|
3492
|
-
const nameToken = this.current()
|
|
3493
|
-
let name = null
|
|
3494
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3495
|
-
name = nameToken.value
|
|
3496
|
-
this.advance()
|
|
3497
|
-
}
|
|
3498
|
-
|
|
3499
|
-
const columns = []
|
|
3500
|
-
|
|
3501
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3502
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
3503
|
-
const col = this.parseSQLColumnDef()
|
|
3504
|
-
if (col) {
|
|
3505
|
-
columns.push(col)
|
|
3506
|
-
}
|
|
3507
|
-
this.match(TokenType.COMMA)
|
|
3508
|
-
}
|
|
3509
|
-
} else {
|
|
3510
|
-
this.skipNewlines()
|
|
3511
|
-
this.match(TokenType.INDENT)
|
|
3512
|
-
|
|
3513
|
-
while (!this.isAtEnd()) {
|
|
3514
|
-
const current = this.current()
|
|
3515
|
-
|
|
3516
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
3517
|
-
this.advance()
|
|
3518
|
-
break
|
|
3519
|
-
}
|
|
3520
|
-
|
|
3521
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
3522
|
-
this.advance()
|
|
3523
|
-
continue
|
|
3524
|
-
}
|
|
3525
|
-
|
|
3526
|
-
const col = this.parseSQLColumnDef()
|
|
3527
|
-
if (col) {
|
|
3528
|
-
columns.push(col)
|
|
3529
|
-
}
|
|
3530
|
-
}
|
|
3531
|
-
}
|
|
3532
|
-
|
|
3533
|
-
return {
|
|
3534
|
-
type: 'CreateTableStatement',
|
|
3535
|
-
name: name,
|
|
3536
|
-
columns: columns
|
|
3537
|
-
}
|
|
3538
|
-
}
|
|
3539
|
-
|
|
3540
|
-
parseSQLColumnDef() {
|
|
3541
|
-
const nameToken = this.current()
|
|
3542
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
3543
|
-
return null
|
|
3544
|
-
}
|
|
3545
|
-
const name = nameToken.value
|
|
3546
|
-
this.advance()
|
|
3547
|
-
|
|
3548
|
-
this.match(TokenType.COLON)
|
|
3549
|
-
|
|
3550
|
-
const typeToken = this.current()
|
|
3551
|
-
let dataType = 'TEXT'
|
|
3552
|
-
if (typeToken && typeToken.type === TokenType.IDENTIFIER) {
|
|
3553
|
-
dataType = this.translateSQLType(typeToken.value)
|
|
3554
|
-
this.advance()
|
|
3555
|
-
}
|
|
3556
|
-
|
|
3557
|
-
let size = null
|
|
3558
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3559
|
-
const sizeToken = this.current()
|
|
3560
|
-
if (sizeToken && (sizeToken.type === TokenType.NUMBER || sizeToken.type === TokenType.INTEGER)) {
|
|
3561
|
-
size = parseInt(sizeToken.value)
|
|
3562
|
-
this.advance()
|
|
3563
|
-
}
|
|
3564
|
-
this.match(TokenType.RPAREN)
|
|
3565
|
-
}
|
|
3566
|
-
|
|
3567
|
-
const constraints = []
|
|
3568
|
-
|
|
3569
|
-
while (!this.isAtEnd()) {
|
|
3570
|
-
const token = this.current()
|
|
3571
|
-
|
|
3572
|
-
if (!token || token.type === TokenType.COMMA || token.type === TokenType.RPAREN ||
|
|
3573
|
-
token.type === TokenType.NEWLINE || token.type === TokenType.DEDENT) {
|
|
3574
|
-
break
|
|
3575
|
-
}
|
|
3576
|
-
|
|
3577
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3578
|
-
|
|
3579
|
-
if (value === 'cle' || value === 'key') {
|
|
3580
|
-
this.advance()
|
|
3581
|
-
if (this.matchValue('primaire') || this.matchValue('primary')) {
|
|
3582
|
-
constraints.push('PRIMARY KEY')
|
|
3583
|
-
}
|
|
3584
|
-
} else if (value === 'primaire' || value === 'primary') {
|
|
3585
|
-
this.advance()
|
|
3586
|
-
constraints.push('PRIMARY KEY')
|
|
3587
|
-
} else if (value === 'unique') {
|
|
3588
|
-
this.advance()
|
|
3589
|
-
constraints.push('UNIQUE')
|
|
3590
|
-
} else if (value === 'non' || value === 'not') {
|
|
3591
|
-
this.advance()
|
|
3592
|
-
if (this.matchValue('nul') || this.matchValue('null')) {
|
|
3593
|
-
constraints.push('NOT NULL')
|
|
3594
|
-
}
|
|
3595
|
-
} else if (value === 'auto' || value === 'autoincrement') {
|
|
3596
|
-
this.advance()
|
|
3597
|
-
if (this.matchValue('increment')) {
|
|
3598
|
-
}
|
|
3599
|
-
constraints.push('AUTO_INCREMENT')
|
|
3600
|
-
} else if (value === 'defaut' || value === 'default') {
|
|
3601
|
-
this.advance()
|
|
3602
|
-
const defToken = this.current()
|
|
3603
|
-
if (defToken) {
|
|
3604
|
-
constraints.push(`DEFAULT ${defToken.value}`)
|
|
3605
|
-
this.advance()
|
|
3606
|
-
}
|
|
3607
|
-
} else if (value === 'reference' || value === 'references') {
|
|
3608
|
-
this.advance()
|
|
3609
|
-
const refTable = this.current()
|
|
3610
|
-
if (refTable && refTable.type === TokenType.IDENTIFIER) {
|
|
3611
|
-
let ref = `REFERENCES ${refTable.value}`
|
|
3612
|
-
this.advance()
|
|
3613
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3614
|
-
const refCol = this.current()
|
|
3615
|
-
if (refCol) {
|
|
3616
|
-
ref += `(${refCol.value})`
|
|
3617
|
-
this.advance()
|
|
3618
|
-
}
|
|
3619
|
-
this.match(TokenType.RPAREN)
|
|
3620
|
-
}
|
|
3621
|
-
constraints.push(ref)
|
|
3622
|
-
}
|
|
3623
|
-
} else {
|
|
3624
|
-
this.advance()
|
|
3625
|
-
}
|
|
3626
|
-
}
|
|
3627
|
-
|
|
3628
|
-
return {
|
|
3629
|
-
name: name,
|
|
3630
|
-
type: dataType,
|
|
3631
|
-
size: size,
|
|
3632
|
-
constraints: constraints
|
|
3633
|
-
}
|
|
3634
|
-
}
|
|
3635
|
-
|
|
3636
|
-
translateSQLType(value) {
|
|
3637
|
-
const lower = value.toLowerCase()
|
|
3638
|
-
|
|
3639
|
-
const types = {
|
|
3640
|
-
'entier': 'INT',
|
|
3641
|
-
'nombre': 'INT',
|
|
3642
|
-
'texte': 'TEXT',
|
|
3643
|
-
'chaine': 'VARCHAR',
|
|
3644
|
-
'caracteres': 'VARCHAR',
|
|
3645
|
-
'decimal': 'DECIMAL',
|
|
3646
|
-
'flottant': 'FLOAT',
|
|
3647
|
-
'double': 'DOUBLE',
|
|
3648
|
-
'booleen': 'BOOLEAN',
|
|
3649
|
-
'date': 'DATE',
|
|
3650
|
-
'heure': 'TIME',
|
|
3651
|
-
'horodatage': 'TIMESTAMP',
|
|
3652
|
-
'dateheure': 'DATETIME',
|
|
3653
|
-
'blob': 'BLOB',
|
|
3654
|
-
'binaire': 'BINARY',
|
|
3655
|
-
'json': 'JSON',
|
|
3656
|
-
'uuid': 'UUID',
|
|
3657
|
-
'petit entier': 'SMALLINT',
|
|
3658
|
-
'grand entier': 'BIGINT',
|
|
3659
|
-
'tres petit entier': 'TINYINT'
|
|
3660
|
-
}
|
|
3661
|
-
|
|
3662
|
-
return types[lower] || value.toUpperCase()
|
|
3663
|
-
}
|
|
3664
|
-
|
|
3665
|
-
parseSQLCreateDatabase() {
|
|
3666
|
-
const nameToken = this.current()
|
|
3667
|
-
let name = null
|
|
3668
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3669
|
-
name = nameToken.value
|
|
3670
|
-
this.advance()
|
|
3671
|
-
}
|
|
3672
|
-
|
|
3673
|
-
return {
|
|
3674
|
-
type: 'CreateDatabaseStatement',
|
|
3675
|
-
name: name
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
|
|
3679
|
-
parseSQLCreateIndex() {
|
|
3680
|
-
let unique = false
|
|
3681
|
-
if (this.matchValue('unique')) {
|
|
3682
|
-
unique = true
|
|
3683
|
-
}
|
|
3684
|
-
|
|
3685
|
-
const nameToken = this.current()
|
|
3686
|
-
let name = null
|
|
3687
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3688
|
-
name = nameToken.value
|
|
3689
|
-
this.advance()
|
|
3690
|
-
}
|
|
3691
|
-
|
|
3692
|
-
if (this.matchValue('sur') || this.matchValue('on')) {
|
|
3693
|
-
}
|
|
3694
|
-
|
|
3695
|
-
const tableToken = this.current()
|
|
3696
|
-
let table = null
|
|
3697
|
-
if (tableToken && tableToken.type === TokenType.IDENTIFIER) {
|
|
3698
|
-
table = tableToken.value
|
|
3699
|
-
this.advance()
|
|
3700
|
-
}
|
|
3701
|
-
|
|
3702
|
-
const columns = []
|
|
3703
|
-
if (this.match(TokenType.LPAREN)) {
|
|
3704
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
3705
|
-
const colToken = this.current()
|
|
3706
|
-
if (colToken && colToken.type === TokenType.IDENTIFIER) {
|
|
3707
|
-
columns.push(colToken.value)
|
|
3708
|
-
this.advance()
|
|
3709
|
-
}
|
|
3710
|
-
this.match(TokenType.COMMA)
|
|
3711
|
-
}
|
|
3712
|
-
}
|
|
3713
|
-
|
|
3714
|
-
return {
|
|
3715
|
-
type: 'CreateIndexStatement',
|
|
3716
|
-
name: name,
|
|
3717
|
-
table: table,
|
|
3718
|
-
columns: columns,
|
|
3719
|
-
unique: unique
|
|
3720
|
-
}
|
|
3721
|
-
}
|
|
3722
|
-
|
|
3723
|
-
parseSQLDrop() {
|
|
3724
|
-
this.advance()
|
|
3725
|
-
|
|
3726
|
-
if (this.matchValue('table')) {
|
|
3727
|
-
const nameToken = this.current()
|
|
3728
|
-
let name = null
|
|
3729
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3730
|
-
name = nameToken.value
|
|
3731
|
-
this.advance()
|
|
3732
|
-
}
|
|
3733
|
-
return { type: 'DropTableStatement', name }
|
|
3734
|
-
}
|
|
3735
|
-
|
|
3736
|
-
if (this.matchValue('base') || this.matchValue('database')) {
|
|
3737
|
-
this.matchValue('de')
|
|
3738
|
-
this.matchValue('donnees')
|
|
3739
|
-
const nameToken = this.current()
|
|
3740
|
-
let name = null
|
|
3741
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3742
|
-
name = nameToken.value
|
|
3743
|
-
this.advance()
|
|
3744
|
-
}
|
|
3745
|
-
return { type: 'DropDatabaseStatement', name }
|
|
3746
|
-
}
|
|
3747
|
-
|
|
3748
|
-
if (this.matchValue('index')) {
|
|
3749
|
-
const nameToken = this.current()
|
|
3750
|
-
let name = null
|
|
3751
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3752
|
-
name = nameToken.value
|
|
3753
|
-
this.advance()
|
|
3754
|
-
}
|
|
3755
|
-
return { type: 'DropIndexStatement', name }
|
|
3756
|
-
}
|
|
3757
|
-
|
|
3758
|
-
return null
|
|
3759
|
-
}
|
|
3760
|
-
|
|
3761
|
-
parseSQLAlter() {
|
|
3762
|
-
this.advance()
|
|
3763
|
-
|
|
3764
|
-
if (this.matchValue('table')) {
|
|
3765
|
-
const nameToken = this.current()
|
|
3766
|
-
let name = null
|
|
3767
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3768
|
-
name = nameToken.value
|
|
3769
|
-
this.advance()
|
|
3770
|
-
}
|
|
3771
|
-
|
|
3772
|
-
const actions = []
|
|
3773
|
-
|
|
3774
|
-
if (this.matchValue('ajouter') || this.matchValue('add')) {
|
|
3775
|
-
if (this.matchValue('colonne') || this.matchValue('column')) {
|
|
3776
|
-
}
|
|
3777
|
-
const col = this.parseSQLColumnDef()
|
|
3778
|
-
if (col) {
|
|
3779
|
-
actions.push({ type: 'ADD', column: col })
|
|
3780
|
-
}
|
|
3781
|
-
}
|
|
3782
|
-
|
|
3783
|
-
if (this.matchValue('supprimer') || this.matchValue('drop')) {
|
|
3784
|
-
if (this.matchValue('colonne') || this.matchValue('column')) {
|
|
3785
|
-
}
|
|
3786
|
-
const colToken = this.current()
|
|
3787
|
-
if (colToken && colToken.type === TokenType.IDENTIFIER) {
|
|
3788
|
-
actions.push({ type: 'DROP', column: colToken.value })
|
|
3789
|
-
this.advance()
|
|
3790
|
-
}
|
|
3791
|
-
}
|
|
3792
|
-
|
|
3793
|
-
if (this.matchValue('modifier') || this.matchValue('modify')) {
|
|
3794
|
-
if (this.matchValue('colonne') || this.matchValue('column')) {
|
|
3795
|
-
}
|
|
3796
|
-
const col = this.parseSQLColumnDef()
|
|
3797
|
-
if (col) {
|
|
3798
|
-
actions.push({ type: 'MODIFY', column: col })
|
|
3799
|
-
}
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
return {
|
|
3803
|
-
type: 'AlterTableStatement',
|
|
3804
|
-
name: name,
|
|
3805
|
-
actions: actions
|
|
3806
|
-
}
|
|
3807
|
-
}
|
|
3808
|
-
|
|
3809
|
-
return null
|
|
3810
|
-
}
|
|
3811
|
-
|
|
3812
|
-
parseGraphQLProgram() {
|
|
3813
|
-
const program = {
|
|
3814
|
-
type: 'GraphQLProgram',
|
|
3815
|
-
definitions: []
|
|
3816
|
-
}
|
|
3817
|
-
|
|
3818
|
-
this.skipNewlines()
|
|
3819
|
-
|
|
3820
|
-
while (!this.isAtEnd()) {
|
|
3821
|
-
const def = this.parseGraphQLDefinition()
|
|
3822
|
-
if (def) {
|
|
3823
|
-
program.definitions.push(def)
|
|
3824
|
-
}
|
|
3825
|
-
this.skipNewlines()
|
|
3826
|
-
}
|
|
3827
|
-
|
|
3828
|
-
return program
|
|
3829
|
-
}
|
|
3830
|
-
|
|
3831
|
-
parseGraphQLDefinition() {
|
|
3832
|
-
this.skipNewlines()
|
|
3833
|
-
const token = this.current()
|
|
3834
|
-
|
|
3835
|
-
if (!token || token.type === TokenType.EOF) return null
|
|
3836
|
-
|
|
3837
|
-
const value = token.value ? token.value.toLowerCase() : ''
|
|
3838
|
-
|
|
3839
|
-
if (value === 'type' || value === 'modele') {
|
|
3840
|
-
return this.parseGraphQLType()
|
|
3841
|
-
}
|
|
3842
|
-
|
|
3843
|
-
if (value === 'input' || value === 'entree') {
|
|
3844
|
-
return this.parseGraphQLInput()
|
|
3845
|
-
}
|
|
3846
|
-
|
|
3847
|
-
if (value === 'enum' || value === 'enumeration') {
|
|
3848
|
-
return this.parseGraphQLEnum()
|
|
3849
|
-
}
|
|
3850
|
-
|
|
3851
|
-
if (value === 'interface') {
|
|
3852
|
-
return this.parseGraphQLInterface()
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
if (value === 'query' || value === 'requete') {
|
|
3856
|
-
return this.parseGraphQLQuery()
|
|
3857
|
-
}
|
|
3858
|
-
|
|
3859
|
-
if (value === 'mutation') {
|
|
3860
|
-
return this.parseGraphQLMutation()
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
if (value === 'subscription' || value === 'abonnement') {
|
|
3864
|
-
return this.parseGraphQLSubscription()
|
|
3865
|
-
}
|
|
3866
|
-
|
|
3867
|
-
if (value === 'schema') {
|
|
3868
|
-
return this.parseGraphQLSchema()
|
|
3869
|
-
}
|
|
3870
|
-
|
|
3871
|
-
this.advance()
|
|
3872
|
-
return null
|
|
3873
|
-
}
|
|
3874
|
-
|
|
3875
|
-
parseGraphQLType() {
|
|
3876
|
-
this.advance()
|
|
3877
|
-
|
|
3878
|
-
const nameToken = this.current()
|
|
3879
|
-
let name = null
|
|
3880
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3881
|
-
name = nameToken.value
|
|
3882
|
-
this.advance()
|
|
3883
|
-
}
|
|
3884
|
-
|
|
3885
|
-
let implements_ = []
|
|
3886
|
-
if (this.matchValue('implemente') || this.matchValue('implements')) {
|
|
3887
|
-
while (!this.isAtEnd()) {
|
|
3888
|
-
const implToken = this.current()
|
|
3889
|
-
if (!implToken || implToken.type !== TokenType.IDENTIFIER) break
|
|
3890
|
-
|
|
3891
|
-
const v = implToken.value.toLowerCase()
|
|
3892
|
-
if (v === '{' || this.peek()?.type === TokenType.LBRACE) break
|
|
3893
|
-
|
|
3894
|
-
implements_.push(implToken.value)
|
|
3895
|
-
this.advance()
|
|
3896
|
-
|
|
3897
|
-
if (!this.match(TokenType.AMPERSAND) && !this.match(TokenType.COMMA)) break
|
|
3898
|
-
}
|
|
3899
|
-
}
|
|
3900
|
-
|
|
3901
|
-
this.skipNewlines()
|
|
3902
|
-
const fields = this.parseGraphQLFields()
|
|
3903
|
-
|
|
3904
|
-
return {
|
|
3905
|
-
type: 'TypeDefinition',
|
|
3906
|
-
name: name,
|
|
3907
|
-
implements: implements_,
|
|
3908
|
-
fields: fields
|
|
3909
|
-
}
|
|
3910
|
-
}
|
|
3911
|
-
|
|
3912
|
-
parseGraphQLInput() {
|
|
3913
|
-
this.advance()
|
|
3914
|
-
|
|
3915
|
-
const nameToken = this.current()
|
|
3916
|
-
let name = null
|
|
3917
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3918
|
-
name = nameToken.value
|
|
3919
|
-
this.advance()
|
|
3920
|
-
}
|
|
3921
|
-
|
|
3922
|
-
this.skipNewlines()
|
|
3923
|
-
const fields = this.parseGraphQLFields()
|
|
3924
|
-
|
|
3925
|
-
return {
|
|
3926
|
-
type: 'InputDefinition',
|
|
3927
|
-
name: name,
|
|
3928
|
-
fields: fields
|
|
3929
|
-
}
|
|
3930
|
-
}
|
|
3931
|
-
|
|
3932
|
-
parseGraphQLEnum() {
|
|
3933
|
-
this.advance()
|
|
3934
|
-
|
|
3935
|
-
const nameToken = this.current()
|
|
3936
|
-
let name = null
|
|
3937
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3938
|
-
name = nameToken.value
|
|
3939
|
-
this.advance()
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
const values = []
|
|
3943
|
-
|
|
3944
|
-
if (this.match(TokenType.LBRACE)) {
|
|
3945
|
-
while (!this.isAtEnd() && !this.match(TokenType.RBRACE)) {
|
|
3946
|
-
this.skipNewlines()
|
|
3947
|
-
const valToken = this.current()
|
|
3948
|
-
if (valToken && valToken.type === TokenType.IDENTIFIER) {
|
|
3949
|
-
values.push(valToken.value)
|
|
3950
|
-
this.advance()
|
|
3951
|
-
}
|
|
3952
|
-
this.skipNewlines()
|
|
3953
|
-
}
|
|
3954
|
-
} else {
|
|
3955
|
-
this.skipNewlines()
|
|
3956
|
-
this.match(TokenType.INDENT)
|
|
3957
|
-
|
|
3958
|
-
while (!this.isAtEnd()) {
|
|
3959
|
-
const current = this.current()
|
|
3960
|
-
|
|
3961
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
3962
|
-
this.advance()
|
|
3963
|
-
break
|
|
3964
|
-
}
|
|
3965
|
-
|
|
3966
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
3967
|
-
this.advance()
|
|
3968
|
-
continue
|
|
3969
|
-
}
|
|
3970
|
-
|
|
3971
|
-
if (current && current.type === TokenType.IDENTIFIER) {
|
|
3972
|
-
values.push(current.value)
|
|
3973
|
-
this.advance()
|
|
3974
|
-
}
|
|
3975
|
-
}
|
|
3976
|
-
}
|
|
3977
|
-
|
|
3978
|
-
return {
|
|
3979
|
-
type: 'EnumDefinition',
|
|
3980
|
-
name: name,
|
|
3981
|
-
values: values
|
|
3982
|
-
}
|
|
3983
|
-
}
|
|
3984
|
-
|
|
3985
|
-
parseGraphQLInterface() {
|
|
3986
|
-
this.advance()
|
|
3987
|
-
|
|
3988
|
-
const nameToken = this.current()
|
|
3989
|
-
let name = null
|
|
3990
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
3991
|
-
name = nameToken.value
|
|
3992
|
-
this.advance()
|
|
3993
|
-
}
|
|
3994
|
-
|
|
3995
|
-
this.skipNewlines()
|
|
3996
|
-
const fields = this.parseGraphQLFields()
|
|
3997
|
-
|
|
3998
|
-
return {
|
|
3999
|
-
type: 'InterfaceDefinition',
|
|
4000
|
-
name: name,
|
|
4001
|
-
fields: fields
|
|
4002
|
-
}
|
|
4003
|
-
}
|
|
4004
|
-
|
|
4005
|
-
parseGraphQLFields() {
|
|
4006
|
-
const fields = []
|
|
4007
|
-
|
|
4008
|
-
if (this.match(TokenType.LBRACE)) {
|
|
4009
|
-
while (!this.isAtEnd() && !this.match(TokenType.RBRACE)) {
|
|
4010
|
-
this.skipNewlines()
|
|
4011
|
-
const field = this.parseGraphQLField()
|
|
4012
|
-
if (field) {
|
|
4013
|
-
fields.push(field)
|
|
4014
|
-
}
|
|
4015
|
-
this.skipNewlines()
|
|
4016
|
-
}
|
|
4017
|
-
} else {
|
|
4018
|
-
this.skipNewlines()
|
|
4019
|
-
this.match(TokenType.INDENT)
|
|
4020
|
-
|
|
4021
|
-
while (!this.isAtEnd()) {
|
|
4022
|
-
const current = this.current()
|
|
4023
|
-
|
|
4024
|
-
if (current && current.type === TokenType.DEDENT) {
|
|
4025
|
-
this.advance()
|
|
4026
|
-
break
|
|
4027
|
-
}
|
|
4028
|
-
|
|
4029
|
-
if (current && current.type === TokenType.NEWLINE) {
|
|
4030
|
-
this.advance()
|
|
4031
|
-
continue
|
|
4032
|
-
}
|
|
4033
|
-
|
|
4034
|
-
const field = this.parseGraphQLField()
|
|
4035
|
-
if (field) {
|
|
4036
|
-
fields.push(field)
|
|
4037
|
-
}
|
|
4038
|
-
}
|
|
4039
|
-
}
|
|
4040
|
-
|
|
4041
|
-
return fields
|
|
4042
|
-
}
|
|
4043
|
-
|
|
4044
|
-
parseGraphQLField() {
|
|
4045
|
-
const nameToken = this.current()
|
|
4046
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
4047
|
-
return null
|
|
4048
|
-
}
|
|
4049
|
-
const name = nameToken.value
|
|
4050
|
-
this.advance()
|
|
4051
|
-
|
|
4052
|
-
const args = []
|
|
4053
|
-
if (this.match(TokenType.LPAREN)) {
|
|
4054
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
4055
|
-
const arg = this.parseGraphQLArg()
|
|
4056
|
-
if (arg) {
|
|
4057
|
-
args.push(arg)
|
|
4058
|
-
}
|
|
4059
|
-
this.match(TokenType.COMMA)
|
|
4060
|
-
}
|
|
4061
|
-
}
|
|
4062
|
-
|
|
4063
|
-
this.match(TokenType.COLON)
|
|
4064
|
-
|
|
4065
|
-
const fieldType = this.parseGraphQLTypeRef()
|
|
4066
|
-
|
|
4067
|
-
const directives = []
|
|
4068
|
-
while (this.match(TokenType.AT)) {
|
|
4069
|
-
const dirToken = this.current()
|
|
4070
|
-
if (dirToken && dirToken.type === TokenType.IDENTIFIER) {
|
|
4071
|
-
directives.push(dirToken.value)
|
|
4072
|
-
this.advance()
|
|
4073
|
-
}
|
|
4074
|
-
}
|
|
4075
|
-
|
|
4076
|
-
return {
|
|
4077
|
-
name: name,
|
|
4078
|
-
args: args,
|
|
4079
|
-
type: fieldType,
|
|
4080
|
-
directives: directives
|
|
4081
|
-
}
|
|
4082
|
-
}
|
|
4083
|
-
|
|
4084
|
-
parseGraphQLArg() {
|
|
4085
|
-
const nameToken = this.current()
|
|
4086
|
-
if (!nameToken || nameToken.type !== TokenType.IDENTIFIER) {
|
|
4087
|
-
return null
|
|
4088
|
-
}
|
|
4089
|
-
const name = nameToken.value
|
|
4090
|
-
this.advance()
|
|
4091
|
-
|
|
4092
|
-
this.match(TokenType.COLON)
|
|
4093
|
-
|
|
4094
|
-
const argType = this.parseGraphQLTypeRef()
|
|
4095
|
-
|
|
4096
|
-
let defaultValue = null
|
|
4097
|
-
if (this.match(TokenType.EQUALS)) {
|
|
4098
|
-
const valToken = this.current()
|
|
4099
|
-
if (valToken) {
|
|
4100
|
-
if (valToken.type === TokenType.STRING) {
|
|
4101
|
-
defaultValue = valToken.value
|
|
4102
|
-
} else if (valToken.type === TokenType.NUMBER || valToken.type === TokenType.INTEGER) {
|
|
4103
|
-
defaultValue = parseFloat(valToken.value)
|
|
4104
|
-
} else if (valToken.type === TokenType.IDENTIFIER) {
|
|
4105
|
-
defaultValue = valToken.value
|
|
4106
|
-
}
|
|
4107
|
-
this.advance()
|
|
4108
|
-
}
|
|
4109
|
-
}
|
|
4110
|
-
|
|
4111
|
-
return {
|
|
4112
|
-
name: name,
|
|
4113
|
-
type: argType,
|
|
4114
|
-
default: defaultValue
|
|
4115
|
-
}
|
|
4116
|
-
}
|
|
4117
|
-
|
|
4118
|
-
parseGraphQLTypeRef() {
|
|
4119
|
-
let isArray = false
|
|
4120
|
-
|
|
4121
|
-
if (this.match(TokenType.LBRACKET)) {
|
|
4122
|
-
isArray = true
|
|
4123
|
-
}
|
|
4124
|
-
|
|
4125
|
-
const typeToken = this.current()
|
|
4126
|
-
let typeName = 'String'
|
|
4127
|
-
if (typeToken && typeToken.type === TokenType.IDENTIFIER) {
|
|
4128
|
-
typeName = this.translateGraphQLType(typeToken.value)
|
|
4129
|
-
this.advance()
|
|
4130
|
-
}
|
|
4131
|
-
|
|
4132
|
-
let isRequired = false
|
|
4133
|
-
if (this.match(TokenType.BANG)) {
|
|
4134
|
-
isRequired = true
|
|
4135
|
-
}
|
|
4136
|
-
|
|
4137
|
-
if (isArray) {
|
|
4138
|
-
this.match(TokenType.RBRACKET)
|
|
4139
|
-
if (this.match(TokenType.BANG)) {
|
|
4140
|
-
isRequired = true
|
|
4141
|
-
}
|
|
4142
|
-
}
|
|
4143
|
-
|
|
4144
|
-
return {
|
|
4145
|
-
name: typeName,
|
|
4146
|
-
isArray: isArray,
|
|
4147
|
-
isRequired: isRequired
|
|
4148
|
-
}
|
|
4149
|
-
}
|
|
4150
|
-
|
|
4151
|
-
translateGraphQLType(value) {
|
|
4152
|
-
const lower = value.toLowerCase()
|
|
4153
|
-
|
|
4154
|
-
const types = {
|
|
4155
|
-
'chaine': 'String',
|
|
4156
|
-
'texte': 'String',
|
|
4157
|
-
'entier': 'Int',
|
|
4158
|
-
'nombre': 'Int',
|
|
4159
|
-
'flottant': 'Float',
|
|
4160
|
-
'decimal': 'Float',
|
|
4161
|
-
'booleen': 'Boolean',
|
|
4162
|
-
'identifiant': 'ID',
|
|
4163
|
-
'id': 'ID'
|
|
4164
|
-
}
|
|
4165
|
-
|
|
4166
|
-
return types[lower] || value
|
|
4167
|
-
}
|
|
4168
|
-
|
|
4169
|
-
parseGraphQLQuery() {
|
|
4170
|
-
this.advance()
|
|
4171
|
-
|
|
4172
|
-
const nameToken = this.current()
|
|
4173
|
-
let name = null
|
|
4174
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
4175
|
-
name = nameToken.value
|
|
4176
|
-
this.advance()
|
|
4177
|
-
}
|
|
4178
|
-
|
|
4179
|
-
const args = []
|
|
4180
|
-
if (this.match(TokenType.LPAREN)) {
|
|
4181
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
4182
|
-
const arg = this.parseGraphQLArg()
|
|
4183
|
-
if (arg) {
|
|
4184
|
-
args.push(arg)
|
|
4185
|
-
}
|
|
4186
|
-
this.match(TokenType.COMMA)
|
|
4187
|
-
}
|
|
4188
|
-
}
|
|
4189
|
-
|
|
4190
|
-
this.match(TokenType.COLON)
|
|
4191
|
-
const returnType = this.parseGraphQLTypeRef()
|
|
4192
|
-
|
|
4193
|
-
return {
|
|
4194
|
-
type: 'QueryDefinition',
|
|
4195
|
-
name: name,
|
|
4196
|
-
args: args,
|
|
4197
|
-
returnType: returnType
|
|
4198
|
-
}
|
|
4199
|
-
}
|
|
4200
|
-
|
|
4201
|
-
parseGraphQLMutation() {
|
|
4202
|
-
this.advance()
|
|
4203
|
-
|
|
4204
|
-
const nameToken = this.current()
|
|
4205
|
-
let name = null
|
|
4206
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
4207
|
-
name = nameToken.value
|
|
4208
|
-
this.advance()
|
|
4209
|
-
}
|
|
4210
|
-
|
|
4211
|
-
const args = []
|
|
4212
|
-
if (this.match(TokenType.LPAREN)) {
|
|
4213
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
4214
|
-
const arg = this.parseGraphQLArg()
|
|
4215
|
-
if (arg) {
|
|
4216
|
-
args.push(arg)
|
|
4217
|
-
}
|
|
4218
|
-
this.match(TokenType.COMMA)
|
|
4219
|
-
}
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
this.match(TokenType.COLON)
|
|
4223
|
-
const returnType = this.parseGraphQLTypeRef()
|
|
4224
|
-
|
|
4225
|
-
return {
|
|
4226
|
-
type: 'MutationDefinition',
|
|
4227
|
-
name: name,
|
|
4228
|
-
args: args,
|
|
4229
|
-
returnType: returnType
|
|
4230
|
-
}
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
|
-
parseGraphQLSubscription() {
|
|
4234
|
-
this.advance()
|
|
4235
|
-
|
|
4236
|
-
const nameToken = this.current()
|
|
4237
|
-
let name = null
|
|
4238
|
-
if (nameToken && nameToken.type === TokenType.IDENTIFIER) {
|
|
4239
|
-
name = nameToken.value
|
|
4240
|
-
this.advance()
|
|
4241
|
-
}
|
|
4242
|
-
|
|
4243
|
-
const args = []
|
|
4244
|
-
if (this.match(TokenType.LPAREN)) {
|
|
4245
|
-
while (!this.isAtEnd() && !this.match(TokenType.RPAREN)) {
|
|
4246
|
-
const arg = this.parseGraphQLArg()
|
|
4247
|
-
if (arg) {
|
|
4248
|
-
args.push(arg)
|
|
4249
|
-
}
|
|
4250
|
-
this.match(TokenType.COMMA)
|
|
4251
|
-
}
|
|
4252
|
-
}
|
|
4253
|
-
|
|
4254
|
-
this.match(TokenType.COLON)
|
|
4255
|
-
const returnType = this.parseGraphQLTypeRef()
|
|
4256
|
-
|
|
4257
|
-
return {
|
|
4258
|
-
type: 'SubscriptionDefinition',
|
|
4259
|
-
name: name,
|
|
4260
|
-
args: args,
|
|
4261
|
-
returnType: returnType
|
|
4262
|
-
}
|
|
4263
|
-
}
|
|
4264
|
-
|
|
4265
|
-
parseGraphQLSchema() {
|
|
4266
|
-
this.advance()
|
|
4267
|
-
|
|
4268
|
-
const operations = {}
|
|
4269
|
-
|
|
4270
|
-
if (this.match(TokenType.LBRACE)) {
|
|
4271
|
-
while (!this.isAtEnd() && !this.match(TokenType.RBRACE)) {
|
|
4272
|
-
this.skipNewlines()
|
|
4273
|
-
const opToken = this.current()
|
|
4274
|
-
|
|
4275
|
-
if (opToken && opToken.type === TokenType.IDENTIFIER) {
|
|
4276
|
-
const op = opToken.value.toLowerCase()
|
|
4277
|
-
this.advance()
|
|
4278
|
-
|
|
4279
|
-
this.match(TokenType.COLON)
|
|
4280
|
-
|
|
4281
|
-
const typeToken = this.current()
|
|
4282
|
-
if (typeToken && typeToken.type === TokenType.IDENTIFIER) {
|
|
4283
|
-
if (op === 'query' || op === 'requete') {
|
|
4284
|
-
operations.query = typeToken.value
|
|
4285
|
-
} else if (op === 'mutation') {
|
|
4286
|
-
operations.mutation = typeToken.value
|
|
4287
|
-
} else if (op === 'subscription' || op === 'abonnement') {
|
|
4288
|
-
operations.subscription = typeToken.value
|
|
4289
|
-
}
|
|
4290
|
-
this.advance()
|
|
4291
|
-
}
|
|
4292
|
-
}
|
|
4293
|
-
|
|
4294
|
-
this.skipNewlines()
|
|
4295
|
-
}
|
|
4296
|
-
}
|
|
4297
|
-
|
|
4298
|
-
return {
|
|
4299
|
-
type: 'SchemaDefinition',
|
|
4300
|
-
operations: operations
|
|
4301
|
-
}
|
|
4302
|
-
}
|
|
4303
|
-
}
|
|
4304
|
-
|
|
4305
|
-
module.exports = {
|
|
4306
|
-
EtherParser
|
|
4307
|
-
}
|