A static analysis tool that traverses the AST
to perform semantic checks, validation, scope resolution, and error detection.
-
npm install @je-es/ast-analyzer
import { Analyzer } from "@je-es/ast-analyzer";
-
// suppose we want to analyze the represented AST for this statement: pub let mut x: i32 = 42
// [1] Create syntax const syntax = Syntax.create({ // :: using @je-es/syntax(parser/lexer) name : 'Kemet', version : '0.0.1', lexer : lexerRules, parser : parserRules, settings : parserSettings } as syntax.SyntaxConfig ); // [2] Parsing the input const parser_result = syntax.parse('pub let mut x: i32 = 42'); // [3] Create module using the parser result const main_module = AST.Module.create( // :: using @je-es/ast // Name 'main', // Statements parser_result.ast.length > 0 // in my case, first item refers to an array of stmts. ? parser_result.ast[0].getCustomData()! as AST.StmtNode[] // otherwise, empty module. : [], // Metadata { path: './src/main.k' } ); // [4] Create program with the created module const program = AST.Program.create([main_module], { entryModule: 'main', path: './' }); // [5] Create analyzer for the created program const analyzer = Analyzer.create({ debug: 'off' }); const analyzer_result = analyzer.analyze(program);
-
-
1. @je-es/lexer
3. @je-es/ast
8. @je-es/lsp
-

