From fe26b6c2b371e1fb93ca7a71388a1d9e21360600 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Sat, 28 Feb 2026 18:59:37 +0300 Subject: [PATCH] scope_analysis & core_ast: added functions to convert directly from source for convenience --- lib/compiler/core_ast.ml | 6 ++++++ lib/compiler/scope_analysis.ml | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/compiler/core_ast.ml b/lib/compiler/core_ast.ml index 5a0e2e0..f72279e 100644 --- a/lib/compiler/core_ast.ml +++ b/lib/compiler/core_ast.ml @@ -1,4 +1,6 @@ +let traverse = Util.traverse + type literal = | Int of int | Double of float @@ -121,3 +123,7 @@ and of_syntactic : Syntactic_ast.top_level -> top_level = function let of_sexpr x = Result.bind (Syntactic_ast.make x) (fun x -> Ok (of_syntactic x)) + +let of_src src = + let sexprs = Parser.parse_str src in + traverse of_sexpr sexprs diff --git a/lib/compiler/scope_analysis.ml b/lib/compiler/scope_analysis.ml index b825aad..06daf7c 100644 --- a/lib/compiler/scope_analysis.ml +++ b/lib/compiler/scope_analysis.ml @@ -134,3 +134,7 @@ let convert program = let tbl = SymbolTable.add s (id ()) tbl in (analyze tbl [] e) :: (aux tbl rest) in traverse (fun x -> x) (aux SymbolTable.empty program) + +let of_src src = + let* core = (Core_ast.of_src src) in + convert core