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