From: Michael D. Lowis Date: Thu, 30 Jan 2020 20:01:07 +0000 (-0500) Subject: added nillable types X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=231d8b76970ec79405455ef47edfafcd5ddf8177;p=proto%2Fsclpl-rb.git added nillable types --- diff --git a/compile.rb b/compile.rb index 2cbbd44..dc048bb 100755 --- a/compile.rb +++ b/compile.rb @@ -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 ####################################### diff --git a/example.src b/example.src index a0024b4..f8a72d1 100644 --- a/example.src +++ b/example.src @@ -1,7 +1,7 @@ module Main imports (X11, XSel, Posix) -#cmd : [String] = true +cmd : ?[String] = true fetchsel(sel : String) {