src/Pure/PIDE/isabelle_markup.ML
author wenzelm
Thu Aug 02 12:36:54 2012 +0200 (2012-08-02)
changeset 48646 91281e9472d8
parent 47395 e6261a493f04
child 48709 719f458cd89e
permissions -rw-r--r--
more official command specifications, including source position;
     1 (*  Title:      Pure/PIDE/isabelle_markup.ML
     2     Author:     Makarius
     3 
     4 Isabelle markup elements.
     5 *)
     6 
     7 signature ISABELLE_MARKUP =
     8 sig
     9   val bindingN: string val binding: Markup.T
    10   val entityN: string val entity: string -> string -> Markup.T
    11   val get_entity_kind: Markup.T -> string option
    12   val defN: string
    13   val refN: string
    14   val lineN: string
    15   val offsetN: string
    16   val end_offsetN: string
    17   val fileN: string
    18   val idN: string
    19   val position_properties': string list
    20   val position_properties: string list
    21   val positionN: string val position: Markup.T
    22   val pathN: string val path: string -> Markup.T
    23   val indentN: string
    24   val blockN: string val block: int -> Markup.T
    25   val widthN: string
    26   val breakN: string val break: int -> Markup.T
    27   val fbreakN: string val fbreak: Markup.T
    28   val hiddenN: string val hidden: Markup.T
    29   val classN: string
    30   val type_nameN: string
    31   val constantN: string
    32   val fixedN: string val fixed: string -> Markup.T
    33   val dynamic_factN: string val dynamic_fact: string -> Markup.T
    34   val tfreeN: string val tfree: Markup.T
    35   val tvarN: string val tvar: Markup.T
    36   val freeN: string val free: Markup.T
    37   val skolemN: string val skolem: Markup.T
    38   val boundN: string val bound: Markup.T
    39   val varN: string val var: Markup.T
    40   val numeralN: string val numeral: Markup.T
    41   val literalN: string val literal: Markup.T
    42   val delimiterN: string val delimiter: Markup.T
    43   val inner_stringN: string val inner_string: Markup.T
    44   val inner_commentN: string val inner_comment: Markup.T
    45   val token_rangeN: string val token_range: Markup.T
    46   val sortN: string val sort: Markup.T
    47   val typN: string val typ: Markup.T
    48   val termN: string val term: Markup.T
    49   val propN: string val prop: Markup.T
    50   val typingN: string val typing: Markup.T
    51   val ML_keywordN: string val ML_keyword: Markup.T
    52   val ML_delimiterN: string val ML_delimiter: Markup.T
    53   val ML_tvarN: string val ML_tvar: Markup.T
    54   val ML_numeralN: string val ML_numeral: Markup.T
    55   val ML_charN: string val ML_char: Markup.T
    56   val ML_stringN: string val ML_string: Markup.T
    57   val ML_commentN: string val ML_comment: Markup.T
    58   val ML_malformedN: string val ML_malformed: Markup.T
    59   val ML_defN: string
    60   val ML_openN: string
    61   val ML_structN: string
    62   val ML_typingN: string val ML_typing: Markup.T
    63   val ML_sourceN: string val ML_source: Markup.T
    64   val doc_sourceN: string val doc_source: Markup.T
    65   val antiqN: string val antiq: Markup.T
    66   val ML_antiquotationN: string
    67   val doc_antiquotationN: string
    68   val doc_antiquotation_optionN: string
    69   val keywordN: string val keyword: Markup.T
    70   val operatorN: string val operator: Markup.T
    71   val commandN: string val command: Markup.T
    72   val stringN: string val string: Markup.T
    73   val altstringN: string val altstring: Markup.T
    74   val verbatimN: string val verbatim: Markup.T
    75   val commentN: string val comment: Markup.T
    76   val controlN: string val control: Markup.T
    77   val malformedN: string val malformed: Markup.T
    78   val tokenN: string val token: Properties.T -> Markup.T
    79   val command_spanN: string val command_span: string -> Markup.T
    80   val ignored_spanN: string val ignored_span: Markup.T
    81   val malformed_spanN: string val malformed_span: Markup.T
    82   val elapsedN: string
    83   val cpuN: string
    84   val gcN: string
    85   val timingN: string val timing: Timing.timing -> Markup.T
    86   val subgoalsN: string
    87   val proof_stateN: string val proof_state: int -> Markup.T
    88   val stateN: string val state: Markup.T
    89   val subgoalN: string val subgoal: Markup.T
    90   val sendbackN: string val sendback: Markup.T
    91   val hiliteN: string val hilite: Markup.T
    92   val taskN: string
    93   val acceptedN: string val accepted: Markup.T
    94   val forkedN: string val forked: Markup.T
    95   val joinedN: string val joined: Markup.T
    96   val failedN: string val failed: Markup.T
    97   val finishedN: string val finished: Markup.T
    98   val serialN: string
    99   val legacyN: string val legacy: Markup.T
   100   val promptN: string val prompt: Markup.T
   101   val reportN: string val report: Markup.T
   102   val no_reportN: string val no_report: Markup.T
   103   val badN: string val bad: Markup.T
   104   val functionN: string
   105   val ready: Properties.T
   106   val loaded_theory: string -> Properties.T
   107   val keyword_decl: string -> Properties.T
   108   val command_decl: string -> string -> Properties.T
   109   val assign_execs: Properties.T
   110   val removed_versions: Properties.T
   111   val invoke_scala: string -> string -> Properties.T
   112   val cancel_scala: string -> Properties.T
   113 end;
   114 
   115 structure Isabelle_Markup: ISABELLE_MARKUP =
   116 struct
   117 
   118 (** markup elements **)
   119 
   120 fun markup_elem elem = (elem, (elem, []): Markup.T);
   121 fun markup_string elem prop = (elem, fn s => (elem, [(prop, s)]): Markup.T);
   122 fun markup_int elem prop = (elem, fn i => (elem, [(prop, Markup.print_int i)]): Markup.T);
   123 
   124 
   125 (* formal entities *)
   126 
   127 val (bindingN, binding) = markup_elem "binding";
   128 
   129 val entityN = "entity";
   130 fun entity kind name = (entityN, [(Markup.nameN, name), (Markup.kindN, kind)]);
   131 
   132 fun get_entity_kind (name, props) =
   133   if name = entityN then AList.lookup (op =) props Markup.kindN
   134   else NONE;
   135 
   136 val defN = "def";
   137 val refN = "ref";
   138 
   139 
   140 (* position *)
   141 
   142 val lineN = "line";
   143 val offsetN = "offset";
   144 val end_offsetN = "end_offset";
   145 val fileN = "file";
   146 val idN = "id";
   147 
   148 val position_properties' = [fileN, idN];
   149 val position_properties = [lineN, offsetN, end_offsetN] @ position_properties';
   150 
   151 val (positionN, position) = markup_elem "position";
   152 
   153 
   154 (* path *)
   155 
   156 val (pathN, path) = markup_string "path" Markup.nameN;
   157 
   158 
   159 (* pretty printing *)
   160 
   161 val indentN = "indent";
   162 val (blockN, block) = markup_int "block" indentN;
   163 
   164 val widthN = "width";
   165 val (breakN, break) = markup_int "break" widthN;
   166 
   167 val (fbreakN, fbreak) = markup_elem "fbreak";
   168 
   169 
   170 (* hidden text *)
   171 
   172 val (hiddenN, hidden) = markup_elem "hidden";
   173 
   174 
   175 (* logical entities *)
   176 
   177 val classN = "class";
   178 val type_nameN = "type name";
   179 val constantN = "constant";
   180 
   181 val (fixedN, fixed) = markup_string "fixed" Markup.nameN;
   182 val (dynamic_factN, dynamic_fact) = markup_string "dynamic_fact" Markup.nameN;
   183 
   184 
   185 (* inner syntax *)
   186 
   187 val (tfreeN, tfree) = markup_elem "tfree";
   188 val (tvarN, tvar) = markup_elem "tvar";
   189 val (freeN, free) = markup_elem "free";
   190 val (skolemN, skolem) = markup_elem "skolem";
   191 val (boundN, bound) = markup_elem "bound";
   192 val (varN, var) = markup_elem "var";
   193 val (numeralN, numeral) = markup_elem "numeral";
   194 val (literalN, literal) = markup_elem "literal";
   195 val (delimiterN, delimiter) = markup_elem "delimiter";
   196 val (inner_stringN, inner_string) = markup_elem "inner_string";
   197 val (inner_commentN, inner_comment) = markup_elem "inner_comment";
   198 
   199 val (token_rangeN, token_range) = markup_elem "token_range";
   200 
   201 val (sortN, sort) = markup_elem "sort";
   202 val (typN, typ) = markup_elem "typ";
   203 val (termN, term) = markup_elem "term";
   204 val (propN, prop) = markup_elem "prop";
   205 
   206 val (typingN, typing) = markup_elem "typing";
   207 
   208 
   209 (* ML syntax *)
   210 
   211 val (ML_keywordN, ML_keyword) = markup_elem "ML_keyword";
   212 val (ML_delimiterN, ML_delimiter) = markup_elem "ML_delimiter";
   213 val (ML_tvarN, ML_tvar) = markup_elem "ML_tvar";
   214 val (ML_numeralN, ML_numeral) = markup_elem "ML_numeral";
   215 val (ML_charN, ML_char) = markup_elem "ML_char";
   216 val (ML_stringN, ML_string) = markup_elem "ML_string";
   217 val (ML_commentN, ML_comment) = markup_elem "ML_comment";
   218 val (ML_malformedN, ML_malformed) = markup_elem "ML_malformed";
   219 
   220 val ML_defN = "ML_def";
   221 val ML_openN = "ML_open";
   222 val ML_structN = "ML_struct";
   223 val (ML_typingN, ML_typing) = markup_elem "ML_typing";
   224 
   225 
   226 (* embedded source text *)
   227 
   228 val (ML_sourceN, ML_source) = markup_elem "ML_source";
   229 val (doc_sourceN, doc_source) = markup_elem "doc_source";
   230 
   231 val (antiqN, antiq) = markup_elem "antiq";
   232 val ML_antiquotationN = "ML antiquotation";
   233 val doc_antiquotationN = "document antiquotation";
   234 val doc_antiquotation_optionN = "document antiquotation option";
   235 
   236 
   237 (* outer syntax *)
   238 
   239 val (keywordN, keyword) = markup_elem "keyword";
   240 val (operatorN, operator) = markup_elem "operator";
   241 val (commandN, command) = markup_elem "command";
   242 val (stringN, string) = markup_elem "string";
   243 val (altstringN, altstring) = markup_elem "altstring";
   244 val (verbatimN, verbatim) = markup_elem "verbatim";
   245 val (commentN, comment) = markup_elem "comment";
   246 val (controlN, control) = markup_elem "control";
   247 val (malformedN, malformed) = markup_elem "malformed";
   248 
   249 val tokenN = "token";
   250 fun token props = (tokenN, props);
   251 
   252 val (command_spanN, command_span) = markup_string "command_span" Markup.nameN;
   253 val (ignored_spanN, ignored_span) = markup_elem "ignored_span";
   254 val (malformed_spanN, malformed_span) = markup_elem "malformed_span";
   255 
   256 
   257 (* timing *)
   258 
   259 val timingN = "timing";
   260 val elapsedN = "elapsed";
   261 val cpuN = "cpu";
   262 val gcN = "gc";
   263 
   264 fun timing {elapsed, cpu, gc} =
   265   (timingN,
   266    [(elapsedN, Time.toString elapsed),
   267     (cpuN, Time.toString cpu),
   268     (gcN, Time.toString gc)]);
   269 
   270 
   271 (* toplevel *)
   272 
   273 val subgoalsN = "subgoals";
   274 val (proof_stateN, proof_state) = markup_int "proof_state" subgoalsN;
   275 
   276 val (stateN, state) = markup_elem "state";
   277 val (subgoalN, subgoal) = markup_elem "subgoal";
   278 val (sendbackN, sendback) = markup_elem "sendback";
   279 val (hiliteN, hilite) = markup_elem "hilite";
   280 
   281 
   282 (* command status *)
   283 
   284 val taskN = "task";
   285 
   286 val (acceptedN, accepted) = markup_elem "accepted";
   287 val (forkedN, forked) = markup_elem "forked";
   288 val (joinedN, joined) = markup_elem "joined";
   289 
   290 val (failedN, failed) = markup_elem "failed";
   291 val (finishedN, finished) = markup_elem "finished";
   292 
   293 
   294 (* messages *)
   295 
   296 val serialN = "serial";
   297 
   298 val (legacyN, legacy) = markup_elem "legacy";
   299 val (promptN, prompt) = markup_elem "prompt";
   300 
   301 val (reportN, report) = markup_elem "report";
   302 val (no_reportN, no_report) = markup_elem "no_report";
   303 
   304 val (badN, bad) = markup_elem "bad";
   305 
   306 
   307 (* protocol message functions *)
   308 
   309 val functionN = "function"
   310 
   311 val ready = [(functionN, "ready")];
   312 
   313 fun loaded_theory name = [(functionN, "loaded_theory"), (Markup.nameN, name)];
   314 
   315 fun keyword_decl name = [(functionN, "keyword_decl"), (Markup.nameN, name)];
   316 fun command_decl name kind =
   317   [(functionN, "command_decl"), (Markup.nameN, name), (Markup.kindN, kind)];
   318 
   319 val assign_execs = [(functionN, "assign_execs")];
   320 val removed_versions = [(functionN, "removed_versions")];
   321 
   322 fun invoke_scala name id = [(functionN, "invoke_scala"), (Markup.nameN, name), (idN, id)];
   323 fun cancel_scala id = [(functionN, "cancel_scala"), (idN, id)];
   324 
   325 end;