@guardian-network/policy-compiler
v0.3.6
Published
Artifcts high level declaration language
Readme
Policy definition DSL (LacLang) compiler
DO NOT USE IN PRODUCTION.
This implementation is in early development. It has not been reviewed or audited. It is not suitable to be used in production. Expect bugs!
The package exposes programmatical compiler of LacLang sources. The resulting object can be used directely to initialize policy onchain.
LacLangCompiler class, exported from the src directory, represents the LacLang compiler.
The instance of the compiler can be constructed both from file (path provided) or from sources (string provided).
const compiler = await LacLangCompiler.fromFile(lacSourcePath);const compiler = await LacLangCompiler.fromSources(lacSources);Also, compiler options can be provided. Compiler options are setting the type checking mode - whether it will be onchain or DSL declarations. If any of the type checking modes are selected, the JSON-RPC provider also must be defined. If neither were selected, types are not checked and the code is immediately translated.
interface LacLangCompilerOptions {
checkTypesAgainstOnchainDescriptors?: boolean;
checkTypesAgainstDslDeclarations?: boolean;
provider?: ContractRunner;
}The compilation results are obtained after invoking compile method on the preconfigured compiler:
const compilationResult = await compiler.compile();The resulting object can be immediately passed directely to the onchain policy handler.
await policyHandler.set(compilationResult);The compiler sequentially translates the DSL into IR, and then IR into final representation. FR is natively compatible with onchain policy handler.
