ether-code 0.9.7 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/ether.js CHANGED
@@ -6,7 +6,7 @@ const http = require('http')
6
6
  const { EtherCompiler } = require('./compiler')
7
7
  const { Watcher } = require('./watcher')
8
8
 
9
- const VERSION = '0.9.7'
9
+ const VERSION = '0.9.8'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
@@ -589,6 +589,12 @@ class HTMLGenerator {
589
589
  case 'include':
590
590
  this.generateInclude(node)
591
591
  break
592
+ case 'EtherCSS':
593
+ this.generateEtherCSS(node)
594
+ break
595
+ case 'EtherJS':
596
+ this.generateEtherJS(node)
597
+ break
592
598
  default:
593
599
  if (node.tag || node.tagName || node.name) {
594
600
  this.generateElement(node)
@@ -1069,6 +1075,58 @@ class HTMLGenerator {
1069
1075
  })
1070
1076
  return result.join('\n')
1071
1077
  }
1078
+
1079
+ generateEtherCSS(node) {
1080
+ if (!node.source) return
1081
+
1082
+ try {
1083
+ const { EtherParserCSS } = require('./ether-parser-css')
1084
+ const { CSSGenerator } = require('./css-generator')
1085
+
1086
+ const cssParser = new EtherParserCSS()
1087
+ const cssAst = cssParser.parse(node.source)
1088
+
1089
+ const cssGenerator = new CSSGenerator()
1090
+ cssGenerator.loadI18n('./i18n-css.json')
1091
+ const cssOutput = cssGenerator.generate(cssAst)
1092
+
1093
+ if (cssOutput) {
1094
+ const lines = cssOutput.split('\n')
1095
+ for (const line of lines) {
1096
+ this.writeLine(line)
1097
+ }
1098
+ }
1099
+ } catch (e) {
1100
+ this.writeLine('/* Erreur de compilation CSS: ' + e.message + ' */')
1101
+ this.writeLine(node.source)
1102
+ }
1103
+ }
1104
+
1105
+ generateEtherJS(node) {
1106
+ if (!node.source) return
1107
+
1108
+ try {
1109
+ const { EtherParserJS } = require('./ether-parser-js')
1110
+ const { JSGenerator } = require('./js-generator')
1111
+
1112
+ const jsParser = new EtherParserJS()
1113
+ const jsAst = jsParser.parse(node.source)
1114
+
1115
+ const jsGenerator = new JSGenerator()
1116
+ jsGenerator.loadI18n('./i18n-js.json')
1117
+ const jsOutput = jsGenerator.generate(jsAst)
1118
+
1119
+ if (jsOutput) {
1120
+ const lines = jsOutput.split('\n')
1121
+ for (const line of lines) {
1122
+ this.writeLine(line)
1123
+ }
1124
+ }
1125
+ } catch (e) {
1126
+ this.writeLine('// Erreur de compilation JS: ' + e.message)
1127
+ this.writeLine(node.source)
1128
+ }
1129
+ }
1072
1130
  }
1073
1131
 
