UNPKG

@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

37 lines (31 loc) 1.38 kB
import Visitor from "."; import { ASTNode } from "bhai-lang-parser"; import InterpreterModule from "../../module/interpreterModule"; import Scope from "../scope"; export default class IfStatement implements Visitor { visitNode(node: ASTNode) { const test = node.test; const parentScope = InterpreterModule.getCurrentScope(); if (test) { const testResult = InterpreterModule.getVisitor(test.type).visitNode(test); if (testResult === true || testResult === "sahi") { const consequent = node.consequent; if (consequent) { InterpreterModule.setCurrentScope(new Scope(parentScope)); InterpreterModule.getCurrentScope().setLoop(parentScope.isLoop()); InterpreterModule.getVisitor(consequent.type).visitNode(consequent); } } else { const alternate = node.alternate; if (alternate) { InterpreterModule.setCurrentScope(new Scope(parentScope)); InterpreterModule.getCurrentScope().setLoop(parentScope.isLoop()); InterpreterModule.getVisitor(alternate.type).visitNode(alternate); } } } parentScope.setBreakStatement(InterpreterModule.getCurrentScope().isBreakStatement()); parentScope.setContinueStatement(InterpreterModule.getCurrentScope().isContinueStatement()); InterpreterModule.setCurrentScope(parentScope); } }