ether-code 0.4.0 → 0.4.2

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.
@@ -221,6 +221,11 @@ class EtherLexer {
221
221
  }
222
222
 
223
223
  if (char === '#') {
224
+ const next = this.peek(1)
225
+ if (next && (this.isHexDigit(next) || this.isAlpha(next))) {
226
+ this.scanHashToken()
227
+ return
228
+ }
224
229
  this.scanComment()
225
230
  return
226
231
  }
@@ -319,6 +324,42 @@ class EtherLexer {
319
324
  }
320
325
  }
321
326
 
327
+ scanHashToken() {
328
+ const startLine = this.line
329
+ const startCol = this.column
330
+
331
+ this.advance()
332
+
333
+ let value = ''
334
+ let isHexColor = true
335
+ let charCount = 0
336
+
337
+ while (!this.isAtEnd()) {
338
+ const char = this.peek()
339
+ if (this.isHexDigit(char)) {
340
+ value += this.advance()
341
+ charCount++
342
+ } else if (this.isAlpha(char) && !this.isHexDigit(char)) {
343
+ isHexColor = false
344
+ value += this.advance()
345
+ } else if (char === '-' || char === '_') {
346
+ isHexColor = false
347
+ value += this.advance()
348
+ } else {
349
+ break
350
+ }
351
+ }
352
+
353
+ if (isHexColor && (charCount === 3 || charCount === 4 || charCount === 6 || charCount === 8)) {
354
+ this.tokens.push(new Token(TokenType.HEX, '#' + value, startLine, startCol, this.currentIndent))
355
+ } else {
356
+ this.tokens.push(new Token(TokenType.HASH, '#', startLine, startCol, this.currentIndent))
357
+ if (value) {
358
+ this.tokens.push(new Token(TokenType.IDENTIFIER, value, startLine, startCol + 1, this.currentIndent))
359
+ }
360
+ }
361
+ }
362
+
322
363
  scanBlockComment() {
323
364
  const startLine = this.line
324
365
  const startCol = this.column
@@ -521,10 +562,42 @@ class EtherLexer {
521
562
  }
522
563
 
523
564
  if (type === TokenType.FLOAT) {
524
- this.tokens.push(new Token(type, parseFloat(value), startLine, startCol, this.currentIndent))
565
+ let numValue = String(parseFloat(value))
566
+ const unit = this.scanCSSUnit()
567
+ if (unit) numValue += unit
568
+ this.tokens.push(new Token(type, numValue, startLine, startCol, this.currentIndent))
525
569
  } else {
526
- this.tokens.push(new Token(type, parseInt(value, 10), startLine, startCol, this.currentIndent))
570
+ let numValue = String(parseInt(value, 10))
571
+ const unit = this.scanCSSUnit()
572
+ if (unit) numValue += unit
573
+ this.tokens.push(new Token(type, numValue, startLine, startCol, this.currentIndent))
574
+ }
575
+ }
576
+
577
+ scanCSSUnit() {
578
+ const units = ['px', 'em', 'rem', 'vh', 'vw', 'vmin', 'vmax', '%', 'fr', 's', 'ms', 'deg', 'rad', 'turn', 'ch', 'ex', 'cm', 'mm', 'in', 'pt', 'pc', 'cqw', 'cqh']
579
+
580
+ for (const unit of units) {
581
+ let matches = true
582
+ for (let i = 0; i < unit.length; i++) {
583
+ const char = this.peek(i)
584
+ if (!char || char.toLowerCase() !== unit[i].toLowerCase()) {
585
+ matches = false
586
+ break
587
+ }
588
+ }
589
+ if (matches) {
590
+ const afterUnit = this.peek(unit.length)
591
+ if (!afterUnit || !this.isAlpha(afterUnit)) {
592
+ let result = ''
593
+ for (let i = 0; i < unit.length; i++) {
594
+ result += this.advance()
595
+ }
596
+ return result
597
+ }
598
+ }
527
599
  }
600
+ return ''
528
601
  }
529
602
 
530
603
  scanIdentifier() {
@@ -693,7 +766,15 @@ class EtherLexer {
693
766
 
694
767
  case '-':
695
768
  if (this.match('-')) {
696
- this.tokens.push(new Token(TokenType.MINUS, '--', startLine, startCol, this.currentIndent))
769
+ if (this.isAlpha(this.peek()) || this.peek() === '-') {
770
+ let varName = '--'
771
+ while (this.isAlphaNumeric(this.peek()) || this.peek() === '-' || this.peek() === '_') {
772
+ varName += this.advance()
773
+ }
774
+ this.tokens.push(new Token(TokenType.IDENTIFIER, varName, startLine, startCol, this.currentIndent))
775
+ } else {
776
+ this.tokens.push(new Token(TokenType.MINUS, '--', startLine, startCol, this.currentIndent))
777
+ }
697
778
  } else if (this.match('>')) {
698
779
  this.tokens.push(new Token(TokenType.ARROW, '->', startLine, startCol, this.currentIndent))
699
780
  } else if (this.match('=')) {
@@ -866,4 +947,4 @@ module.exports = {
866
947
  Token,
867
948
  TokenType,
868
949
  LANG_BLOCKS
869
- }
950
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {