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
         this.result += node.content
28
         this.result += node.content
29
       } else if (node.type === 'identifier') {
29
       } else if (node.type === 'identifier') {
30
         this.result += this.lookup(node.name)
30
         this.result += this.lookup(node.name)
31
-      } else if (node.type === 'map') {
31
+      } else if (node.type === 'each') {
32
         const symbol = node.symbol.value
32
         const symbol = node.symbol.value
33
         const subject = this.lookup(node.subject.name)
33
         const subject = this.lookup(node.subject.name)
34
         subject.forEach(item => {
34
         subject.forEach(item => {

+ 1
- 1
src/lexer.js View File

58
 
58
 
59
         let value = endPattern.exec(source.slice(pos))[0].trim()
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
           tokenStream.tokens.push({
62
           tokenStream.tokens.push({
63
             type: tokenTypes.KEYWORD,
63
             type: tokenTypes.KEYWORD,
64
             line: line,
64
             line: line,

+ 3
- 3
src/parser.js View File

77
   keyword() {
77
   keyword() {
78
     const keyword = this.tokenStream.eat(tokenTypes.KEYWORD)
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
       const symbol = this.tokenStream.eat(tokenTypes.SYMBOL)
82
       const symbol = this.tokenStream.eat(tokenTypes.SYMBOL)
82
       const body = this.expr()
83
       const body = this.expr()
83
-      const subject = this.identifier()
84
       return new Node({
84
       return new Node({
85
-        type: 'map',
85
+        type: 'each',
86
         symbol: symbol,
86
         symbol: symbol,
87
         body: body,
87
         body: body,
88
         subject: subject,
88
         subject: subject,

+ 1
- 1
test/compiler.js View File

49
   const lexer = new Lexer()
49
   const lexer = new Lexer()
50
   const tokenStream = lexer.scan(`
50
   const tokenStream = lexer.scan(`
51
     (ul
51
     (ul
52
-      (map 'item (li item) items))
52
+      (each items 'item (li item)))
53
   `)
53
   `)
54
   const parser = new Parser(tokenStream)
54
   const parser = new Parser(tokenStream)
55
   const tree = parser.parse()
55
   const tree = parser.parse()

Loading…
Cancel
Save