(input)
| 397 | |
| 398 | |
| 399 | constructor(input) { |
| 400 | super(input, allTokens, {}); |
| 401 | let self = this; |
| 402 | let asValue = (node) => { |
| 403 | if(node.type === "constant" || node.type === "variable" || node.type === "parenthesis") { |
| 404 | return node; |
| 405 | } else if(node.variable) { |
| 406 | return node.variable; |
| 407 | } |
| 408 | throw new Error("Tried to get value of a node that is neither a constant nor a variable.\n\n" + JSON.stringify(node)); |
| 409 | } |
| 410 | let ifOutputs = (expression) => { |
| 411 | let outputs = []; |
| 412 | if(expression.type === "parenthesis") { |
| 413 | for(let item of expression.items) { |
| 414 | outputs.push(asValue(item)); |
| 415 | } |
| 416 | } else { |
| 417 | outputs.push(asValue(expression)); |
| 418 | } |
| 419 | return outputs; |
| 420 | } |
| 421 | |
| 422 | let makeNode = (type, node) => { |
| 423 | return self.block.makeNode(type, node); |
| 424 | } |
| 425 | |
| 426 | let blockStack = []; |
| 427 | let pushBlock = (blockId?) => { |
| 428 | let block; |
| 429 | let prev = blockStack[blockStack.length - 1]; |
| 430 | if(prev) { |
| 431 | block = prev.subBlock(); |
| 432 | } else { |
| 433 | block = new ParseBlock(blockId || "block"); |
| 434 | } |
| 435 | blockStack.push(block); |
| 436 | self.block = block; |
| 437 | return block; |
| 438 | } |
| 439 | |
| 440 | let popBlock = () => { |
| 441 | let popped = blockStack.pop(); |
| 442 | self.block = blockStack[blockStack.length - 1]; |
| 443 | return popped; |
| 444 | } |
| 445 | |
| 446 | //----------------------------------------------------------- |
| 447 | // Doc rules |
| 448 | //----------------------------------------------------------- |
| 449 | |
| 450 | self.RULE("doc", () => { |
| 451 | let doc = { |
| 452 | full: [], |
| 453 | content: [], |
| 454 | blocks: [], |
| 455 | } |
| 456 | self.MANY(() => { |
nothing calls this directly
no test coverage detected