Browse Source

Redo map as each, still playing with the syntax

master
Dylan Baker 5 years ago
parent
commit
ebc21f694d
4 changed files with 6 additions and 6 deletions
  1. 1
    1
      src/compiler.js
  2. 1
    1
      src/lexer.js
  3. 3
    3
      src/parser.js
  4. 1
    1
      test/compiler.js

+ 1
- 1
src/compiler.js View File

@@ -28,7 +28,7 @@ module.exports = class Compiler {
28 28
         this.result += node.content
29 29
       } else if (node.type === 'identifier') {
30 30
         this.result += this.lookup(node.name)
31
-      } else if (node.type === 'map') {
31
+      } else if (node.type === 'each') {
32 32
         const symbol = node.symbol.value
33 33
         const subject = this.lookup(node.subject.name)
34 34
         subject.forEach(item => {

+ 1
- 1
src/lexer.js View File

@@ -58,7 +58,7 @@ module.exports = class Lexer {
58 58
 
59 59
         let value = endPattern.exec(source.slice(pos))[0].trim()
60 60
 
61
-        if (['if', 'map'].includes(value)) {
61
+        if (['if', 'each'].includes(value)) {
62 62
           tokenStream.tokens.push({
63 63
             type: tokenTypes.KEYWORD,
64 64
             line: line,

+ 3
- 3
src/parser.js View File

@@ -77,12 +77,12 @@ module.exports = class Parser {
77 77
   keyword() {
78 78
     const keyword = this.tokenStream.eat(tokenTypes.KEYWORD)
79 79
 
80
-    if (keyword.value === 'map') {
80
+    if (keyword.value === 'each') {
81
+      const subject = this.identifier()
81 82
       const symbol = this.tokenStream.eat(tokenTypes.SYMBOL)
82 83
       const body = this.expr()
83
-      const subject = this.identifier()
84 84
       return new Node({
85
-        type: 'map',
85
+        type: 'each',
86 86
         symbol: symbol,
87 87
         body: body,
88 88
         subject: subject,

+ 1
- 1
test/compiler.js View File

@@ -49,7 +49,7 @@ test('compiles map operations', function(t) {
49 49
   const lexer = new Lexer()
50 50
   const tokenStream = lexer.scan(`
51 51
     (ul
52
-      (map 'item (li item) items))
52
+      (each items 'item (li item)))
53 53
   `)
54 54
   const parser = new Parser(tokenStream)
55 55
   const tree = parser.parse()

Loading…
Cancel
Save