From 0cce3afb1032c8d5686e403544f3e7b6397f314c Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Fri, 18 Oct 2024 15:24:29 -0400 Subject: [PATCH] added imports and exports --- cerise-c.m | 6 ++++++ lib/lexer.rb | 4 +++- lib/parser.rb | 25 +++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cerise-c.m b/cerise-c.m index f2eb820..0337271 100644 --- a/cerise-c.m +++ b/cerise-c.m @@ -1,5 +1,11 @@ module TestSuite +imports ( + "foo/bar/baz" +) + +exports (Main) + TestLiterals() { # assert 42 diff --git a/lib/lexer.rb b/lib/lexer.rb index bf101c9..edd375e 100644 --- a/lib/lexer.rb +++ b/lib/lexer.rb @@ -40,7 +40,9 @@ class Lexer "set" => :set, "return" => :return, "assert" => :assert, - "module" => :module + "module" => :module, + "imports" => :imports, + "exports" => :exports } def next diff --git a/lib/parser.rb b/lib/parser.rb index 146370b..3935db9 100644 --- a/lib/parser.rb +++ b/lib/parser.rb @@ -144,11 +144,32 @@ class Parser end def imports - # TBD + if accept(:imports) + @imports = [] + expect("(") + while !matches(")") + @imports << module_path() + expect(",") if not matches(")") + end + expect(")") + end + end + + def module_path() + expect(:string).text.sub(/^"([^"]+)"$/,'\1') end def exports - # TBD + if accept(:exports) + @exports = [] + expect("(") + while !matches(")") + @exports << identifier().name + expect(",") if not matches(")") + end + expect(")") + pp @exports + end end def toplevel_defintion -- 2.52.0