-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathkwnodewoke.js
39 lines (31 loc) · 1.23 KB
/
kwnodewoke.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
const constants = require("../../constants.js");
const BaseNode = require("../basenode.js");
const feedbackMessages = require("../../feedbackMessages.js");
class KwNodeWoke extends BaseNode {
getNode () {
if (KwNodeWoke.isExpectedWokeStatement(this)) {
return KwNodeWoke.getParsedWokeNode(this);
}
this.throwError(feedbackMessages.unexpectedDeclaration(constants.KW.WOKE));
}
static isExpectedWokeStatement (context) {
return context.getBlockTypeStack().includes(constants.KW.ISE);
}
static getParsedWokeNode (context) {
context.skipKeyword(constants.KW.WOKE);
const node = {};
node.operation = constants.KW.WOKE;
node.varNames = KwNodeWoke.getWokeVarNames(context);
context.skipPunctuation(constants.SYM.STATEMENT_TERMINATOR);
return node;
}
static getWokeVarNames (context) {
const varTokens = context.parseDelimited("`", "`", ",", context.getTokenThatSatisfiesPredicate.bind(context), (token) => token.type === constants.VARIABLE);
const varNames = [];
varTokens.map(varToken => {
varNames.push(varToken.value);
});
return varNames;
}
}
module.exports = new KwNodeWoke();