ISL (Intent Specification Language) recursive descent parser - transforms ISL source into AST
npm install @isl-lang/parserbash
npm install @isl-lang/parser
or
pnpm add @isl-lang/parser
or
yarn add @isl-lang/parser
`
Usage
`typescript
import { parse, parseFile } from '@isl-lang/parser';
// Parse ISL source code
const ast = parse(
);
// Parse from file
const astFromFile = parseFile('./specs/user.isl');
`
API
$3
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
$3
Parse an ISL file from the filesystem.
Parameters:
- path - Path to the ISL file
- options - Optional parsing configuration
Returns: Abstract Syntax Tree
$3
Tokenize ISL source code into a stream of tokens.
$3
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
`typescript
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);
}
}
``