src/Pure/PIDE/markup.scala
author wenzelm
Mon Dec 09 12:16:52 2013 +0100 (2013-12-09 ago)
changeset 54702 3daeba5130f0
parent 53378 07990ba8c0ea
child 55033 8e8243975860
permissions -rw-r--r--
added document antiquotation @{url}, which produces formal markup for LaTeX and 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 
    31   /* formal entities */
    32 
    33   val BINDING = "binding"
    34   val ENTITY = "entity"
    35   val DEF = "def"
    36   val REF = "ref"
    37 
    38   object Entity
    39   {
    40     def unapply(markup: Markup): Option[(String, String)] =
    41       markup match {
    42         case Markup(ENTITY, props @ Kind(kind)) =>
    43           props match {
    44             case Name(name) => Some(kind, name)
    45             case _ => None
    46           }
    47         case _ => None
    48       }
    49   }
    50 
    51 
    52   /* position */
    53 
    54   val LINE = "line"
    55   val OFFSET = "offset"
    56   val END_OFFSET = "end_offset"
    57   val FILE = "file"
    58   val ID = "id"
    59 
    60   val DEF_LINE = "def_line"
    61   val DEF_OFFSET = "def_offset"
    62   val DEF_END_OFFSET = "def_end_offset"
    63   val DEF_FILE = "def_file"
    64   val DEF_ID = "def_id"
    65 
    66   val POSITION_PROPERTIES = Set(LINE, OFFSET, END_OFFSET, FILE, ID)
    67   val POSITION = "position"
    68 
    69 
    70   /* external resources */
    71 
    72   val PATH = "path"
    73 
    74   object Path
    75   {
    76     def unapply(markup: Markup): Option[String] =
    77       markup match {
    78         case Markup(PATH, Name(name)) => Some(name)
    79         case _ => None
    80       }
    81   }
    82 
    83   val URL = "url"
    84 
    85   object Url
    86   {
    87     def unapply(markup: Markup): Option[String] =
    88       markup match {
    89         case Markup(URL, Name(name)) => Some(name)
    90         case _ => None
    91       }
    92   }
    93 
    94 
    95   /* pretty printing */
    96 
    97   val Indent = new Properties.Int("indent")
    98   val BLOCK = "block"
    99 
   100   val Width = new Properties.Int("width")
   101   val BREAK = "break"
   102 
   103   val ITEM = "item"
   104   val BULLET = "bullet"
   105 
   106   val SEPARATOR = "separator"
   107 
   108 
   109   /* hidden text */
   110 
   111   val HIDDEN = "hidden"
   112 
   113 
   114   /* logical entities */
   115 
   116   val CLASS = "class"
   117   val TYPE_NAME = "type_name"
   118   val FIXED = "fixed"
   119   val CASE = "case"
   120   val CONSTANT = "constant"
   121   val DYNAMIC_FACT = "dynamic_fact"
   122 
   123 
   124   /* inner syntax */
   125 
   126   val TFREE = "tfree"
   127   val TVAR = "tvar"
   128   val FREE = "free"
   129   val SKOLEM = "skolem"
   130   val BOUND = "bound"
   131   val VAR = "var"
   132   val NUMERAL = "numeral"
   133   val LITERAL = "literal"
   134   val DELIMITER = "delimiter"
   135   val INNER_STRING = "inner_string"
   136   val INNER_COMMENT = "inner_comment"
   137 
   138   val TOKEN_RANGE = "token_range"
   139 
   140   val SORT = "sort"
   141   val TYP = "typ"
   142   val TERM = "term"
   143   val PROP = "prop"
   144 
   145   val SORTING = "sorting"
   146   val TYPING = "typing"
   147 
   148   val ATTRIBUTE = "attribute"
   149   val METHOD = "method"
   150 
   151 
   152   /* embedded source text */
   153 
   154   val ML_SOURCE = "ML_source"
   155   val DOCUMENT_SOURCE = "document_source"
   156 
   157   val ANTIQ = "antiq"
   158   val ML_ANTIQUOTATION = "ML_antiquotation"
   159   val DOCUMENT_ANTIQUOTATION = "document_antiquotation"
   160   val DOCUMENT_ANTIQUOTATION_OPTION = "document_antiquotation_option"
   161 
   162 
   163   /* text structure */
   164 
   165   val PARAGRAPH = "paragraph"
   166   val TEXT_FOLD = "text_fold"
   167 
   168 
   169   /* ML syntax */
   170 
   171   val ML_KEYWORD = "ML_keyword"
   172   val ML_DELIMITER = "ML_delimiter"
   173   val ML_TVAR = "ML_tvar"
   174   val ML_NUMERAL = "ML_numeral"
   175   val ML_CHAR = "ML_char"
   176   val ML_STRING = "ML_string"
   177   val ML_COMMENT = "ML_comment"
   178 
   179   val ML_DEF = "ML_def"
   180   val ML_OPEN = "ML_open"
   181   val ML_STRUCT = "ML_struct"
   182   val ML_TYPING = "ML_typing"
   183 
   184 
   185   /* outer syntax */
   186 
   187   val KEYWORD = "keyword"
   188   val OPERATOR = "operator"
   189   val COMMAND = "command"
   190   val STRING = "string"
   191   val ALTSTRING = "altstring"
   192   val VERBATIM = "verbatim"
   193   val COMMENT = "comment"
   194   val CONTROL = "control"
   195 
   196   val KEYWORD1 = "keyword1"
   197   val KEYWORD2 = "keyword2"
   198 
   199 
   200   /* timing */
   201 
   202   val Elapsed = new Properties.Double("elapsed")
   203   val CPU = new Properties.Double("cpu")
   204   val GC = new Properties.Double("gc")
   205 
   206   object Timing_Properties
   207   {
   208     def apply(timing: isabelle.Timing): Properties.T =
   209       Elapsed(timing.elapsed.seconds) ::: CPU(timing.cpu.seconds) ::: GC(timing.gc.seconds)
   210 
   211     def unapply(props: Properties.T): Option[isabelle.Timing] =
   212       (props, props, props) match {
   213         case (Elapsed(elapsed), CPU(cpu), GC(gc)) =>
   214           Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   215         case _ => None
   216       }
   217   }
   218 
   219   val TIMING = "timing"
   220 
   221   object Timing
   222   {
   223     def apply(timing: isabelle.Timing): Markup = Markup(TIMING, Timing_Properties(timing))
   224 
   225     def unapply(markup: Markup): Option[isabelle.Timing] =
   226       markup match {
   227         case Markup(TIMING, Timing_Properties(timing)) => Some(timing)
   228         case _ => None
   229       }
   230   }
   231 
   232 
   233   /* command timing */
   234 
   235   val COMMAND_TIMING = "command_timing"
   236 
   237 
   238   /* toplevel */
   239 
   240   val SUBGOALS = "subgoals"
   241   val PROOF_STATE = "proof_state"
   242 
   243   val STATE = "state"
   244   val GOAL = "goal"
   245   val SUBGOAL = "subgoal"
   246 
   247 
   248   /* command status */
   249 
   250   val TASK = "task"
   251 
   252   val ACCEPTED = "accepted"
   253   val FORKED = "forked"
   254   val JOINED = "joined"
   255   val RUNNING = "running"
   256   val FINISHED = "finished"
   257   val FAILED = "failed"
   258 
   259 
   260   /* interactive documents */
   261 
   262   val VERSION = "version"
   263   val ASSIGN = "assign"
   264 
   265 
   266   /* prover process */
   267 
   268   val PROVER_COMMAND = "prover_command"
   269   val PROVER_ARG = "prover_arg"
   270 
   271 
   272   /* messages */
   273 
   274   val Serial = new Properties.Long("serial")
   275 
   276   val MESSAGE = "message"
   277 
   278   val INIT = "init"
   279   val STATUS = "status"
   280   val REPORT = "report"
   281   val RESULT = "result"
   282   val WRITELN = "writeln"
   283   val TRACING = "tracing"
   284   val WARNING = "warning"
   285   val ERROR = "error"
   286   val PROTOCOL = "protocol"
   287   val SYSTEM = "system"
   288   val STDOUT = "stdout"
   289   val STDERR = "stderr"
   290   val EXIT = "exit"
   291 
   292   val WRITELN_MESSAGE = "writeln_message"
   293   val TRACING_MESSAGE = "tracing_message"
   294   val WARNING_MESSAGE = "warning_message"
   295   val ERROR_MESSAGE = "error_message"
   296 
   297   val messages =
   298     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   299         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   300   val message: String => String = messages.withDefault((s: String) => s)
   301 
   302   val Return_Code = new Properties.Int("return_code")
   303 
   304   val LEGACY = "legacy"
   305 
   306   val NO_REPORT = "no_report"
   307 
   308   val BAD = "bad"
   309 
   310   val INTENSIFY = "intensify"
   311   val INFORMATION = "information"
   312 
   313 
   314   /* active areas */
   315 
   316   val BROWSER = "browser"
   317   val GRAPHVIEW = "graphview"
   318 
   319   val SENDBACK = "sendback"
   320   val PADDING = "padding"
   321   val PADDING_LINE = (PADDING, "line")
   322   val PADDING_COMMAND = (PADDING, "command")
   323 
   324   val DIALOG = "dialog"
   325   val Result = new Properties.String(RESULT)
   326 
   327 
   328   /* protocol message functions */
   329 
   330   val FUNCTION = "function"
   331   val Function = new Properties.String(FUNCTION)
   332 
   333   val Flush: Properties.T = List((FUNCTION, "flush"))
   334 
   335   val Assign_Update: Properties.T = List((FUNCTION, "assign_update"))
   336   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   337 
   338   object Protocol_Handler
   339   {
   340     def unapply(props: Properties.T): Option[(String)] =
   341       props match {
   342         case List((FUNCTION, "protocol_handler"), (NAME, name)) => Some(name)
   343         case _ => None
   344       }
   345   }
   346 
   347   val INVOKE_SCALA = "invoke_scala"
   348   object Invoke_Scala
   349   {
   350     def unapply(props: Properties.T): Option[(String, String)] =
   351       props match {
   352         case List((FUNCTION, INVOKE_SCALA), (NAME, name), (ID, id)) => Some((name, id))
   353         case _ => None
   354       }
   355   }
   356 
   357   val CANCEL_SCALA = "cancel_scala"
   358   object Cancel_Scala
   359   {
   360     def unapply(props: Properties.T): Option[String] =
   361       props match {
   362         case List((FUNCTION, CANCEL_SCALA), (ID, id)) => Some(id)
   363         case _ => None
   364       }
   365   }
   366 
   367   val SLEDGEHAMMER_PROVERS = "sledgehammer_provers"
   368   val Sledgehammer_Provers: Properties.T = List((FUNCTION, SLEDGEHAMMER_PROVERS))
   369 
   370   object ML_Statistics
   371   {
   372     def unapply(props: Properties.T): Option[Properties.T] =
   373       props match {
   374         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   375         case _ => None
   376       }
   377   }
   378 
   379   object Task_Statistics
   380   {
   381     def unapply(props: Properties.T): Option[Properties.T] =
   382       props match {
   383         case (FUNCTION, "task_statistics") :: stats => Some(stats)
   384         case _ => None
   385       }
   386   }
   387 }
   388 
   389 
   390 sealed case class Markup(name: String, properties: Properties.T)
   391