|
@@ -17,32 +17,36 @@ module.exports = class Parser {
|
17
|
17
|
expr() {
|
18
|
18
|
this.tokenStream.eat(tokenTypes.OPAREN)
|
19
|
19
|
|
20
|
|
- let elementNode = new Node()
|
21
|
|
- elementNode.type = 'functionCall'
|
22
|
|
- elementNode.functionName = this.tokenStream.eat(tokenTypes.LITERAL).value
|
23
|
|
- elementNode.args = []
|
24
|
|
- elementNode.subtree = []
|
|
20
|
+ let node = new Node()
|
|
21
|
+
|
|
22
|
+ if (this.tokenStream.peek().type === tokenTypes.LITERAL) {
|
|
23
|
+ node.type = 'functionCall'
|
|
24
|
+ node.functionName = this.tokenStream.eat(tokenTypes.LITERAL).value
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ node.args = []
|
|
28
|
+ node.subtree = []
|
25
|
29
|
|
26
|
30
|
while (
|
27
|
31
|
this.tokenStream.peek().type != tokenTypes.CPAREN &&
|
28
|
32
|
this.tokenStream.peek().type !== tokenTypes.EOF
|
29
|
33
|
) {
|
30
|
34
|
if (this.tokenStream.peek().type === tokenTypes.ATTRIBUTE) {
|
31
|
|
- elementNode.args.push(this.attribute())
|
|
35
|
+ node.args.push(this.attribute())
|
32
|
36
|
} else if (this.tokenStream.peek().type === tokenTypes.OPAREN) {
|
33
|
|
- elementNode.subtree.push(this.expr())
|
|
37
|
+ node.subtree.push(this.expr())
|
34
|
38
|
} else if (this.tokenStream.peek().type === tokenTypes.LITERAL) {
|
35
|
|
- elementNode.subtree.push(this.identifier())
|
|
39
|
+ node.subtree.push(this.identifier())
|
36
|
40
|
} else if (this.tokenStream.peek().type === tokenTypes.QUOTE) {
|
37
|
|
- elementNode.subtree.push(this.quotedString())
|
|
41
|
+ node.subtree.push(this.quotedString())
|
38
|
42
|
} else if (this.tokenStream.peek().type === tokenTypes.KEYWORD) {
|
39
|
|
- elementNode.subtree.push(this.keyword())
|
|
43
|
+ node = this.keyword()
|
40
|
44
|
}
|
41
|
45
|
}
|
42
|
46
|
|
43
|
47
|
this.tokenStream.eat(tokenTypes.CPAREN)
|
44
|
48
|
|
45
|
|
- return elementNode
|
|
49
|
+ return node
|
46
|
50
|
}
|
47
|
51
|
|
48
|
52
|
attribute() {
|