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