1074
1132
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.9.7",
3
+ "version": "0.9.8",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {
@@ -118,14 +118,14 @@ class EtherParserHTML extends EtherParserBase {
118
118
  'lecture': ['seule', 'auto'],
119
119
  'nouvelle': ['fenetre'],
120
120
  'a': ['popup'],
121
- 'jeu': ['caracteres', 'caractères'],
121
+ 'jeu': ['caracteres', 'caractères'],
122
122
  'equivalent': ['http'],
123
- 'équivalent': ['http'],
123
+ 'équivalent': ['http'],
124
124
  'fusion': ['colonnes', 'lignes'],
125
- 'plein': ['ecran', 'écran'],
125
+ 'plein': ['ecran', 'écran'],
126
126
  'bac': ['sable'],
127
- 'origine': ['croisee', 'croisée'],
128
- 'sources': ['reactives', 'réactives']
127
+ 'origine': ['croisee', 'croisée'],
128
+ 'sources': ['reactives', 'réactives']
129
129
  }
130
130
 
131
131
  while (!this.isAtEnd()) {
@@ -203,9 +203,22 @@ class EtherParserHTML extends EtherParserBase {
203
203
  const rawContentTags = ['script', 'style']
204
204
  const isRawContent = rawContentTags.includes(tag)
205
205
  const isScript = tag === 'script'
206
+ const isStyle = tag === 'style'
206
207
 
207
208
  if (this.match(TokenType.INDENT)) {
208
- if (isRawContent) {
209
+ if (isStyle) {
210
+ const etherSource = this.collectEtherBlock()
211
+ children.push({
212
+ type: 'EtherCSS',
213
+ source: etherSource
214
+ })
215
+ } else if (isScript) {
216
+ const etherSource = this.collectEtherBlock()
217
+ children.push({
218
+ type: 'EtherJS',
219
+ source: etherSource
220
+ })
221
+ } else if (isRawContent) {
209
222
  let rawText = []
210
223
  while (!this.isAtEnd()) {
211
224
  const current = this.current()
@@ -227,11 +240,7 @@ class EtherParserHTML extends EtherParserBase {
227
240
  }
228
241
 
229
242
  if (current && current.type === TokenType.STRING) {
230
- if (isScript) {
231
- rawText.push("'" + current.value.replace(/'/g, "\\'") + "'")
232
- } else {
233
- rawText.push(current.value)
234
- }
243
+ rawText.push(current.value)
235
244
  this.advance()
236
245
  continue
237
246
  }
@@ -321,6 +330,84 @@ class EtherParserHTML extends EtherParserBase {
321
330
  return String(token.value)
322
331
  }
323
332
 
333
+ collectEtherBlock() {
334
+ const lines = []
335
+ let currentLine = []
336
+ let indentDepth = 1
337
+
338
+ while (!this.isAtEnd()) {
339
+ const current = this.current()
340
+
341
+ if (current && current.type === TokenType.DEDENT) {
342
+ if (currentLine.length > 0) {
343
+ lines.push(' '.repeat(Math.max(0, indentDepth - 1)) + this.joinTokens(currentLine))
344
+ currentLine = []
345
+ }
346
+ indentDepth--
347
+ this.advance()
348
+ if (indentDepth <= 0) {
349
+ break
350
+ }
351
+ continue
352
+ }
353
+
354
+ if (current && current.type === TokenType.INDENT) {
355
+ if (currentLine.length > 0) {
356
+ lines.push(' '.repeat(Math.max(0, indentDepth - 1)) + this.joinTokens(currentLine))
357
+ currentLine = []
358
+ }
359
+ indentDepth++
360
+ this.advance()
361
+ continue
362
+ }
363
+
364
+ if (current && current.type === TokenType.NEWLINE) {
365
+ if (currentLine.length > 0) {
366
+ lines.push(' '.repeat(Math.max(0, indentDepth - 1)) + this.joinTokens(currentLine))
367
+ currentLine = []
368
+ }
369
+ this.advance()
370
+ continue
371
+ }
372
+
373
+ if (!current || current.type === TokenType.EOF) break
374
+
375
+ if (current.type === TokenType.STRING) {
376
+ currentLine.push('"' + current.value + '"')
377
+ } else {
378
+ currentLine.push(this.tokenToString(current))
379
+ }
380
+ this.advance()
381
+ }
382
+
383
+ if (currentLine.length > 0) {
384
+ lines.push(' '.repeat(Math.max(0, indentDepth - 1)) + this.joinTokens(currentLine))
385
+ }
386
+
387
+ return lines.join('\n')
388
+ }
389
+
390
+ joinTokens(tokens) {
391
+ let result = ''
392
+ for (let i = 0; i < tokens.length; i++) {
393
+ const token = tokens[i]
394
+ const prevToken = i > 0 ? tokens[i - 1] : null
395
+
396
+ const noSpaceBefore = [':', ',', ')', ']']
397
+ const noSpaceAfter = ['.', '#', '(', '[', '::', '-']
398
+
399
+ if (i > 0) {
400
+ const needSpace = !noSpaceBefore.includes(token) && !noSpaceAfter.includes(prevToken)
401
+ if (needSpace) {
402
+ result += ' '
403
+ }
404
+ }
405
+
406
+ result += token
407
+ }
408
+ return result
409
+ }
410
+
324
411
  processCompoundTags(tagName) {
325
412
  const nextToken = this.current()
326
413
  if (!nextToken || nextToken.type !== TokenType.IDENTIFIER) {
@@ -585,4 +672,4 @@ class EtherParserHTML extends EtherParserBase {
585
672
  }
586
673
  }
587
674
 
588
- module.exports = { EtherParserHTML }
675
+ module.exports = { EtherParserHTML }