src/Pure/PIDE/markup.scala
author wenzelm
Sun Oct 05 17:58:36 2014 +0200 (2014-10-05)
changeset 58545 30b75b7958d6
parent 58544 340f130b3d38
child 58853 f8715e7c1be6
permissions -rw-r--r--
citation tooltip/hyperlink based on open buffers with .bib files;
     1 /*  Title:      Pure/PIDE/markup.scala
     2     Module:     PIDE
     3     Author:     Makarius
     4 
     5 Quasi-abstract markup elements.
     6 */
     7 
     8 package isabelle
     9 
    10 
    11 object Markup
    12 {
    13   /* elements */
    14 
    15   object Elements
    16   {
    17     def apply(elems: Set[String]): Elements = new Elements(elems)
    18     def apply(elems: String*): Elements = apply(Set(elems: _*))
    19     val empty: Elements = apply()
    20     val full: Elements =
    21       new Elements(Set.empty)
    22       {
    23         override def apply(elem: String): Boolean = true
    24         override def toString: String = "Elements.full"
    25       }
    26   }
    27 
    28   sealed class Elements private[Markup](private val rep: Set[String])
    29   {
    30     def apply(elem: String): Boolean = rep.contains(elem)
    31     def + (elem: String): Elements = new Elements(rep + elem)
    32     def ++ (elems: Elements): Elements = new Elements(rep ++ elems.rep)
    33     override def toString: String = rep.mkString("Elements(", ",", ")")
    34   }
    35 
    36 
    37   /* properties */
    38 
    39   val NAME = "name"
    40   val Name = new Properties.String(NAME)
    41 
    42   val KIND = "kind"
    43   val Kind = new Properties.String(KIND)
    44 
    45   val INSTANCE = "instance"
    46   val Instance = new Properties.String(INSTANCE)
    47 
    48 
    49   /* basic markup */
    50 
    51   val Empty = Markup("", Nil)
    52   val Broken = Markup("broken", Nil)
    53 
    54   class Markup_String(val name: String, prop: String)
    55   {
    56     private val Prop = new Properties.String(prop)
    57 
    58     def apply(s: String): Markup = Markup(name, Prop(s))
    59     def unapply(markup: Markup): Option[String] =
    60       if (markup.name == name) Prop.unapply(markup.properties) else None
    61   }
    62 
    63   class Markup_Int(val name: String, prop: String)
    64   {
    65     private val Prop = new Properties.Int(prop)
    66 
    67     def apply(i: Int): Markup = Markup(name, Prop(i))
    68     def unapply(markup: Markup): Option[Int] =
    69       if (markup.name == name) Prop.unapply(markup.properties) else None
    70   }
    71 
    72 
    73   /* formal entities */
    74 
    75   val BINDING = "binding"
    76   val ENTITY = "entity"
    77   val DEF = "def"
    78   val REF = "ref"
    79 
    80   object Entity
    81   {
    82     def unapply(markup: Markup): Option[(String, String)] =
    83       markup match {
    84         case Markup(ENTITY, props) =>
    85           (props, props) match {
    86             case (Kind(kind), Name(name)) => Some((kind, name))
    87             case _ => None
    88           }
    89         case _ => None
    90       }
    91   }
    92 
    93 
    94   /* completion */
    95 
    96   val COMPLETION = "completion"
    97   val NO_COMPLETION = "no_completion"
    98 
    99 
   100   /* position */
   101 
   102   val LINE = "line"
   103   val OFFSET = "offset"
   104   val END_OFFSET = "end_offset"
   105   val FILE = "file"
   106   val ID = "id"
   107 
   108   val DEF_LINE = "def_line"
   109   val DEF_OFFSET = "def_offset"
   110   val DEF_END_OFFSET = "def_end_offset"
   111   val DEF_FILE = "def_file"
   112   val DEF_ID = "def_id"
   113 
   114   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
   115   val POSITION = "position"
   116 
   117 
   118   /* expression */
   119 
   120   val EXPRESSION = "expression"
   121 
   122 
   123   /* citation */
   124 
   125   val CITATION = "citation"
   126   val Citation = new Markup_String(CITATION, NAME)
   127 
   128 
   129   /* embedded languages */
   130 
   131   val Symbols = new Properties.Boolean("symbols")
   132   val Antiquotes = new Properties.Boolean("antiquotes")
   133   val Delimited = new Properties.Boolean("delimited")
   134 
   135   val LANGUAGE = "language"
   136   object Language
   137   {
   138     val ML = "ML"
   139     val SML = "SML"
   140     val PATH = "path"
   141     val UNKNOWN = "unknown"
   142 
   143     def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
   144       markup match {
   145         case Markup(LANGUAGE, props) =>
   146           (props, props, props, props) match {
   147             case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
   148               Some((name, symbols, antiquotes, delimited))
   149             case _ => None
   150           }
   151         case _ => None
   152       }
   153   }
   154 
   155 
   156   /* external resources */
   157 
   158   val PATH = "path"
   159   val Path = new Markup_String(PATH, NAME)
   160 
   161   val URL = "url"
   162   val Url = new Markup_String(URL, NAME)
   163 
   164 
   165   /* pretty printing */
   166 
   167   val Block = new Markup_Int("block", "indent")
   168   val Break = new Markup_Int("break", "width")
   169 
   170   val ITEM = "item"
   171   val BULLET = "bullet"
   172 
   173   val SEPARATOR = "separator"
   174 
   175 
   176   /* text properties */
   177 
   178   val WORDS = "words"
   179 
   180   val HIDDEN = "hidden"
   181 
   182 
   183   /* misc entities */
   184 
   185   val CLASS = "class"
   186   val TYPE_NAME = "type_name"
   187   val FIXED = "fixed"
   188   val CASE = "case"
   189   val CONSTANT = "constant"
   190   val DYNAMIC_FACT = "dynamic_fact"
   191 
   192 
   193   /* inner syntax */
   194 
   195   val TFREE = "tfree"
   196   val TVAR = "tvar"
   197   val FREE = "free"
   198   val SKOLEM = "skolem"
   199   val BOUND = "bound"
   200   val VAR = "var"
   201   val NUMERAL = "numeral"
   202   val LITERAL = "literal"
   203   val DELIMITER = "delimiter"
   204   val INNER_STRING = "inner_string"
   205   val INNER_CARTOUCHE = "inner_cartouche"
   206   val INNER_COMMENT = "inner_comment"
   207 
   208   val TOKEN_RANGE = "token_range"
   209 
   210   val SORTING = "sorting"
   211   val TYPING = "typing"
   212 
   213   val ATTRIBUTE = "attribute"
   214   val METHOD = "method"
   215 
   216 
   217   /* antiquotations */
   218 
   219   val ANTIQUOTED = "antiquoted"
   220   val ANTIQUOTE = "antiquote"
   221 
   222   val ML_ANTIQUOTATION = "ML_antiquotation"
   223   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   224   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   225 
   226 
   227   /* text structure */
   228 
   229   val PARAGRAPH = "paragraph"
   230   val TEXT_FOLD = "text_fold"
   231 
   232 
   233   /* ML syntax */
   234 
   235   val ML_KEYWORD1 = "ML_keyword1"
   236   val ML_KEYWORD2 = "ML_keyword2"
   237   val ML_KEYWORD3 = "ML_keyword3"
   238   val ML_DELIMITER = "ML_delimiter"
   239   val ML_TVAR = "ML_tvar"
   240   val ML_NUMERAL = "ML_numeral"
   241   val ML_CHAR = "ML_char"
   242   val ML_STRING = "ML_string"
   243   val ML_COMMENT = "ML_comment"
   244   val SML_STRING = "SML_string"
   245   val SML_COMMENT = "SML_comment"
   246 
   247   val ML_DEF = "ML_def"
   248   val ML_OPEN = "ML_open"
   249   val ML_STRUCTURE = "ML_structure"
   250   val ML_TYPING = "ML_typing"
   251 
   252 
   253   /* outer syntax */
   254 
   255   val COMMAND = "command"
   256   val KEYWORD1 = "keyword1"
   257   val KEYWORD2 = "keyword2"
   258   val KEYWORD3 = "keyword3"
   259   val QUASI_KEYWORD = "quasi_keyword"
   260   val IMPROPER = "improper"
   261   val OPERATOR = "operator"
   262   val STRING = "string"
   263   val ALTSTRING = "altstring"
   264   val VERBATIM = "verbatim"
   265   val CARTOUCHE = "cartouche"
   266   val COMMENT = "comment"
   267   val CONTROL = "control"
   268 
   269 
   270   /* timing */
   271 
   272   val Elapsed = new Properties.Double("elapsed")
   273   val CPU = new Properties.Double("cpu")
   274   val GC = new Properties.Double("gc")
   275 
   276   object Timing_Properties
   277   {
   278     def apply(timing: isabelle.Timing): Properties.T =
   279       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   280 
   281     def unapply(props: Properties.T): Option[isabelle.Timing] =
   282       (props, props, props) match {
   283         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   284           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   285         case _ => None
   286       }
   287   }
   288 
   289   val TIMING = "timing"
   290 
   291   object Timing
   292   {
   293     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   294 
   295     def unapply(markup: Markup): Option[isabelle.Timing] =
   296       markup match {
   297         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   298         case _ => None
   299       }
   300   }
   301 
   302 
   303   /* command timing */
   304 
   305   val COMMAND_TIMING = "command_timing"
   306 
   307 
   308   /* toplevel */
   309 
   310   val SUBGOALS = "subgoals"
   311   val PROOF_STATE = "proof_state"
   312 
   313   val STATE = "state"
   314   val GOAL = "goal"
   315   val SUBGOAL = "subgoal"
   316 
   317 
   318   /* command status */
   319 
   320   val TASK = "task"
   321 
   322   val ACCEPTED = "accepted"
   323   val FORKED = "forked"
   324   val JOINED = "joined"
   325   val RUNNING = "running"
   326   val FINISHED = "finished"
   327   val FAILED = "failed"
   328 
   329 
   330   /* interactive documents */
   331 
   332   val VERSION = "version"
   333   val ASSIGN = "assign"
   334 
   335 
   336   /* prover process */
   337 
   338   val PROVER_COMMAND = "prover_command"
   339   val PROVER_ARG = "prover_arg"
   340 
   341 
   342   /* messages */
   343 
   344   val SERIAL = "serial"
   345   val Serial = new Properties.Long(SERIAL)
   346 
   347   val MESSAGE = "message"
   348 
   349   val INIT = "init"
   350   val STATUS = "status"
   351   val REPORT = "report"
   352   val RESULT = "result"
   353   val WRITELN = "writeln"
   354   val TRACING = "tracing"
   355   val WARNING = "warning"
   356   val ERROR = "error"
   357   val PROTOCOL = "protocol"
   358   val SYSTEM = "system"
   359   val STDOUT = "stdout"
   360   val STDERR = "stderr"
   361   val EXIT = "exit"
   362 
   363   val WRITELN_MESSAGE = "writeln_message"
   364   val TRACING_MESSAGE = "tracing_message"
   365   val WARNING_MESSAGE = "warning_message"
   366   val ERROR_MESSAGE = "error_message"
   367 
   368   val messages =
   369     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   370         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   371   val message: String => String = messages.withDefault((s: String) => s)
   372 
   373   val Return_Code = new Properties.Int("return_code")
   374 
   375   val LEGACY = "legacy"
   376 
   377   val NO_REPORT = "no_report"
   378 
   379   val BAD = "bad"
   380 
   381   val INTENSIFY = "intensify"
   382   val INFORMATION = "information"
   383 
   384 
   385   /* active areas */
   386 
   387   val BROWSER = "browser"
   388   val GRAPHVIEW = "graphview"
   389 
   390   val SENDBACK = "sendback"
   391   val PADDING = "padding"
   392   val PADDING_LINE = (PADDING, "line")
   393   val PADDING_COMMAND = (PADDING, "command")
   394 
   395   val DIALOG = "dialog"
   396   val Result = new Properties.String(RESULT)
   397 
   398 
   399   /* protocol message functions */
   400 
   401   val FUNCTION = "function"
   402   val Function = new Properties.String(FUNCTION)
   403 
   404   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   405   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   406 
   407   object Protocol_Handler
   408   {
   409     def unapply(props: Properties.T): Option[(String)] =
   410       props match {
   411         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   412         case _ => None
   413       }
   414   }
   415 
   416   val INVOKE_SCALA = "invoke_scala"
   417   object Invoke_Scala
   418   {
   419     def unapply(props: Properties.T): Option[(String, String)] =
   420       props match {
   421         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   422         case _ => None
   423       }
   424   }
   425 
   426   val CANCEL_SCALA = "cancel_scala"
   427   object Cancel_Scala
   428   {
   429     def unapply(props: Properties.T): Option[String] =
   430       props match {
   431         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   432         case _ => None
   433       }
   434   }
   435 
   436   object ML_Statistics
   437   {
   438     def unapply(props: Properties.T): Option[Properties.T] =
   439       props match {
   440         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   441         case _ => None
   442       }
   443   }
   444 
   445   object Task_Statistics
   446   {
   447     def unapply(props: Properties.T): Option[Properties.T] =
   448       props match {
   449         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   450         case _ => None
   451       }
   452   }
   453 
   454   object Loading_Theory
   455   {
   456     def unapply(props: Properties.T): Option[String] =
   457       props match {
   458         case List((FUNCTION, "loading_theory"), (NAME, name)) => Some(name)
   459         case _ => None
   460       }
   461   }
   462 
   463   object Use_Theories_Result
   464   {
   465     def unapply(props: Properties.T): Option[(String, Boolean)] =
   466       props match {
   467         case List((FUNCTION, "use_theories_result"),
   468           ("id", id), ("ok", Properties.Value.Boolean(ok))) => Some((id, ok))
   469         case _ => None
   470       }
   471   }
   472 
   473   val PRINT_OPERATIONS = "print_operations"
   474 
   475 
   476   /* simplifier trace */
   477 
   478   val SIMP_TRACE_PANEL = "simp_trace_panel"
   479 
   480   val SIMP_TRACE_LOG = "simp_trace_log"
   481   val SIMP_TRACE_STEP = "simp_trace_step"
   482   val SIMP_TRACE_RECURSE = "simp_trace_recurse"
   483   val SIMP_TRACE_HINT = "simp_trace_hint"
   484   val SIMP_TRACE_IGNORE = "simp_trace_ignore"
   485 
   486   val SIMP_TRACE_CANCEL = "simp_trace_cancel"
   487   object Simp_Trace_Cancel
   488   {
   489     def unapply(props: Properties.T): Option[Long] =
   490       props match {
   491         case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
   492         case _ => None
   493       }
   494   }
   495 }
   496 
   497 
   498 sealed case class Markup(name: String, properties: Properties.T)
   499