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