-
Notifications
You must be signed in to change notification settings - Fork 11
/
if.es6
55 lines (46 loc) 路 1.54 KB
/
if.es6
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
import CheddarExpressionToken from './expr';
import CheddarCodeblock from '../patterns/block';
import CheddarLexer from '../patterns/EXPLICIT';
export default class StatementIf extends CheddarLexer {
exec() {
this.open();
let FORMAT = [CheddarExpressionToken, CheddarCodeblock];
let IF = this.grammar(true, ['if', ...FORMAT]);
let OUT;
if (!IF instanceof CheddarLexer)
return IF;
console.log("A", this);
while (this.lookAhead("else")) {
console.log("B");
this.jumpLiteral("else");
if (this.lookAhead("if")) {
console.log("C");
// else if
this.jumpLiteral("if");
this.newToken("elif");
this.jumpWhite();
console.log("D");
OUT = this.grammar(true, FORMAT);
console.log("E");
} else {
// else
console.log("F");
this.newToken("else");
this.jumpWhite();
console.log("G");
OUT = this.attempt(CheddarCodeblock);
console.log("H");
this.Index = OUT.Index;
if (OUT instanceof CheddarLexer)
this.Tokens = OUT;
console.log("I");
}
console.log("J");
if (!(OUT instanceof CheddarLexer))
return OUT;
console.log("K");
this.jumpWhite();
}
console.log("DONE");
}
}