]> git.mdlowis.com Git - proto/cerise-c.git/commitdiff
added imports and exports
authorMike Lowis <mike.lowis@gentex.com>
Fri, 18 Oct 2024 19:24:29 +0000 (15:24 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Fri, 18 Oct 2024 19:24:29 +0000 (15:24 -0400)
cerise-c.m
lib/lexer.rb
lib/parser.rb

index f2eb820637363988163bba05ce4d310be4b819a4..0337271065d6c04c6c2eff5055f431bed4fd62c4 100644 (file)
@@ -1,5 +1,11 @@
 module TestSuite
 
+imports (
+    "foo/bar/baz"
+)
+
+exports (Main)
+
 TestLiterals()
 {
 #    assert 42
index bf101c9e24fb21ffa340499850422227c1de6acc..edd375e091218067b578e856ee13b38033783f0a 100644 (file)
@@ -40,7 +40,9 @@ class Lexer
     "set"    => :set,
     "return" => :return,
     "assert" => :assert,
-    "module" => :module
+    "module" => :module,
+    "imports" => :imports,
+    "exports" => :exports
   }
 
   def next
index 146370b80aa5a798d2112f58fa6b2f9ff1835a6f..3935db99382c7c7fc9d5acc7c1a1a3b58f829027 100644 (file)
@@ -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