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