]> git.mdlowis.com Git - proto/sclpl-rb.git/commitdiff
added parsing of referenced modules
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Feb 2020 03:05:22 +0000 (22:05 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Feb 2020 03:05:22 +0000 (22:05 -0500)
compile.rb

index 238053012783b912a2dd74be14f8f2f0c62d22c8..3cde1ed6e99d6a43152e7cebad74c91540ecf635 100755 (executable)
@@ -54,6 +54,8 @@ BuiltinSyms = {
   },
 }
 
+Modules = {}
+
 class Symtable
   def initialize
     @builtins = BuiltinSyms
@@ -204,7 +206,7 @@ class Parser
     @imports
   end
 
-  def definitions()
+  def definitions(api_only = false)
     while !matches(:eof)
       sym = {
         export: accept("$"),
@@ -220,6 +222,9 @@ class Parser
       else
         error("invalid symbol definition")
       end
+      if api_only && sym[:export] then
+        sym[:value] = nil
+      end
       @symbols[sym[:name]] = sym
     end
     @symbols
@@ -563,21 +568,26 @@ class Parser
 end
 
 class Package
-  def initialize(path)
+  attr_accessor :name, :definitions
+
+  def initialize(path, api_only = false)
     @name = nil
     @imports = {}
     @declares = {}
     @definitions = {}
-    add_file(path)
+    add_file(path, api_only)
     type_check
   end
 
-  def add_file(path)
+  def add_file(path, api_only = false)
     parse = Parser.new(path)
     @name = parse.module()
     @imports = parse.imports()
-p @imports
-    @definitions = parse.definitions()
+    @imports.each do |m|
+      pkg = Package.new("lib/#{m.downcase}.m", api_only = true)
+      Modules[pkg.name] = pkg.definitions()
+    end
+    @definitions = parse.definitions(api_only)
   end
 
   def dump
@@ -593,4 +603,5 @@ p @imports
 end
 
 pkg = Package.new("lib/main.m")
+#pp Modules
 #pkg.dump()