36 (* present *) |
36 (* present *) |
37 |
37 |
38 local |
38 local |
39 |
39 |
40 val token_kind_markup = |
40 val token_kind_markup = |
41 fn Token.Command => Isabelle_Markup.command |
41 fn Token.Command => (Isabelle_Markup.command, "") |
42 | Token.Keyword => Isabelle_Markup.keyword |
42 | Token.Keyword => (Isabelle_Markup.keyword, "") |
43 | Token.Ident => Markup.empty |
43 | Token.Ident => (Markup.empty, "") |
44 | Token.LongIdent => Markup.empty |
44 | Token.LongIdent => (Markup.empty, "") |
45 | Token.SymIdent => Markup.empty |
45 | Token.SymIdent => (Markup.empty, "") |
46 | Token.Var => Isabelle_Markup.var |
46 | Token.Var => (Isabelle_Markup.var, "") |
47 | Token.TypeIdent => Isabelle_Markup.tfree |
47 | Token.TypeIdent => (Isabelle_Markup.tfree, "") |
48 | Token.TypeVar => Isabelle_Markup.tvar |
48 | Token.TypeVar => (Isabelle_Markup.tvar, "") |
49 | Token.Nat => Markup.empty |
49 | Token.Nat => (Markup.empty, "") |
50 | Token.Float => Markup.empty |
50 | Token.Float => (Markup.empty, "") |
51 | Token.String => Isabelle_Markup.string |
51 | Token.String => (Isabelle_Markup.string, "") |
52 | Token.AltString => Isabelle_Markup.altstring |
52 | Token.AltString => (Isabelle_Markup.altstring, "") |
53 | Token.Verbatim => Isabelle_Markup.verbatim |
53 | Token.Verbatim => (Isabelle_Markup.verbatim, "") |
54 | Token.Space => Markup.empty |
54 | Token.Space => (Markup.empty, "") |
55 | Token.Comment => Isabelle_Markup.comment |
55 | Token.Comment => (Isabelle_Markup.comment, "") |
56 | Token.InternalValue => Markup.empty |
56 | Token.InternalValue => (Markup.empty, "") |
57 | Token.Error msg => Isabelle_Markup.bad msg |
57 | Token.Error msg => (Isabelle_Markup.bad, msg) |
58 | Token.Sync => Isabelle_Markup.control |
58 | Token.Sync => (Isabelle_Markup.control, "") |
59 | Token.EOF => Isabelle_Markup.control; |
59 | Token.EOF => (Isabelle_Markup.control, ""); |
60 |
60 |
61 fun token_markup tok = |
61 fun token_markup tok = |
62 if Token.keyword_with (not o Lexicon.is_ascii_identifier) tok then Isabelle_Markup.operator |
62 if Token.keyword_with (not o Lexicon.is_ascii_identifier) tok |
|
63 then (Isabelle_Markup.operator, "") |
63 else |
64 else |
64 let |
65 let |
65 val kind = Token.kind_of tok; |
66 val kind = Token.kind_of tok; |
66 val props = |
67 val props = |
67 if kind = Token.Command |
68 if kind = Token.Command |
68 then Markup.properties [(Markup.nameN, Token.content_of tok)] |
69 then Markup.properties [(Markup.nameN, Token.content_of tok)] |
69 else I; |
70 else I; |
70 in props (token_kind_markup kind) end; |
71 val (markup, txt) = token_kind_markup kind; |
|
72 in (props markup, txt) end; |
71 |
73 |
72 fun reports_of_token tok = |
74 fun reports_of_token tok = |
73 let |
75 let |
74 val malformed_symbols = |
76 val malformed_symbols = |
75 Symbol_Pos.explode (Token.source_position_of tok) |
77 Symbol_Pos.explode (Token.source_position_of tok) |
76 |> map_filter (fn (sym, pos) => |
78 |> map_filter (fn (sym, pos) => |
77 if Symbol.is_malformed sym |
79 if Symbol.is_malformed sym |
78 then SOME (pos, Isabelle_Markup.bad "Malformed symbol") else NONE); |
80 then SOME ((pos, Isabelle_Markup.bad), "Malformed symbol") else NONE); |
79 val is_malformed = Token.is_error tok orelse not (null malformed_symbols); |
81 val is_malformed = Token.is_error tok orelse not (null malformed_symbols); |
80 val reports = (Token.position_of tok, token_markup tok) :: malformed_symbols; |
82 val (markup, txt) = token_markup tok; |
|
83 val reports = ((Token.position_of tok, markup), txt) :: malformed_symbols; |
81 in (is_malformed, reports) end; |
84 in (is_malformed, reports) end; |
82 |
85 |
83 in |
86 in |
84 |
87 |
85 fun reports_of_tokens toks = |
88 fun reports_of_tokens toks = |
86 let val results = map reports_of_token toks |
89 let val results = map reports_of_token toks |
87 in (exists fst results, maps snd results) end; |
90 in (exists fst results, maps snd results) end; |
88 |
91 |
89 fun present_token tok = |
92 fun present_token tok = |
90 Markup.enclose (token_markup tok) (Output.output (Token.unparse tok)); |
93 Markup.enclose (fst (token_markup tok)) (Output.output (Token.unparse tok)); |
91 |
94 |
92 end; |
95 end; |
93 |
96 |
94 |
97 |
95 |
98 |