@adamsy/bhai-lang
Version:
<h1 align="center">Bhai Lang</h1> <p align="center"> <a href="https://lgtm.com/projects/g/DulLabs/bhai-lang/alerts/"><img alt="Total alerts" src="https://img.shields.io/lgtm/alerts/g/DulLabs/bhai-lang.svg?logo=lgtm&logoWidth=18"/></a> <a href="https://lgt
29 lines (24 loc) • 864 B
text/typescript
import Visitor from ".";
import { ASTNode } from "bhai-lang-parser";
import InvalidStateException from "../../exceptions/invalidStateException";
import InterpreterModule from "../../module/interpreterModule";
export default class PrintStatement implements Visitor {
visitNode(node: ASTNode) {
if (!node.expressions)
throw new InvalidStateException(
`No expressions to print: ${node.expressions}`
);
const value = node.expressions
.map((expression: ASTNode) => {
let currentNodeOutput = InterpreterModule.getVisitor(expression.type).visitNode(expression);
if (currentNodeOutput === true)
currentNodeOutput = "sahi";
else if (currentNodeOutput === false)
currentNodeOutput = "galat";
return currentNodeOutput;
}
)
.join(" ");
console.log(value);
}
}