36 lines
843 B
TypeScript
36 lines
843 B
TypeScript
import peggyParser from "./PeggyParser.js";
|
|
|
|
export type Application = {
|
|
application: {
|
|
left: LambdaTerm;
|
|
args: Array<LambdaTerm>;
|
|
};
|
|
};
|
|
|
|
export type Abstraction = {
|
|
abstraction: {
|
|
param: Variable;
|
|
body: LambdaTerm;
|
|
};
|
|
};
|
|
|
|
export type Variable = string;
|
|
|
|
export type LambdaTerm = Application | Abstraction | Variable;
|
|
|
|
export const isApplication = (term: LambdaTerm): term is Application => {
|
|
return (term as Application).application !== undefined;
|
|
};
|
|
|
|
export const isAbstraction = (term: LambdaTerm): term is Abstraction => {
|
|
return (term as Abstraction).abstraction !== undefined;
|
|
};
|
|
|
|
export const isVariable = (term: LambdaTerm): term is Variable => {
|
|
return typeof term === "string";
|
|
};
|
|
|
|
export const parse = (term: string, library = false) => {
|
|
return peggyParser.parse(term, { peg$library: library });
|
|
};
|