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