]> git.mdlowis.com Git - proto/sclpl-rb.git/commitdiff
added nillable types
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 30 Jan 2020 20:01:07 +0000 (15:01 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 30 Jan 2020 20:01:07 +0000 (15:01 -0500)
compile.rb
example.src

index 2cbbd44adec928e8bf087e2214cb0fe4ee0446c6..dc048bb988b03b0a404138d1f19a932eb16ede8a 100755 (executable)
@@ -11,6 +11,7 @@ module Type
   Ptr = Struct.new(:type)
   Int = Struct.new(:min, :max)
   Float = Struct.new(:bits)
+  Nilable = Struct.new(:type)
 end
 
 module Ast
@@ -59,7 +60,7 @@ class Lexer
   SPACE = /([ \t\v\n\r]+|#.*\n)/
   IDENT = /[_a-zA-Z][_a-zA-Z0-9]*/
   BRACES = /[\(\)\[\]\{\}\.]/
-  OPERATORS = /[*\/=+-:\$]/
+  OPERATORS = /[*\/=+-:\$?]/
   INTEGER = /[0-9]+/
   STRING = /"(\\"|[^"])*"/
   ID_TYPES = {
@@ -207,6 +208,8 @@ class Parser
       struct_type()
     elsif matches("*")
       pointer_type()
+    elsif matches("?")
+      nilable_type()
 #    elsif matches(:func)
 #      func_type()
     else
@@ -242,6 +245,11 @@ class Parser
     Type::Ptr.new(type_specifier())
   end
 
+  def nilable_type()
+    expect("?")
+    Type::Nilable.new(type_specifier())
+  end
+
   #######################################
   # Variable Definitions
   #######################################
index a0024b49747f4d9c3f60dc1752a79a84cc070ded..f8a72d177d2fa777bb04d0cee6094e905ff51020 100644 (file)
@@ -1,7 +1,7 @@
 module Main
 imports (X11, XSel, Posix)
 
-#cmd : [String] = true
+cmd : ?[String] = true
 
 fetchsel(sel : String)
 {