The full module for Kipper, which contains the core language, compiler and command line interface (CLI).
Kipper is a simple strongly and statically typed programming language, which is designed to allow for straightforward, simple, secure and type-safe coding similar to TypeScript, Rust and Python! 🦊
- Full type safety to ensure errors occur on compile time, not runtime.
- Runtime types and type checking, which allow variable types to be checked during runtime, if
their type can not be evaluated during compile time. For example when using
JSON.parse()
. - Runtime errors for invalid operations. No hidden errors like in JavaScript.
- Null safety, by enforcing non-null types unless explicitly allowed.
- Full translation and integration with TypeScript.
Kipper is still in an early development phase, as such not all features shown in the snippet are implemented yet.
These are the child packages that are shipped with this bundle of Kipper:
@kipper/core
: The Kipper compiler for the browser and Node.js! 🦊@kipper/cli
: The Kipper command line interface (CLI) to interact with the Kipper compiler! 🦊
Proper documentation for the Kipper language is available here!
To use Kipper you have three options:
- Run it in the browser using the CDN
kipper-standalone.min.js
file, which bundles the entire compiler for your browser. - Run it using the NodeJS CLI
@kipper/cli
. - Import the package
@kipper/core
in NodeJS or Deno.
For running Kipper in the browser, you will have to include the kipper-standalone.min.js
file, which
provides the kipper compiler for the browser.
As a dependency you will also have to include babel.min.js
, which is needed to allow for a compilation
from TS to JS in your browser, as Kipper compiles only to TypeScript.
Simple example of running your code in your browser using Kipper and Babel:
<!-- Babel dependency -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<!-- Kipper dependency -->
<script src="https://cdn.jsdelivr.net/npm/@kipper/core@latest/kipper-standalone.min.js"></script>
<!-- You won't have to define Kipper or anything after including the previous file. It will be defined per default -->
<!-- with the global 'Kipper' -->
<script type="module">
// Define your own logger and compiler, which will handle the compilation
const logger = new Kipper.KipperLogger((level, msg) => {
console.log(`[${Kipper.getLogLevelString(level)}] ${msg}`);
});
// Define your own compiler with your wanted configuration
const compiler = new Kipper.KipperCompiler(logger);
// Compile the code to Typescript
// Top-level await ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await#top_level_await
const result = (await compiler.compile(`call print("Hello world!");`)).write();
// Transpile the TS code into JS
const jsCode = Babel.transform(result, { filename: "kipper-web-script.ts", presets: ["env", "typescript"] });
// Finally, run your program
eval(jsCode.code);
</script>
This is to recommend way to use Kipper if you want to dive deeper into Kipper, as it allows you to locally use and run kipper, without depending on a browser.
For example:
- Compiling a Kipper program:
kipper compile file.kip
- Executing a Kipper program using Node.js:
kipper run file.kip
This also enables the usage of Kipper files with the .kip
extension, which can be read and compiled to TypeScript,
without having to configure anything yourself. This also allows the input of data over the
console and file-interactions, which are not supported inside a browser.
For more info go to the @kipper/cli
README.
This is the recommended way if you intend to use kipper in a workflow or write code yourself to manage the compiler. This also allows for special handling of logging and customising the compilation process.
Simple example of using kipper using Node.js:
import * as ts from "typescript";
import { promises as fs } from "fs";
import * as Kipper from "@kipper/core";
const path = "INSERT_PATH";
fs.readFile(path, "utf8" as BufferEncoding).then(async (fileContent: string) => {
// Define your own logger and compiler, which will handle the compilation
const logger = new Kipper.KipperLogger((level, msg) => {
console.log(`[${level}] ${msg}`);
});
const compiler = new Kipper.KipperCompiler(logger);
// Compile the code string or stream
let result = await compiler.compile(fileContent, {
/* Config */
});
let tsCode = result.write();
// Compiling down to JS using the typescript node module
let jsCode = ts.transpile(tsCode);
// Running the Kipper program
eval(jsCode);
});
If you want to contribute to Kipper, we have a full guide explaining the structure of Kipper and how to use GitHub issues and pull requests. Check it out here!
If you have any questions or concerns, you can open up a discussion page here!
Copyright (C) 2021-2022 Luna Klatzer
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
See the LICENSE for information on terms & conditions for usage.