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