From e7a7a4025107c717221a1ef6ab823e26d4af6660 Mon Sep 17 00:00:00 2001 From: wires Date: Tue, 11 Mar 2025 22:59:16 -0400 Subject: [PATCH] reorganization for easier testing --- src/akhamoth.erl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/akhamoth.erl b/src/akhamoth.erl index 26dca55..53e946e 100644 --- a/src/akhamoth.erl +++ b/src/akhamoth.erl @@ -1,14 +1,17 @@ -module(akhamoth). --export([compile/1, collect/2]). +-export([compile_file/1, compile_binary/1, collect/2]). -compile(Path) -> - {ok, Src} = file:read_file(Path), - Lexer = akh_lexer:new(Src), - collect(Lexer, []). +compile_file(Path) -> + {ok, Source} = file:read_file(Path), + compile_binary(Source). -collect(Lexer, Acc) -> - case akh_lexer:next(Lexer) of +compile_binary(Source) -> + Lx = akh_lexer:new(Source), + collect(Lx, []). + +collect(Lx, Acc) -> + case akh_lexer:next(Lx) of none -> Acc; {ok, T, L} -> collect(L, [T | Acc]) end.