MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / parse

Method parse

www/js/_hyperscript.esm.js:7025–7048  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

7023 this.args = { value: expr };
7024 }
7025 static parse(parser) {
7026 if (!parser.matchToken("if")) return;
7027 var expr = parser.requireElement("expression");
7028 parser.matchToken("then");
7029 var trueBranch = parser.parseElement("commandList");
7030 var nestedIfStmt = false;
7031 let elseToken = parser.matchToken("else") || parser.matchToken("otherwise");
7032 if (elseToken) {
7033 let elseIfIfToken = parser.peekToken("if");
7034 nestedIfStmt = elseIfIfToken != null && elseIfIfToken.line === elseToken.line;
7035 if (nestedIfStmt) {
7036 var falseBranch = parser.parseElement("command");
7037 } else {
7038 var falseBranch = parser.parseElement("commandList");
7039 }
7040 }
7041 if (parser.hasMore() && !nestedIfStmt) {
7042 parser.requireToken("end");
7043 }
7044 var ifCmd = new _IfCommand(expr, trueBranch, falseBranch);
7045 parser.setParent(trueBranch, ifCmd);
7046 parser.setParent(falseBranch, ifCmd);
7047 return ifCmd;
7048 }
7049 resolve(context, { value: exprValue }) {
7050 if (exprValue) {
7051 return this.trueBranch;

Callers

nothing calls this directly

Calls 7

matchTokenMethod · 0.45
requireElementMethod · 0.45
parseElementMethod · 0.45
peekTokenMethod · 0.45
hasMoreMethod · 0.45
requireTokenMethod · 0.45
setParentMethod · 0.45

Tested by

no test coverage detected