src/Pure/PIDE/markup.scala
author wenzelm
Mon Dec 10 13:52:33 2012 +0100 (2012-12-10 ago)
changeset 50450 358b6020f8b6
parent 50255 d0ec1f0d1d7d
child 50498 6647ba2775c1
permissions -rw-r--r--
generalized notion of active area, where sendback is just one application;
some support for graphview via active area;
     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 
   149 
   150   /* ML syntax */
   151 
   152   val ML_KEYWORD = "ML_keyword"
   153   val ML_DELIMITER = "ML_delimiter"
   154   val ML_TVAR = "ML_tvar"
   155   val ML_NUMERAL = "ML_numeral"
   156   val ML_CHAR = "ML_char"
   157   val ML_STRING = "ML_string"
   158   val ML_COMMENT = "ML_comment"
   159 
   160   val ML_DEF = "ML_def"
   161   val ML_OPEN = "ML_open"
   162   val ML_STRUCT = "ML_struct"
   163   val ML_TYPING = "ML_typing"
   164 
   165 
   166   /* outer syntax */
   167 
   168   val KEYWORD = "keyword"
   169   val OPERATOR = "operator"
   170   val COMMAND = "command"
   171   val STRING = "string"
   172   val ALTSTRING = "altstring"
   173   val VERBATIM = "verbatim"
   174   val COMMENT = "comment"
   175   val CONTROL = "control"
   176 
   177   val KEYWORD1 = "keyword1"
   178   val KEYWORD2 = "keyword2"
   179 
   180 
   181   /* timing */
   182 
   183   val TIMING = "timing"
   184   val ELAPSED = "elapsed"
   185   val CPU = "cpu"
   186   val GC = "gc"
   187 
   188   object Timing
   189   {
   190     def apply(timing: isabelle.Timing): Markup =
   191       Markup(TIMING, List(
   192         (ELAPSED, Properties.Value.Double(timing.elapsed.seconds)),
   193         (CPU, Properties.Value.Double(timing.cpu.seconds)),
   194         (GC, Properties.Value.Double(timing.gc.seconds))))
   195     def unapply(markup: Markup): Option[isabelle.Timing] =
   196       markup match {
   197         case Markup(TIMING, List(
   198           (ELAPSED, Properties.Value.Double(elapsed)),
   199           (CPU, Properties.Value.Double(cpu)),
   200           (GC, Properties.Value.Double(gc)))) =>
   201             Some(new isabelle.Timing(Time.seconds(elapsed), Time.seconds(cpu), Time.seconds(gc)))
   202         case _ => None
   203       }
   204   }
   205 
   206 
   207   /* toplevel */
   208 
   209   val SUBGOALS = "subgoals"
   210   val PROOF_STATE = "proof_state"
   211 
   212   val STATE = "state"
   213   val SUBGOAL = "subgoal"
   214 
   215 
   216   /* active areas */
   217 
   218   val SENDBACK = "sendback"
   219   val GRAPHVIEW = "graphview"
   220 
   221   val PADDING = "padding"
   222   val PADDING_LINE = (PADDING, LINE)
   223 
   224   val INTENSIFY = "intensify"
   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 WRITELN = "writeln"
   261   val TRACING = "tracing"
   262   val WARNING = "warning"
   263   val ERROR = "error"
   264   val PROTOCOL = "protocol"
   265   val SYSTEM = "system"
   266   val STDOUT = "stdout"
   267   val STDERR = "stderr"
   268   val EXIT = "exit"
   269 
   270   val WRITELN_MESSAGE = "writeln_message"
   271   val TRACING_MESSAGE = "tracing_message"
   272   val WARNING_MESSAGE = "warning_message"
   273   val ERROR_MESSAGE = "error_message"
   274 
   275   val message: String => String =
   276     Map(WRITELN -> WRITELN_MESSAGE, TRACING -> TRACING_MESSAGE,
   277         WARNING -> WARNING_MESSAGE, ERROR -> ERROR_MESSAGE)
   278       .withDefault((name: String) => name + "_message")
   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 
   289   /* protocol message functions */
   290 
   291   val FUNCTION = "function"
   292   val Function = new Properties.String(FUNCTION)
   293 
   294   val Assign_Execs: Properties.T = List((FUNCTION, "assign_execs"))
   295   val Removed_Versions: Properties.T = List((FUNCTION, "removed_versions"))
   296 
   297   object Invoke_Scala
   298   {
   299     def unapply(props: Properties.T): Option[(String, String)] =
   300       props match {
   301         case List((FUNCTION, "invoke_scala"), (NAME, name), (ID, id)) => Some((name, id))
   302         case _ => None
   303       }
   304   }
   305   object Cancel_Scala
   306   {
   307     def unapply(props: Properties.T): Option[String] =
   308       props match {
   309         case List((FUNCTION, "cancel_scala"), (ID, id)) => Some(id)
   310         case _ => None
   311       }
   312   }
   313 
   314   object ML_Statistics
   315   {
   316     def unapply(props: Properties.T): Option[Properties.T] =
   317       props match {
   318         case (FUNCTION, "ML_statistics") :: stats => Some(stats)
   319         case _ => None
   320       }
   321   }
   322 }
   323 
   324 
   325 sealed case class Markup(name: String, properties: Properties.T)
   326