tokiwa-software / fuzion

The Fuzion Language Implementation
https://fuzion-lang.dev
GNU General Public License v3.0
47 stars 11 forks source link

`codepoint` should inherit `has_interval` #2288

Open fridis opened 11 months ago

fridis commented 11 months ago

This used to be part of #2285: Since ranges of codepoints are frequently needed as in codepoint.type.ascii_digits, it might make sense to have codepoint inherit has_interval. But then,has_interval should no longer inherit integer. Needs to be analyzed how this can be done best.

maxteufel commented 8 months ago

what if we made codepoint an integer?

michaellilltokiwa commented 7 months ago

@maxteufel great idea.

currently still a bit painful though:

diff --git a/lib/codepoint.fz b/lib/codepoint.fz
index 9108dc978..fc657d2d0 100644
--- a/lib/codepoint.fz
+++ b/lib/codepoint.fz
@@ -25,7 +25,7 @@

 # codepoint -- represents a unicode codepoint
 #
-public codepoint(public val u32) : String
+public codepoint(public val u32) : integer, String
   pre
     debug: (codepoint.range.contains val)
     debug: !codepoint.utf16_surrogate.contains val
@@ -135,3 +135,16 @@ is
   # This defines a total order over strings that is unrelated to alphabetic order.
   #
   fixed type.lteq(a, b codepoint) => a.val <= b.val
+
+
+  /* NYI: select mechanism missing to choose inheritance from String instead of integer */
+  public redef infix * (n i32) String.infix * => panic "NYI"
+  public redef element_of(s container.Set String) bool => panic "NYI"
+  public redef infix ∈ (s container.Set String) => panic "NYI"
+  public redef not_element_of(s container.Set String) => panic "NYI"
+  public redef infix ∉ (s container.Set String) => panic "NYI"
+  public redef infix + (other Any) String => String.concat codepoint.this other.as_string
+
+  public redef as_string =>
+    ref : String
+      utf8 Sequence u8 => codepoint.this.utf8