src/Pure/General/completion.ML
author wenzelm
Sun, 23 Feb 2014 14:39:51 +0100
changeset 55687 78c83cd477c1
parent 55674 8a213ab0e78a
child 55694 a1184dfb8e00
permissions -rw-r--r--
clarified completion names; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/completion.ML
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     3
55674
8a213ab0e78a support for semantic completion on Scala side;
wenzelm
parents: 55672
diff changeset
     4
Semantic completion within the formal context.
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     5
*)
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     6
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     7
signature COMPLETION =
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
     8
sig
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
     9
  type T
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    10
  val make: Position.T -> string list -> T
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    11
  val none: T
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    12
  val report: T -> unit
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    13
end;
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    14
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    15
structure Completion: COMPLETION =
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    16
struct
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    17
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    18
abstype T = Completion of {pos: Position.T, total: int, names: string list}
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    19
with
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    20
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    21
fun dest (Completion args) = args;
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    22
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    23
fun make pos names =
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    24
  Completion
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    25
   {pos = pos,
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    26
    total = length names,
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    27
    names = take (Options.default_int "completion_limit") names};
55672
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    28
5e25cc741ab9 support for completion within the formal context;
wenzelm
parents:
diff changeset
    29
end;
55687
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    30
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    31
val none = make Position.none [];
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    32
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    33
fun report completion =
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    34
  let val {pos, total, names} = dest completion in
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    35
    if Position.is_reported pos andalso not (null names) then
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    36
      let
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    37
        val props =
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    38
          (Markup.totalN, Markup.print_int total) ::
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    39
            (map Markup.print_int (1 upto length names) ~~ names);
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    40
        val markup = (Markup.completionN, Position.properties_of pos @ props);
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    41
      in Output.report (Markup.markup markup "") end
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    42
    else ()
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    43
  end;
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    44
78c83cd477c1 clarified completion names;
wenzelm
parents: 55674
diff changeset
    45
end;