From 231d8b76970ec79405455ef47edfafcd5ddf8177 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 30 Jan 2020 15:01:07 -0500 Subject: [PATCH] added nillable types --- compile.rb | 10 +++++++++- example.src | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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) { -- 2.49.0