@isl-lang/typechecker
v1.0.0
Published
Semantic analyzer for ISL - validates AST, resolves types, builds symbol table
Maintainers
Readme
@isl-lang/typechecker
Semantic analyzer for ISL - validates AST, resolves types, and builds symbol tables.
Installation
npm install @isl-lang/typechecker
# or
pnpm add @isl-lang/typecheckerUsage
import { parse } from '@isl-lang/parser';
import { typecheck, TypeChecker } from '@isl-lang/typechecker';
const ast = parse(`
domain UserManagement {
type User {
id: uuid
name: string
email: email
}
intent CreateUser {
input { name: string, email: email }
output { user: User }
}
}
`);
// Quick validation
const result = typecheck(ast);
if (result.errors.length > 0) {
result.errors.forEach(err => console.error(err.message));
} else {
console.log('Type checking passed!');
console.log('Symbol table:', result.symbolTable);
}
// Or use the TypeChecker class for more control
const checker = new TypeChecker();
const checked = checker.check(ast);API
typecheck(ast: AST): TypeCheckResult
Perform type checking on an AST.
Returns:
errors- Array of type errors foundwarnings- Array of type warningssymbolTable- Resolved symbol tabletypeMap- Map of nodes to their resolved types
TypeChecker
Class for incremental type checking with caching.
const checker = new TypeChecker();
// Check multiple files
checker.addFile('user.isl', userAst);
checker.addFile('order.isl', orderAst);
// Get all errors
const errors = checker.getAllErrors();
// Get type for a specific node
const type = checker.getType(node);Features
- Type inference - Infers types for expressions
- Contract validation - Validates pre/postconditions
- Cross-reference resolution - Resolves type references across domains
- Import validation - Validates imports and exports
- Incremental checking - Efficient re-checking of modified files
Error Types
import { TypeError, TypeErrorCode } from '@isl-lang/typechecker';
// Error codes
TypeErrorCode.UNDEFINED_TYPE
TypeErrorCode.TYPE_MISMATCH
TypeErrorCode.DUPLICATE_DEFINITION
TypeErrorCode.INVALID_CONTRACTDocumentation
Full documentation: https://isl-lang.dev/docs/typechecker
Related Packages
- @isl-lang/parser - ISL parser
- @isl-lang/evaluator - Expression evaluator
License
MIT
