krl-compiler

raw JSON →
1.3.0 verified Fri May 01 auth: no javascript maintenance

The krl-compiler package (v1.3.0, stable, low release cadence) is a compiler that converts KRL (Kinetic Rule Language, used in the Pico Labs ecosystem) to JavaScript. It supports both programmatic API and CLI usage. Key differentiators: synchronous compilation, optional AST input, inline source maps, and a --verify flag for validation. Unlike general-purpose compilers, it is specialized for KRL rulesets targeting the pico-engine runtime.

error TypeError: compile is not a function
cause Importing the module incorrectly (e.g., treating as named export).
fix
Use default import: import compile from 'krl-compiler' or const compile = require('krl-compiler').
error Cannot find module 'krl-compiler'
cause Package not installed or incorrect version resolution.
fix
Run npm install krl-compiler and ensure it's in node_modules.
error Unexpected token: keyword 'ruleset'
cause Invalid KRL syntax passed to compile.
fix
Validate KRL code before compilation; use --verify flag for CLI.
gotcha The compile function throws synchronous errors for invalid KRL input.
fix Wrap calls in try/catch blocks.
deprecated The --no-source-map option is deprecated in favor of --no-inline-source-map.
fix Use --no-inline-source-map instead.
breaking As of v1.0.0, the module is ESM-only; require() is not supported.
fix Use import or switch to dynamic import().
gotcha CLI output includes an inline source map by default, which may bloat the output.
fix Use --no-source-map to omit it.
npm install krl-compiler
yarn add krl-compiler
pnpm add krl-compiler

Demonstrates basic programmatic usage: importing the compiler and converting KRL source to JavaScript.

const compile = require('krl-compiler');

const krlCode = `
  ruleset a8x138 {
    meta {
      name "Hello World"
      description "A simple KRL ruleset"
      author "Pico Labs"
    }
    rule hello {
      select when echo hello
      send_directive("say") with
        something = "Hello World";
    }
  }
`;

try {
  const jsCode = compile(krlCode);
  console.log(jsCode);
} catch (err) {
  console.error('Compilation failed:', err.message);
}