clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
authorwenzelm
Sat Aug 11 17:24:21 2012 +0200 (2012-08-11 ago)
changeset 48768abc45de5bb22
parent 48767 7f0c469cc796
child 48769 e3b7087bb923
clarified "bad" markup: proper body text, invent missing serial on Scala side (counting backwards);
src/Pure/General/antiquote.ML
src/Pure/Isar/outer_syntax.ML
src/Pure/ML/ml_lex.ML
src/Pure/PIDE/isabelle_markup.ML
src/Pure/PIDE/isabelle_markup.scala
src/Pure/Syntax/syntax_phases.ML
src/Pure/Thy/thy_syntax.ML
src/Tools/jEdit/src/isabelle_rendering.scala
     1.1 --- a/src/Pure/General/antiquote.ML	Sat Aug 11 17:23:09 2012 +0200
     1.2 +++ b/src/Pure/General/antiquote.ML	Sat Aug 11 17:24:21 2012 +0200
     1.3 @@ -12,7 +12,8 @@
     1.4      Open of Position.T |
     1.5      Close of Position.T
     1.6    val is_text: 'a antiquote -> bool
     1.7 -  val reports_of: ('a -> Position.report list) -> 'a antiquote list -> Position.report list
     1.8 +  val reports_of: ('a -> Position.report_text list) ->
     1.9 +    'a antiquote list -> Position.report_text list
    1.10    val check_nesting: 'a antiquote list -> unit
    1.11    val scan_antiq: Symbol_Pos.T list -> (Symbol_Pos.T list * Position.range) * Symbol_Pos.T list
    1.12    val scan: Symbol_Pos.T list -> 'a antiquote * Symbol_Pos.T list
    1.13 @@ -40,9 +41,9 @@
    1.14  fun reports_of text =
    1.15    maps
    1.16      (fn Text x => text x
    1.17 -      | Antiq (_, (pos, _)) => [(pos, Isabelle_Markup.antiq)]
    1.18 -      | Open pos => [(pos, Isabelle_Markup.antiq)]
    1.19 -      | Close pos => [(pos, Isabelle_Markup.antiq)]);
    1.20 +      | Antiq (_, (pos, _)) => [((pos, Isabelle_Markup.antiq), "")]
    1.21 +      | Open pos => [((pos, Isabelle_Markup.antiq), "")]
    1.22 +      | Close pos => [((pos, Isabelle_Markup.antiq), "")]);
    1.23  
    1.24  
    1.25  (* check_nesting *)
    1.26 @@ -99,7 +100,7 @@
    1.27  
    1.28  fun read (syms, pos) =
    1.29    (case Scan.read Symbol_Pos.stopper (Scan.repeat scan_text) syms of
    1.30 -    SOME xs => (Position.reports (reports_of (K []) xs); check_nesting xs; xs)
    1.31 +    SOME xs => (Position.reports_text (reports_of (K []) xs); check_nesting xs; xs)
    1.32    | NONE => error ("Malformed quotation/antiquotation source" ^ Position.str_of pos));
    1.33  
    1.34  end;
     2.1 --- a/src/Pure/Isar/outer_syntax.ML	Sat Aug 11 17:23:09 2012 +0200
     2.2 +++ b/src/Pure/Isar/outer_syntax.ML	Sat Aug 11 17:24:21 2012 +0200
     2.3 @@ -284,12 +284,12 @@
     2.4          let val name = Token.content_of tok in
     2.5            (case commands name of
     2.6              NONE => []
     2.7 -          | SOME cmd => [(Token.position_of tok, command_markup false (name, cmd))])
     2.8 +          | SOME cmd => [((Token.position_of tok, command_markup false (name, cmd)), "")])
     2.9          end
    2.10        else [];
    2.11  
    2.12      val (is_malformed, token_reports) = Thy_Syntax.reports_of_tokens toks;
    2.13 -    val _ = Position.reports (token_reports @ maps command_reports toks);
    2.14 +    val _ = Position.reports_text (token_reports @ maps command_reports toks);
    2.15    in
    2.16      if is_malformed then (Toplevel.malformed pos "Malformed command syntax", true)
    2.17      else
     3.1 --- a/src/Pure/ML/ml_lex.ML	Sat Aug 11 17:23:09 2012 +0200
     3.2 +++ b/src/Pure/ML/ml_lex.ML	Sat Aug 11 17:24:21 2012 +0200
     3.3 @@ -104,28 +104,30 @@
     3.4  local
     3.5  
     3.6  val token_kind_markup =
     3.7 - fn Keyword   => Isabelle_Markup.ML_keyword
     3.8 -  | Ident     => Markup.empty
     3.9 -  | LongIdent => Markup.empty
    3.10 -  | TypeVar   => Isabelle_Markup.ML_tvar
    3.11 -  | Word      => Isabelle_Markup.ML_numeral
    3.12 -  | Int       => Isabelle_Markup.ML_numeral
    3.13 -  | Real      => Isabelle_Markup.ML_numeral
    3.14 -  | Char      => Isabelle_Markup.ML_char
    3.15 -  | String    => Isabelle_Markup.ML_string
    3.16 -  | Space     => Markup.empty
    3.17 -  | Comment   => Isabelle_Markup.ML_comment
    3.18 -  | Error msg => Isabelle_Markup.bad msg
    3.19 -  | EOF       => Markup.empty;
    3.20 + fn Keyword   => (Isabelle_Markup.ML_keyword, "")
    3.21 +  | Ident     => (Markup.empty, "")
    3.22 +  | LongIdent => (Markup.empty, "")
    3.23 +  | TypeVar   => (Isabelle_Markup.ML_tvar, "")
    3.24 +  | Word      => (Isabelle_Markup.ML_numeral, "")
    3.25 +  | Int       => (Isabelle_Markup.ML_numeral, "")
    3.26 +  | Real      => (Isabelle_Markup.ML_numeral, "")
    3.27 +  | Char      => (Isabelle_Markup.ML_char, "")
    3.28 +  | String    => (Isabelle_Markup.ML_string, "")
    3.29 +  | Space     => (Markup.empty, "")
    3.30 +  | Comment   => (Isabelle_Markup.ML_comment, "")
    3.31 +  | Error msg => (Isabelle_Markup.bad, msg)
    3.32 +  | EOF       => (Markup.empty, "");
    3.33  
    3.34  fun token_markup kind x =
    3.35    if kind = Keyword andalso exists_string (not o Symbol.is_ascii_letter) x
    3.36 -  then Isabelle_Markup.ML_delimiter
    3.37 +  then (Isabelle_Markup.ML_delimiter, "")
    3.38    else token_kind_markup kind;
    3.39  
    3.40  in
    3.41  
    3.42 -fun report_of_token (Token ((pos, _), (kind, x))) = (pos, token_markup kind x);
    3.43 +fun report_of_token (Token ((pos, _), (kind, x))) =
    3.44 +  let val (markup, txt) = token_markup kind x
    3.45 +  in ((pos, markup), txt) end;
    3.46  
    3.47  end;
    3.48  
    3.49 @@ -301,7 +303,7 @@
    3.50          |> Source.source Symbol_Pos.stopper (Scan.bulk (!!! "bad input" scan_antiq))
    3.51            (SOME (false, fn msg => recover msg >> map Antiquote.Text))
    3.52          |> Source.exhaust
    3.53 -        |> tap (Position.reports o Antiquote.reports_of (single o report_of_token))
    3.54 +        |> tap (Position.reports_text o Antiquote.reports_of (single o report_of_token))
    3.55          |> tap Antiquote.check_nesting
    3.56          |> tap (List.app (fn Antiquote.Text tok => (check_content_of tok; warn tok) | _ => ())))
    3.57        handle ERROR msg =>
     4.1 --- a/src/Pure/PIDE/isabelle_markup.ML	Sat Aug 11 17:23:09 2012 +0200
     4.2 +++ b/src/Pure/PIDE/isabelle_markup.ML	Sat Aug 11 17:24:21 2012 +0200
     4.3 @@ -95,8 +95,7 @@
     4.4    val promptN: string val prompt: Markup.T
     4.5    val reportN: string val report: Markup.T
     4.6    val no_reportN: string val no_report: Markup.T
     4.7 -  val messageN: string
     4.8 -  val badN: string val bad: string -> Markup.T
     4.9 +  val badN: string val bad: Markup.T
    4.10    val functionN: string
    4.11    val assign_execs: Properties.T
    4.12    val removed_versions: Properties.T
    4.13 @@ -287,11 +286,7 @@
    4.14  val (reportN, report) = markup_elem "report";
    4.15  val (no_reportN, no_report) = markup_elem "no_report";
    4.16  
    4.17 -val messageN = "message"
    4.18 -val badN = "bad"
    4.19 -
    4.20 -fun bad "" = (badN, [])
    4.21 -  | bad msg = (badN, [(messageN, msg)]);
    4.22 +val (badN, bad) = markup_elem "bad";
    4.23  
    4.24  
    4.25  (* protocol message functions *)
     5.1 --- a/src/Pure/PIDE/isabelle_markup.scala	Sat Aug 11 17:23:09 2012 +0200
     5.2 +++ b/src/Pure/PIDE/isabelle_markup.scala	Sat Aug 11 17:24:21 2012 +0200
     5.3 @@ -236,7 +236,6 @@
     5.4  
     5.5    val NO_REPORT = "no_report"
     5.6  
     5.7 -  val Message = new Properties.String("message")
     5.8    val BAD = "bad"
     5.9  
    5.10  
     6.1 --- a/src/Pure/Syntax/syntax_phases.ML	Sat Aug 11 17:23:09 2012 +0200
     6.2 +++ b/src/Pure/Syntax/syntax_phases.ML	Sat Aug 11 17:24:21 2012 +0200
     6.3 @@ -318,7 +318,7 @@
     6.4  fun parse_failed ctxt pos msg kind =
     6.5    cat_error msg ("Failed to parse " ^ kind ^
     6.6      Markup.markup Isabelle_Markup.report
     6.7 -      (Context_Position.reported_text ctxt pos (Isabelle_Markup.bad "") ""));
     6.8 +      (Context_Position.reported_text ctxt pos Isabelle_Markup.bad ""));
     6.9  
    6.10  fun parse_sort ctxt =
    6.11    Syntax.parse_token ctxt Term_XML.Decode.sort Isabelle_Markup.sort
    6.12 @@ -609,7 +609,7 @@
    6.13        | token_trans "_tvar" x = SOME (Pretty.mark_str (Isabelle_Markup.tvar, x))
    6.14        | token_trans "_free" x = SOME (Pretty.marks_str (free_or_skolem ctxt x))
    6.15        | token_trans "_bound" x = SOME (Pretty.mark_str (Isabelle_Markup.bound, x))
    6.16 -      | token_trans "_loose" x = SOME (Pretty.mark_str (Isabelle_Markup.bad "", x))
    6.17 +      | token_trans "_loose" x = SOME (Pretty.mark_str (Isabelle_Markup.bad, x))
    6.18        | token_trans "_var" x = SOME (Pretty.mark_str (var_or_skolem x))
    6.19        | token_trans "_numeral" x = SOME (Pretty.mark_str (Isabelle_Markup.numeral, x))
    6.20        | token_trans "_inner_string" x = SOME (Pretty.mark_str (Isabelle_Markup.inner_string, x))
     7.1 --- a/src/Pure/Thy/thy_syntax.ML	Sat Aug 11 17:23:09 2012 +0200
     7.2 +++ b/src/Pure/Thy/thy_syntax.ML	Sat Aug 11 17:24:21 2012 +0200
     7.3 @@ -7,7 +7,7 @@
     7.4  signature THY_SYNTAX =
     7.5  sig
     7.6    val parse_tokens: Scan.lexicon * Scan.lexicon -> Position.T -> string -> Token.T list
     7.7 -  val reports_of_tokens: Token.T list -> bool * Position.report list
     7.8 +  val reports_of_tokens: Token.T list -> bool * (Position.report * string) list
     7.9    val present_token: Token.T -> Output.output
    7.10    datatype span_kind = Command of string | Ignored | Malformed
    7.11    type span
    7.12 @@ -38,28 +38,29 @@
    7.13  local
    7.14  
    7.15  val token_kind_markup =
    7.16 - fn Token.Command       => Isabelle_Markup.command
    7.17 -  | Token.Keyword       => Isabelle_Markup.keyword
    7.18 -  | Token.Ident         => Markup.empty
    7.19 -  | Token.LongIdent     => Markup.empty
    7.20 -  | Token.SymIdent      => Markup.empty
    7.21 -  | Token.Var           => Isabelle_Markup.var
    7.22 -  | Token.TypeIdent     => Isabelle_Markup.tfree
    7.23 -  | Token.TypeVar       => Isabelle_Markup.tvar
    7.24 -  | Token.Nat           => Markup.empty
    7.25 -  | Token.Float         => Markup.empty
    7.26 -  | Token.String        => Isabelle_Markup.string
    7.27 -  | Token.AltString     => Isabelle_Markup.altstring
    7.28 -  | Token.Verbatim      => Isabelle_Markup.verbatim
    7.29 -  | Token.Space         => Markup.empty
    7.30 -  | Token.Comment       => Isabelle_Markup.comment
    7.31 -  | Token.InternalValue => Markup.empty
    7.32 -  | Token.Error msg     => Isabelle_Markup.bad msg
    7.33 -  | Token.Sync          => Isabelle_Markup.control
    7.34 -  | Token.EOF           => Isabelle_Markup.control;
    7.35 + fn Token.Command       => (Isabelle_Markup.command, "")
    7.36 +  | Token.Keyword       => (Isabelle_Markup.keyword, "")
    7.37 +  | Token.Ident         => (Markup.empty, "")
    7.38 +  | Token.LongIdent     => (Markup.empty, "")
    7.39 +  | Token.SymIdent      => (Markup.empty, "")
    7.40 +  | Token.Var           => (Isabelle_Markup.var, "")
    7.41 +  | Token.TypeIdent     => (Isabelle_Markup.tfree, "")
    7.42 +  | Token.TypeVar       => (Isabelle_Markup.tvar, "")
    7.43 +  | Token.Nat           => (Markup.empty, "")
    7.44 +  | Token.Float         => (Markup.empty, "")
    7.45 +  | Token.String        => (Isabelle_Markup.string, "")
    7.46 +  | Token.AltString     => (Isabelle_Markup.altstring, "")
    7.47 +  | Token.Verbatim      => (Isabelle_Markup.verbatim, "")
    7.48 +  | Token.Space         => (Markup.empty, "")
    7.49 +  | Token.Comment       => (Isabelle_Markup.comment, "")
    7.50 +  | Token.InternalValue => (Markup.empty, "")
    7.51 +  | Token.Error msg     => (Isabelle_Markup.bad, msg)
    7.52 +  | Token.Sync          => (Isabelle_Markup.control, "")
    7.53 +  | Token.EOF           => (Isabelle_Markup.control, "");
    7.54  
    7.55  fun token_markup tok =
    7.56 -  if Token.keyword_with (not o Lexicon.is_ascii_identifier) tok then Isabelle_Markup.operator
    7.57 +  if Token.keyword_with (not o Lexicon.is_ascii_identifier) tok
    7.58 +  then (Isabelle_Markup.operator, "")
    7.59    else
    7.60      let
    7.61        val kind = Token.kind_of tok;
    7.62 @@ -67,7 +68,8 @@
    7.63          if kind = Token.Command
    7.64          then Markup.properties [(Markup.nameN, Token.content_of tok)]
    7.65          else I;
    7.66 -    in props (token_kind_markup kind) end;
    7.67 +      val (markup, txt) = token_kind_markup kind;
    7.68 +    in (props markup, txt) end;
    7.69  
    7.70  fun reports_of_token tok =
    7.71    let
    7.72 @@ -75,9 +77,10 @@
    7.73        Symbol_Pos.explode (Token.source_position_of tok)
    7.74        |> map_filter (fn (sym, pos) =>
    7.75            if Symbol.is_malformed sym
    7.76 -          then SOME (pos, Isabelle_Markup.bad "Malformed symbol") else NONE);
    7.77 +          then SOME ((pos, Isabelle_Markup.bad), "Malformed symbol") else NONE);
    7.78      val is_malformed = Token.is_error tok orelse not (null malformed_symbols);
    7.79 -    val reports = (Token.position_of tok, token_markup tok) :: malformed_symbols;
    7.80 +    val (markup, txt) = token_markup tok;
    7.81 +    val reports = ((Token.position_of tok, markup), txt) :: malformed_symbols;
    7.82    in (is_malformed, reports) end;
    7.83  
    7.84  in
    7.85 @@ -87,7 +90,7 @@
    7.86    in (exists fst results, maps snd results) end;
    7.87  
    7.88  fun present_token tok =
    7.89 -  Markup.enclose (token_markup tok) (Output.output (Token.unparse tok));
    7.90 +  Markup.enclose (fst (token_markup tok)) (Output.output (Token.unparse tok));
    7.91  
    7.92  end;
    7.93  
     8.1 --- a/src/Tools/jEdit/src/isabelle_rendering.scala	Sat Aug 11 17:23:09 2012 +0200
     8.2 +++ b/src/Tools/jEdit/src/isabelle_rendering.scala	Sat Aug 11 17:24:21 2012 +0200
     8.3 @@ -104,8 +104,8 @@
     8.4    }
     8.5  
     8.6  
     8.7 -  private def tooltip_text(msg: XML.Body): String =
     8.8 -    Pretty.string_of(msg, margin = Isabelle.Int_Property("tooltip-margin"))
     8.9 +  private def tooltip_text(msg: XML.Tree): String =
    8.10 +    Pretty.string_of(List(msg), margin = Isabelle.Int_Property("tooltip-margin"))
    8.11  
    8.12    def tooltip_message(snapshot: Document.Snapshot, range: Text.Range): Option[String] =
    8.13    {
    8.14 @@ -119,10 +119,9 @@
    8.15            if markup == Isabelle_Markup.WRITELN ||
    8.16                markup == Isabelle_Markup.WARNING ||
    8.17                markup == Isabelle_Markup.ERROR =>
    8.18 -            msgs + (serial -> tooltip_text(List(msg)))
    8.19 -          case (msgs, Text.Info(_,
    8.20 -              XML.Elem(Markup(Isabelle_Markup.BAD, Isabelle_Markup.Message(msg)), _))) =>
    8.21 -            msgs + (0L -> tooltip_text(YXML.parse_body(msg)))
    8.22 +            msgs + (serial -> tooltip_text(msg))
    8.23 +          case (msgs, Text.Info(_, msg @ XML.Elem(Markup(Isabelle_Markup.BAD, _), _))) =>
    8.24 +            msgs + (Document.new_id() -> tooltip_text(msg))
    8.25          }).toList.flatMap(_.info)
    8.26      if (msgs.isEmpty) None else Some(cat_lines(msgs.iterator.map(_._2)))
    8.27    }