clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
authorwenzelm
Tue Feb 25 17:03:55 2014 +0100 (2014-02-25 ago)
changeset 557444a4e5686e091
parent 55743 225a060e7445
child 55745 b865c3035d5c
clarified token markup: keyword1/keyword2 is for syntax, and "command" the entity kind;
tuned message;
src/Pure/Isar/token.ML
src/Pure/PIDE/markup.ML
src/Pure/PIDE/markup.scala
src/Pure/Thy/latex.ML
src/Pure/Thy/thy_syntax.ML
     1.1 --- a/src/Pure/Isar/token.ML	Tue Feb 25 14:56:58 2014 +0100
     1.2 +++ b/src/Pure/Isar/token.ML	Tue Feb 25 17:03:55 2014 +0100
     1.3 @@ -42,6 +42,7 @@
     1.4    val inner_syntax_of: T -> string
     1.5    val source_position_of: T -> Symbol_Pos.text * Position.T
     1.6    val content_of: T -> string
     1.7 +  val markup: T -> Markup.T * string
     1.8    val unparse: T -> string
     1.9    val text_of: T -> string * string
    1.10    val get_files: T -> file Exn.result list
    1.11 @@ -213,6 +214,42 @@
    1.12  fun content_of (Token (_, (_, x), _)) = x;
    1.13  
    1.14  
    1.15 +(* markup *)
    1.16 +
    1.17 +local
    1.18 +
    1.19 +val token_kind_markup =
    1.20 + fn Command       => (Markup.keyword1, "")
    1.21 +  | Keyword       => (Markup.keyword2, "")
    1.22 +  | Ident         => (Markup.empty, "")
    1.23 +  | LongIdent     => (Markup.empty, "")
    1.24 +  | SymIdent      => (Markup.empty, "")
    1.25 +  | Var           => (Markup.var, "")
    1.26 +  | TypeIdent     => (Markup.tfree, "")
    1.27 +  | TypeVar       => (Markup.tvar, "")
    1.28 +  | Nat           => (Markup.empty, "")
    1.29 +  | Float         => (Markup.empty, "")
    1.30 +  | String        => (Markup.string, "")
    1.31 +  | AltString     => (Markup.altstring, "")
    1.32 +  | Verbatim      => (Markup.verbatim, "")
    1.33 +  | Cartouche     => (Markup.cartouche, "")
    1.34 +  | Space         => (Markup.empty, "")
    1.35 +  | Comment       => (Markup.comment, "")
    1.36 +  | InternalValue => (Markup.empty, "")
    1.37 +  | Error msg     => (Markup.bad, msg)
    1.38 +  | Sync          => (Markup.control, "")
    1.39 +  | EOF           => (Markup.control, "");
    1.40 +
    1.41 +in
    1.42 +
    1.43 +fun markup tok =
    1.44 +  if keyword_with (not o Symbol.is_ascii_identifier) tok
    1.45 +  then (Markup.operator, "")
    1.46 +  else token_kind_markup (kind_of tok);
    1.47 +
    1.48 +end;
    1.49 +
    1.50 +
    1.51  (* unparse *)
    1.52  
    1.53  fun unparse (Token (_, (kind, x), _)) =
    1.54 @@ -231,11 +268,13 @@
    1.55    else
    1.56      let
    1.57        val k = str_of_kind (kind_of tok);
    1.58 +      val (m, _) = markup tok;
    1.59        val s = unparse tok;
    1.60      in
    1.61        if s = "" then (k, "")
    1.62 -      else if size s < 40 andalso not (exists_string (fn c => c = "\n") s) then (k ^ " " ^ s, "")
    1.63 -      else (k, s)
    1.64 +      else if size s < 40 andalso not (exists_string (fn c => c = "\n") s)
    1.65 +      then (k ^ " " ^ Markup.markup m s, "")
    1.66 +      else (k, Markup.markup m s)
    1.67      end;
    1.68  
    1.69  
     2.1 --- a/src/Pure/PIDE/markup.ML	Tue Feb 25 14:56:58 2014 +0100
     2.2 +++ b/src/Pure/PIDE/markup.ML	Tue Feb 25 17:03:55 2014 +0100
     2.3 @@ -97,9 +97,8 @@
     2.4    val document_antiquotation_optionN: string
     2.5    val paragraphN: string val paragraph: T
     2.6    val text_foldN: string val text_fold: T
     2.7 -  val keywordN: string val keyword: T
     2.8 +  val commandN: string
     2.9    val operatorN: string val operator: T
    2.10 -  val commandN: string val command: T
    2.11    val stringN: string val string: T
    2.12    val altstringN: string val altstring: T
    2.13    val verbatimN: string val verbatim: T
    2.14 @@ -396,9 +395,11 @@
    2.15  
    2.16  (* outer syntax *)
    2.17  
    2.18 -val (keywordN, keyword) = markup_elem "keyword";
    2.19 +val commandN = "command";
    2.20 +
    2.21 +val (keyword1N, keyword1) = markup_elem "keyword1";
    2.22 +val (keyword2N, keyword2) = markup_elem "keyword2";
    2.23  val (operatorN, operator) = markup_elem "operator";
    2.24 -val (commandN, command) = markup_elem "command";
    2.25  val (stringN, string) = markup_elem "string";
    2.26  val (altstringN, altstring) = markup_elem "altstring";
    2.27  val (verbatimN, verbatim) = markup_elem "verbatim";
    2.28 @@ -409,9 +410,6 @@
    2.29  val tokenN = "token";
    2.30  fun token props = (tokenN, props);
    2.31  
    2.32 -val (keyword1N, keyword1) = markup_elem "keyword1";
    2.33 -val (keyword2N, keyword2) = markup_elem "keyword2";
    2.34 -
    2.35  
    2.36  (* timing *)
    2.37  
     3.1 --- a/src/Pure/PIDE/markup.scala	Tue Feb 25 14:56:58 2014 +0100
     3.2 +++ b/src/Pure/PIDE/markup.scala	Tue Feb 25 17:03:55 2014 +0100
     3.3 @@ -209,9 +209,11 @@
     3.4  
     3.5    /* outer syntax */
     3.6  
     3.7 -  val KEYWORD = "keyword"
     3.8 +  val COMMAND = "command"
     3.9 +
    3.10 +  val KEYWORD1 = "keyword1"
    3.11 +  val KEYWORD2 = "keyword2"
    3.12    val OPERATOR = "operator"
    3.13 -  val COMMAND = "command"
    3.14    val STRING = "string"
    3.15    val ALTSTRING = "altstring"
    3.16    val VERBATIM = "verbatim"
    3.17 @@ -219,9 +221,6 @@
    3.18    val COMMENT = "comment"
    3.19    val CONTROL = "control"
    3.20  
    3.21 -  val KEYWORD1 = "keyword1"
    3.22 -  val KEYWORD2 = "keyword2"
    3.23 -
    3.24  
    3.25    /* timing */
    3.26  
     4.1 --- a/src/Pure/Thy/latex.ML	Tue Feb 25 14:56:58 2014 +0100
     4.2 +++ b/src/Pure/Thy/latex.ML	Tue Feb 25 17:03:55 2014 +0100
     4.3 @@ -178,10 +178,8 @@
     4.4    in (output_symbols syms, Symbol.length syms) end;
     4.5  
     4.6  fun latex_markup (s, _) =
     4.7 -  if s = Markup.commandN orelse s = Markup.keyword1N
     4.8 -    then ("\\isacommand{", "}")
     4.9 -  else if s = Markup.keywordN orelse s = Markup.keyword2N
    4.10 -    then ("\\isakeyword{", "}")
    4.11 +  if s = Markup.keyword1N then ("\\isacommand{", "}")
    4.12 +  else if s = Markup.keyword2N then ("\\isakeyword{", "}")
    4.13    else Markup.no_output;
    4.14  
    4.15  fun latex_indent "" _ = ""
     5.1 --- a/src/Pure/Thy/thy_syntax.ML	Tue Feb 25 14:56:58 2014 +0100
     5.2 +++ b/src/Pure/Thy/thy_syntax.ML	Tue Feb 25 17:03:55 2014 +0100
     5.3 @@ -42,41 +42,6 @@
     5.4  
     5.5  local
     5.6  
     5.7 -val token_kind_markup =
     5.8 - fn Token.Command       => (Markup.command, "")
     5.9 -  | Token.Keyword       => (Markup.keyword, "")
    5.10 -  | Token.Ident         => (Markup.empty, "")
    5.11 -  | Token.LongIdent     => (Markup.empty, "")
    5.12 -  | Token.SymIdent      => (Markup.empty, "")
    5.13 -  | Token.Var           => (Markup.var, "")
    5.14 -  | Token.TypeIdent     => (Markup.tfree, "")
    5.15 -  | Token.TypeVar       => (Markup.tvar, "")
    5.16 -  | Token.Nat           => (Markup.empty, "")
    5.17 -  | Token.Float         => (Markup.empty, "")
    5.18 -  | Token.String        => (Markup.string, "")
    5.19 -  | Token.AltString     => (Markup.altstring, "")
    5.20 -  | Token.Verbatim      => (Markup.verbatim, "")
    5.21 -  | Token.Cartouche     => (Markup.cartouche, "")
    5.22 -  | Token.Space         => (Markup.empty, "")
    5.23 -  | Token.Comment       => (Markup.comment, "")
    5.24 -  | Token.InternalValue => (Markup.empty, "")
    5.25 -  | Token.Error msg     => (Markup.bad, msg)
    5.26 -  | Token.Sync          => (Markup.control, "")
    5.27 -  | Token.EOF           => (Markup.control, "");
    5.28 -
    5.29 -fun token_markup tok =
    5.30 -  if Token.keyword_with (not o Symbol.is_ascii_identifier) tok
    5.31 -  then (Markup.operator, "")
    5.32 -  else
    5.33 -    let
    5.34 -      val kind = Token.kind_of tok;
    5.35 -      val props =
    5.36 -        if kind = Token.Command
    5.37 -        then Markup.properties [(Markup.nameN, Token.content_of tok)]
    5.38 -        else I;
    5.39 -      val (markup, txt) = token_kind_markup kind;
    5.40 -    in (props markup, txt) end;
    5.41 -
    5.42  fun reports_of_token tok =
    5.43    let
    5.44      val malformed_symbols =
    5.45 @@ -85,7 +50,7 @@
    5.46            if Symbol.is_malformed sym
    5.47            then SOME ((pos, Markup.bad), "Malformed symbolic character") else NONE);
    5.48      val is_malformed = Token.is_error tok orelse not (null malformed_symbols);
    5.49 -    val (markup, txt) = token_markup tok;
    5.50 +    val (markup, txt) = Token.markup tok;
    5.51      val reports = ((Token.pos_of tok, markup), txt) :: malformed_symbols;
    5.52    in (is_malformed, reports) end;
    5.53  
    5.54 @@ -96,7 +61,7 @@
    5.55    in (exists fst results, maps snd results) end;
    5.56  
    5.57  fun present_token tok =
    5.58 -  Markup.enclose (fst (token_markup tok)) (Output.output (Token.unparse tok));
    5.59 +  Markup.enclose (fst (Token.markup tok)) (Output.output (Token.unparse tok));
    5.60  
    5.61  end;
    5.62