@isl-lang/parser
ISL parser - transforms ISL (Intent Specification Language) source code into an Abstract Syntax Tree.
Installation
npm install @isl-lang/parser
pnpm add @isl-lang/parser
yarn add @isl-lang/parser
Usage
import { parse, parseFile } from '@isl-lang/parser';
const ast = parse(`
domain UserManagement {
intent CreateUser {
input {
name: string
email: email
}
output {
id: uuid
createdAt: timestamp
}
preconditions {
name.length > 0
email.isValid()
}
postconditions {
result.id != null
}
}
}
`);
const astFromFile = parseFile('./specs/user.isl');
API
parse(source: string, options?: ParseOptions): AST
Parse ISL source code into an AST.
Parameters:
source - ISL source code string
options - Optional parsing configuration
filename - Source filename for error messages
startRule - Starting grammar rule (default: 'program')
Returns: Abstract Syntax Tree
parseFile(path: string, options?: ParseOptions): AST
Parse an ISL file from the filesystem.
Parameters:
path - Path to the ISL file
options - Optional parsing configuration
Returns: Abstract Syntax Tree
tokenize(source: string): Token[]
Tokenize ISL source code into a stream of tokens.
AST Node Types
The parser produces nodes conforming to the ISL AST specification:
Program - Root node containing all declarations
Domain - Domain definition with intents and types
Intent - Intent definition with I/O and contracts
Type - Type definitions (entity, value, enum)
Expression - Contract expressions
Error Handling
import { parse, ParseError } from '@isl-lang/parser';
try {
const ast = parse(source);
} catch (error) {
if (error instanceof ParseError) {
console.error(`Parse error at ${error.location}:`);
console.error(error.message);
}
}
Documentation
Full documentation: https://isl-lang.dev/docs/parser
Related Packages
License
MIT