UNPKG

calcium-lang

Version:
43 lines (42 loc) 1.58 kB
import * as JSONElementType from "./jsonElement"; import * as Cmd from "../command"; import * as Expr from "../expression"; import * as Kw from "../keyword"; import Statement from "../runtime/statement"; /** * a default parser for Calcium language */ export default class Parser { readonly table: Map<Kw.Command, (stmt: Statement) => Cmd.Command>; /** * * @param table has default implementation when empty */ constructor(table?: Map<Kw.Command, (stmt: Statement) => Cmd.Command>); /** * used by `Call`. * @param args arguments given to a function * @returns converted objects that will be evaluated in runtime */ readArgs(args: JSONElementType.Any[]): Expr.Expression[]; /** * * @param stmt a JSON array that represents one line to execute * @returns a command object to be executed */ read(stmt: Statement): Cmd.Command; readBinOp(operator: string, expr: JSONElementType.BinaryOperation): Expr.BinaryOperation; /** * parse JSON element(s) and return `Expression`. * @param expr any JSON element * @returns an internal type or a reference */ readExpr(expr: JSONElementType.Any): Expr.Expression; /** * parse a reference array and return an reference object used in runtime. * @param expr a reference array such as `["var", "x"]` * @returns a reference object to be evaluated later */ readRef(expr: JSONElementType.Reference): Expr.Reference; readUnOp(operator: string, expr: JSONElementType.UnaryOperation): Expr.UnaryOperation; }