clarified signature: more explicit types;
authorwenzelm
Fri, 13 Jan 2023 17:14:59 +0100
changeset 76965 922df6aa1607
parent 76964 c044306db39f
child 76966 2f91b787f509
clarified signature: more explicit types;
src/Pure/General/completion.scala
src/Pure/PIDE/markup.scala
src/Pure/PIDE/rendering.scala
src/Pure/Tools/update.scala
--- a/src/Pure/General/completion.scala	Fri Jan 13 15:57:11 2023 +0100
+++ b/src/Pure/General/completion.scala	Fri Jan 13 17:14:59 2023 +0100
@@ -230,6 +230,9 @@
     val ML_outer = Language_Context(Markup.Language.ML, false, true)
     val ML_inner = Language_Context(Markup.Language.ML, true, false)
     val SML_outer = Language_Context(Markup.Language.SML, false, false)
+
+    def apply(lang: Markup.Language.Value): Language_Context =
+      Language_Context(lang.name, lang.symbols, lang.antiquotes)
   }
 
   sealed case class Language_Context(language: String, symbols: Boolean, antiquotes: Boolean) {
--- a/src/Pure/PIDE/markup.scala	Fri Jan 13 15:57:11 2023 +0100
+++ b/src/Pure/PIDE/markup.scala	Fri Jan 13 17:14:59 2023 +0100
@@ -193,24 +193,21 @@
     val PATH = "path"
     val UNKNOWN = "unknown"
 
-    def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
+    sealed case class Value(name: String, symbols: Boolean, antiquotes: Boolean, delimited: Boolean) {
+      def is_path: Boolean = name == PATH
+      def description: String = Word.implode(Word.explode('_', name))
+    }
+
+    def unapply(markup: Markup): Option[Value] =
       markup match {
         case Markup(LANGUAGE, props) =>
           (props, props, props, props) match {
             case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
-              Some((name, symbols, antiquotes, delimited))
+              Some(Value(name, symbols, antiquotes, delimited))
             case _ => None
           }
         case _ => None
       }
-
-    object Path {
-      def unapply(markup: Markup): Option[Boolean] =
-        markup match {
-          case Language(PATH, _, _, delimited) => Some(delimited)
-          case _ => None
-        }
-    }
   }
 
 
--- a/src/Pure/PIDE/rendering.scala	Fri Jan 13 15:57:11 2023 +0100
+++ b/src/Pure/PIDE/rendering.scala	Fri Jan 13 17:14:59 2023 +0100
@@ -311,9 +311,8 @@
   def language_context(range: Text.Range): Option[Completion.Language_Context] =
     snapshot.select(range, Rendering.language_context_elements, _ =>
       {
-        case Text.Info(_, XML.Elem(Markup.Language(language, symbols, antiquotes, delimited), _)) =>
-          if (delimited) Some(Completion.Language_Context(language, symbols, antiquotes))
-          else None
+        case Text.Info(_, XML.Elem(Markup.Language(lang), _)) =>
+          if (lang.delimited) Some(Completion.Language_Context(lang)) else None
         case Text.Info(_, elem)
         if elem.name == Markup.ML_STRING || elem.name == Markup.ML_COMMENT =>
           Some(Completion.Language_Context.ML_inner)
@@ -335,8 +334,8 @@
   def language_path(range: Text.Range): Option[Text.Info[Boolean]] =
     snapshot.select(range, Rendering.language_elements, _ =>
       {
-        case Text.Info(info_range, XML.Elem(Markup.Language.Path(delimited), _)) =>
-          Some((delimited, snapshot.convert(info_range)))
+        case Text.Info(info_range, XML.Elem(Markup.Language(lang), _)) if lang.is_path =>
+          Some((lang.delimited, snapshot.convert(info_range)))
         case _ => None
       }).headOption.map({ case Text.Info(_, (delimited, range)) => Text.Info(range, delimited) })
 
@@ -672,9 +671,8 @@
                 if (session.debugger.breakpoint_state(breakpoint)) "breakpoint (enabled)"
                 else "breakpoint (disabled)"
               Some(info + (r0, true, XML.Text(text)))
-          case (info, Text.Info(r0, XML.Elem(Markup.Language(language, _, _, _), _))) =>
-            val lang = Word.implode(Word.explode('_', language))
-            Some(info + (r0, true, XML.Text("language: " + lang)))
+          case (info, Text.Info(r0, XML.Elem(Markup.Language(lang), _))) =>
+            Some(info + (r0, true, XML.Text("language: " + lang.description)))
 
           case (info, Text.Info(r0, XML.Elem(Markup.Expression(kind), _))) =>
             val descr = if (kind == "") "expression" else "expression: " + kind
--- a/src/Pure/Tools/update.scala	Fri Jan 13 15:57:11 2023 +0100
+++ b/src/Pure/Tools/update.scala	Fri Jan 13 17:14:59 2023 +0100
@@ -66,8 +66,8 @@
       xml flatMap {
         case XML.Wrapped_Elem(markup, body1, body2) =>
           if (markup.name == Markup.UPDATE) update_xml(body1) else update_xml(body2)
-        case XML.Elem(Markup.Language.Path(_), body)
-        if path_cartouches =>
+        case XML.Elem(Markup.Language(lang), body)
+        if lang.is_path && path_cartouches =>
           Token.read_embedded(Keyword.Keywords.empty, XML.content(body)) match {
             case Some(tok) => List(XML.Text(Symbol.cartouche(tok.content)))
             case None => update_xml(body)