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