Defining the language
A Krikata language consists of a top level expression, which in turn consists of nested other expressions. Expressions have a certain Typescript type, which is what will be returned upon execution.
const greeting = new Type<string>("greeting");
greeting.setFunctions([
Constant("hi", () => `Hi mysterious person!`),
Func("hello")
.arg(primitives.string)
.setExec((value: string) => `Hello ${value}! It is a great day today!`),
]);
Let's deconstruct this:
- We construct a new Krikata
Type
namedgreeting
. - The Typescript type parameter of
greeting
isstring
. This means when running the program, this expression will evaluate to astring
. - We give
greeting
an array of functions:- The first function,
hi
, takes no arguments. When it is executed, it will return a constant string. - The second function,
hello
, takes one argument, a string. This is accomplished using theprimitives.string
expression, which evaluates to a TypeScript string. This value will be passed to the function's executor, and it is used to customise the string that is returned.
- The first function,