src/Pure/PIDE/markup.scala
author wenzelm
Sat Apr 19 19:52:02 2014 +0200 (2014-04-19 ago)
changeset 56623 4675df68450e
parent 56616 abc2da18d08d
child 56733 f7700146678d
permissions -rw-r--r--
more elementary option sledgehammer_provers, avoiding complications of defaults from ML side (NB: guessing at number of cores does not make sense in PIDE);
     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 COMPLETION = "completion"
    73   val NO_COMPLETION = "no_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   val Delimited = new Properties.Boolean("delimited")
    99 
   100   val LANGUAGE = "language"
   101   object Language
   102   {
   103     val ML = "ML"
   104     val SML = "SML"
   105     val UNKNOWN = "unknown"
   106 
   107     def unapply(markup: Markup): Option[(String, Boolean, Boolean, Boolean)] =
   108       markup match {
   109         case Markup(LANGUAGE, props) =>
   110           (props, props, props, props) match {
   111             case (Name(name), Symbols(symbols), Antiquotes(antiquotes), Delimited(delimited)) =>
   112               Some((name, symbols, antiquotes, delimited))
   113             case _ => None
   114           }
   115         case _ => None
   116       }
   117   }
   118 
   119 
   120   /* external resources */
   121 
   122   val PATH = "path"
   123   val Path = new Markup_String(PATH, NAME)
   124 
   125   val URL = "url"
   126   val Url = new Markup_String(URL, NAME)
   127 
   128 
   129   /* pretty printing */
   130 
   131   val Block = new Markup_Int("block", "indent")
   132   val Break = new Markup_Int("break", "width")
   133 
   134   val ITEM = "item"
   135   val BULLET = "bullet"
   136 
   137   val SEPARATOR = "separator"
   138 
   139 
   140   /* text properties */
   141 
   142   val WORDS = "words"
   143 
   144   val HIDDEN = "hidden"
   145 
   146 
   147   /* logical entities */
   148 
   149   val CLASS = "class"
   150   val TYPE_NAME = "type_name"
   151   val FIXED = "fixed"
   152   val CASE = "case"
   153   val CONSTANT = "constant"
   154   val DYNAMIC_FACT = "dynamic_fact"
   155 
   156 
   157   /* inner syntax */
   158 
   159   val TFREE = "tfree"
   160   val TVAR = "tvar"
   161   val FREE = "free"
   162   val SKOLEM = "skolem"
   163   val BOUND = "bound"
   164   val VAR = "var"
   165   val NUMERAL = "numeral"
   166   val LITERAL = "literal"
   167   val DELIMITER = "delimiter"
   168   val INNER_STRING = "inner_string"
   169   val INNER_CARTOUCHE = "inner_cartouche"
   170   val INNER_COMMENT = "inner_comment"
   171 
   172   val TOKEN_RANGE = "token_range"
   173 
   174   val SORTING = "sorting"
   175   val TYPING = "typing"
   176 
   177   val ATTRIBUTE = "attribute"
   178   val METHOD = "method"
   179 
   180 
   181   /* antiquotations */
   182 
   183   val ANTIQUOTED = "antiquoted"
   184   val ANTIQUOTE = "antiquote"
   185 
   186   val ML_ANTIQUOTATION = "ML_antiquotation"
   187   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   188   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   189 
   190 
   191   /* text structure */
   192 
   193   val PARAGRAPH = "paragraph"
   194   val TEXT_FOLD = "text_fold"
   195 
   196 
   197   /* ML syntax */
   198 
   199   val ML_KEYWORD1 = "ML_keyword1"
   200   val ML_KEYWORD2 = "ML_keyword2"
   201   val ML_KEYWORD3 = "ML_keyword3"
   202   val ML_DELIMITER = "ML_delimiter"
   203   val ML_TVAR = "ML_tvar"
   204   val ML_NUMERAL = "ML_numeral"
   205   val ML_CHAR = "ML_char"
   206   val ML_STRING = "ML_string"
   207   val ML_COMMENT = "ML_comment"
   208   val SML_STRING = "SML_string"
   209   val SML_COMMENT = "SML_comment"
   210 
   211   val ML_DEF = "ML_def"
   212   val ML_OPEN = "ML_open"
   213   val ML_STRUCTURE = "ML_structure"
   214   val ML_TYPING = "ML_typing"
   215 
   216 
   217   /* outer syntax */
   218 
   219   val COMMAND = "command"
   220   val KEYWORD1 = "keyword1"
   221   val KEYWORD2 = "keyword2"
   222   val KEYWORD3 = "keyword3"
   223   val QUASI_KEYWORD = "quasi_keyword"
   224   val IMPROPER = "improper"
   225   val OPERATOR = "operator"
   226   val STRING = "string"
   227   val ALTSTRING = "altstring"
   228   val VERBATIM = "verbatim"
   229   val CARTOUCHE = "cartouche"
   230   val COMMENT = "comment"
   231   val CONTROL = "control"
   232 
   233 
   234   /* timing */
   235 
   236   val Elapsed = new Properties.Double("elapsed")
   237   val CPU = new Properties.Double("cpu")
   238   val GC = new Properties.Double("gc")
   239 
   240   object Timing_Properties
   241   {
   242     def apply(timing: isabelle.Timing): Properties.T =
   243       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   244 
   245     def unapply(props: Properties.T): Option[isabelle.Timing] =
   246       (props, props, props) match {
   247         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   248           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   249         case _ => None
   250       }
   251   }
   252 
   253   val TIMING = "timing"
   254 
   255   object Timing
   256   {
   257     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   258 
   259     def unapply(markup: Markup): Option[isabelle.Timing] =
   260       markup match {
   261         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   262         case _ => None
   263       }
   264   }
   265 
   266 
   267   /* command timing */
   268 
   269   val COMMAND_TIMING = "command_timing"
   270 
   271 
   272   /* toplevel */
   273 
   274   val SUBGOALS = "subgoals"
   275   val PROOF_STATE = "proof_state"
   276 
   277   val STATE = "state"
   278   val GOAL = "goal"
   279   val SUBGOAL = "subgoal"
   280 
   281 
   282   /* command status */
   283 
   284   val TASK = "task"
   285 
   286   val ACCEPTED = "accepted"
   287   val FORKED = "forked"
   288   val JOINED = "joined"
   289   val RUNNING = "running"
   290   val FINISHED = "finished"
   291   val FAILED = "failed"
   292 
   293 
   294   /* interactive documents */
   295 
   296   val VERSION = "version"
   297   val ASSIGN = "assign"
   298 
   299 
   300   /* prover process */
   301 
   302   val PROVER_COMMAND = "prover_command"
   303   val PROVER_ARG = "prover_arg"
   304 
   305 
   306   /* messages */
   307 
   308   val SERIAL = "serial"
   309   val Serial = new Properties.Long(SERIAL)
   310 
   311   val MESSAGE = "message"
   312 
   313   val INIT = "init"
   314   val STATUS = "status"
   315   val REPORT = "report"
   316   val RESULT = "result"
   317   val WRITELN = "writeln"
   318   val TRACING = "tracing"
   319   val WARNING = "warning"
   320   val ERROR = "error"
   321   val PROTOCOL = "protocol"
   322   val SYSTEM = "system"
   323   val STDOUT = "stdout"
   324   val STDERR = "stderr"
   325   val EXIT = "exit"
   326 
   327   val WRITELN_MESSAGE = "writeln_message"
   328   val TRACING_MESSAGE = "tracing_message"
   329   val WARNING_MESSAGE = "warning_message"
   330   val ERROR_MESSAGE = "error_message"
   331 
   332   val messages =
   333     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   334         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   335   val message: String => String = messages.withDefault((s: String) => s)
   336 
   337   val Return_Code = new Properties.Int("return_code")
   338 
   339   val LEGACY = "legacy"
   340 
   341   val NO_REPORT = "no_report"
   342 
   343   val BAD = "bad"
   344 
   345   val INTENSIFY = "intensify"
   346   val INFORMATION = "information"
   347 
   348 
   349   /* active areas */
   350 
   351   val BROWSER = "browser"
   352   val GRAPHVIEW = "graphview"
   353 
   354   val SENDBACK = "sendback"
   355   val PADDING = "padding"
   356   val PADDING_LINE = (PADDING, "line")
   357   val PADDING_COMMAND = (PADDING, "command")
   358 
   359   val DIALOG = "dialog"
   360   val Result = new Properties.String(RESULT)
   361 
   362 
   363   /* protocol message functions */
   364 
   365   val FUNCTION = "function"
   366   val Function = new Properties.String(FUNCTION)
   367 
   368   val Flush: Properties.T = List((FUNCTION, "flush"))
   369 
   370   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   371   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   372 
   373   object Protocol_Handler
   374   {
   375     def unapply(props: Properties.T): Option[(String)] =
   376       props match {
   377         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   378         case _ => None
   379       }
   380   }
   381 
   382   val INVOKE_SCALA = "invoke_scala"
   383   object Invoke_Scala
   384   {
   385     def unapply(props: Properties.T): Option[(String, String)] =
   386       props match {
   387         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   388         case _ => None
   389       }
   390   }
   391 
   392   val CANCEL_SCALA = "cancel_scala"
   393   object Cancel_Scala
   394   {
   395     def unapply(props: Properties.T): Option[String] =
   396       props match {
   397         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   398         case _ => None
   399       }
   400   }
   401 
   402   object ML_Statistics
   403   {
   404     def unapply(props: Properties.T): Option[Properties.T] =
   405       props match {
   406         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   407         case _ => None
   408       }
   409   }
   410 
   411   object Task_Statistics
   412   {
   413     def unapply(props: Properties.T): Option[Properties.T] =
   414       props match {
   415         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   416         case _ => None
   417       }
   418   }
   419 
   420   object Loading_Theory
   421   {
   422     def unapply(props: Properties.T): Option[String] =
   423       props match {
   424         case List((FUNCTION, "loading_theory"), (NAME, name)) => Some(name)
   425         case _ => None
   426       }
   427   }
   428 
   429   object Use_Theories_Result
   430   {
   431     def unapply(props: Properties.T): Option[(String, Boolean)] =
   432       props match {
   433         case List((FUNCTION, "use_theories_result"),
   434           ("id", id), ("ok", Properties.Value.Boolean(ok))) => Some((id, ok))
   435         case _ => None
   436       }
   437   }
   438 
   439 
   440   /* simplifier trace */
   441 
   442   val SIMP_TRACE = "simp_trace"
   443 
   444   val SIMP_TRACE_LOG = "simp_trace_log"
   445   val SIMP_TRACE_STEP = "simp_trace_step"
   446   val SIMP_TRACE_RECURSE = "simp_trace_recurse"
   447   val SIMP_TRACE_HINT = "simp_trace_hint"
   448   val SIMP_TRACE_IGNORE = "simp_trace_ignore"
   449 
   450   val SIMP_TRACE_CANCEL = "simp_trace_cancel"
   451   object Simp_Trace_Cancel
   452   {
   453     def unapply(props: Properties.T): Option[Long] =
   454       props match {
   455         case (FUNCTION, SIMP_TRACE_CANCEL) :: Serial(i) => Some(i)
   456         case _ => None
   457       }
   458   }
   459 }
   460 
   461 
   462 sealed case class Markup(name: String, properties: Properties.T)
   463