solutions/cw4/lexer.sc
changeset 961 c0600f8b6427
parent 959 64ec1884d860
--- a/solutions/cw4/lexer.sc	Wed May 29 13:25:30 2024 +0100
+++ b/solutions/cw4/lexer.sc	Thu Sep 19 15:47:33 2024 +0100
@@ -1,6 +1,8 @@
 // Lexer from CW2 with additions to the rules
 //============================================
 
+import scala.language.implicitConversions
+
 // Rexp
 abstract class Rexp
 case object ZERO extends Rexp
@@ -34,8 +36,9 @@
   case c::s => SEQ(CHAR(c), charlist2rexp(s))
 }
 
-implicit def string2rexp(s : String) : Rexp = 
-  charlist2rexp(s.toList)
+given Conversion[String, Rexp] = (s => charlist2rexp(s.toList))
+//implicit def string2rexp(s : String) : Rexp = 
+//  charlist2rexp(s.toList)
 
 extension (r: Rexp) {
   def | (s: Rexp) = ALT(r, s)
@@ -45,11 +48,11 @@
 
 extension (s: String) {
   def | (r: Rexp) = ALT(s, r)
-  def | (r: String) = ALT(s, r)
+  //def | (r: String) = ALT(s, r)
   def % = STAR(s)
   def ~ (r: Rexp) = SEQ(s, r)
-  def ~ (r: String) = SEQ(s, r)
-  def $ (r: Rexp) = RECD(s, r)
+  //def ~ (r: String) = SEQ(s, r)
+  infix def $ (r: Rexp) = RECD(s, r)
 }
 
 // nullable