-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathkwnodeyi.js
89 lines (71 loc) · 2.62 KB
/
kwnodeyi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const bracketExpressionNl = require("../nodeLiterals/bracketexpressionnl.js");
const feedbackMessages = require("../../feedbackMessages.js");
class KwNodeYi extends BaseNode {
constructor () {
super();
if (!(bracketExpressionNl instanceof BaseNode)) {
throw new Error(feedbackMessages.baseNodeType("Dependency bracketExpressionNl"));
}
}
getNode () {
const node = {};
node.operation = constants.KW.YI;
this.pushToBlockTypeStack(constants.KW.YI);
this.skipKeyword(constants.KW.YI);
node.yivalue = bracketExpressionNl.getNode.call(this);
this.skipPunctuation(constants.SYM.L_PAREN);
node.yibody = KwNodeYi.getYiBody(this);
node.padasi = KwNodeYi.getPadasi(this);
this.skipPunctuation(constants.SYM.R_PAREN);
this.popBlockTypeStack();
return node;
}
static getYiBody (context) {
const yiBody = []; const kwNodeIRU = new KwNodeIRU();
while (KwNodeYi.isNextTokenIru(context)) {
yiBody.push(kwNodeIRU.getNode.call(context));
}
return yiBody;
}
static isNextTokenIru (context) {
return context.isNotEndOfFile() && context.lexer().peek().value === constants.KW.IRU;
}
static getPadasi (context) {
const padasi = [];
if (context.isNextTokenKeyword(constants.KW.PADASI)) {
context.skipKeyword(constants.KW.PADASI);
context.skipPunctuation(constants.SYM.COLON);
while (context.isNotEndOfBlock()) {
padasi.push(context.parseAst());
}
}
return padasi;
}
}
class KwNodeIRU extends BaseNode {
getNode () {
const node = {};
node.operation = constants.KW.IRU;
this.skipKeyword(constants.KW.IRU);
node.IRUvalue = this.parseExpression();
this.skipPunctuation(constants.SYM.COLON);
node.IRUbody = KwNodeIRU.getIRUBody(this);
return node;
}
static getIRUBody (context) {
const IRUBody = [];
while (KwNodeIRU.canParseIRUStatements(context)) {
IRUBody.push(context.parseAst());
}
return IRUBody;
}
static canParseIRUStatements (context) {
return context.isNotEndOfFile() &&
context.lexer().peek().value !== constants.KW.IRU &&
context.lexer().peek().value !== constants.KW.PADASI &&
context.lexer().peek().value !== constants.SYM.R_PAREN;
}
}
module.exports = new KwNodeYi();