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

34 lines (26 loc) 1.06 kB
import Visitor from "."; import { ASTNode } from "bhai-lang-parser"; import InterpreterModule from "../../module/interpreterModule"; import Scope from "../scope"; export default class BlockStatement implements Visitor { visitNode(node: ASTNode) { const parentScope = InterpreterModule.getCurrentScope(); InterpreterModule.setCurrentScope(new Scope(parentScope)); InterpreterModule.getCurrentScope().setLoop(parentScope.isLoop()); if (Array.isArray(node.body)) { node.body.every((statement: ASTNode) => { if (InterpreterModule.getCurrentScope().isBreakStatement()) { return false; } if (InterpreterModule.getCurrentScope().isContinueStatement()) { parentScope.setContinueStatement(true); return false; } InterpreterModule.getVisitor(statement.type).visitNode(statement); return true; }); } parentScope.setBreakStatement(InterpreterModule.getCurrentScope().isBreakStatement()); InterpreterModule.setCurrentScope(parentScope); } }