| author | blanchet | 
| Wed, 18 Jun 2014 14:19:42 +0200 | |
| changeset 57273 | 01b68f625550 | 
| parent 56293 | 9bc33476f6ac | 
| child 59720 | f893472fff31 | 
| permissions | -rw-r--r-- | 
| 55672 | 1 | (* Title: Pure/Isar/completion.ML | 
| 2 | Author: Makarius | |
| 3 | ||
| 55674 | 4 | Semantic completion within the formal context. | 
| 55672 | 5 | *) | 
| 6 | ||
| 7 | signature COMPLETION = | |
| 8 | sig | |
| 55687 | 9 | type T | 
| 55977 | 10 | val names: Position.T -> (string * (string * string)) list -> T | 
| 55672 | 11 | val none: T | 
| 55840 
2982d233d798
consider completion report as part of error message -- less stateful, may get handled;
 wenzelm parents: 
55694diff
changeset | 12 | val reported_text: T -> string | 
| 55915 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 13 | val suppress_abbrevs: string -> Markup.T list | 
| 55672 | 14 | end; | 
| 15 | ||
| 16 | structure Completion: COMPLETION = | |
| 17 | struct | |
| 18 | ||
| 55977 | 19 | abstype T = | 
| 20 |   Completion of {pos: Position.T, total: int, names: (string * (string * string)) list}
 | |
| 55687 | 21 | with | 
| 55672 | 22 | |
| 55915 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 23 | (* completion of names *) | 
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 24 | |
| 55687 | 25 | fun dest (Completion args) = args; | 
| 55672 | 26 | |
| 55694 
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
 wenzelm parents: 
55687diff
changeset | 27 | fun names pos names = | 
| 55687 | 28 | Completion | 
| 29 |    {pos = pos,
 | |
| 30 | total = length names, | |
| 31 | names = take (Options.default_int "completion_limit") names}; | |
| 55672 | 32 | |
| 33 | end; | |
| 55687 | 34 | |
| 55694 
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
 wenzelm parents: 
55687diff
changeset | 35 | val none = names Position.none []; | 
| 55687 | 36 | |
| 55840 
2982d233d798
consider completion report as part of error message -- less stateful, may get handled;
 wenzelm parents: 
55694diff
changeset | 37 | fun reported_text completion = | 
| 55687 | 38 |   let val {pos, total, names} = dest completion in
 | 
| 39 | if Position.is_reported pos andalso not (null names) then | |
| 40 | let | |
| 55694 
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
 wenzelm parents: 
55687diff
changeset | 41 | val markup = Position.markup pos Markup.completion; | 
| 
a1184dfb8e00
clarified semantic completion: retain kind.full_name as official item name for history;
 wenzelm parents: 
55687diff
changeset | 42 | val body = (total, names) |> | 
| 55977 | 43 | let open XML.Encode in pair int (list (pair string (pair string string))) end; | 
| 55840 
2982d233d798
consider completion report as part of error message -- less stateful, may get handled;
 wenzelm parents: 
55694diff
changeset | 44 | in YXML.string_of (XML.Elem (markup, body)) end | 
| 
2982d233d798
consider completion report as part of error message -- less stateful, may get handled;
 wenzelm parents: 
55694diff
changeset | 45 | else "" | 
| 55687 | 46 | end; | 
| 47 | ||
| 55915 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 48 | |
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 49 | (* suppress short abbreviations *) | 
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 50 | |
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 51 | fun suppress_abbrevs s = | 
| 55917 
5438ed05e1c9
special treatment of method combinators like Args.$$$ keywords, although parsed via Parse.$$$;
 wenzelm parents: 
55915diff
changeset | 52 | if not (Symbol.is_ascii_identifier s) andalso (length (Symbol.explode s) <= 1 orelse s = "::") | 
| 55915 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 53 | then [Markup.no_completion] | 
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 54 | else []; | 
| 
607948c90bf0
suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
 wenzelm parents: 
55840diff
changeset | 55 | |
| 55687 | 56 | end; |