69288
|
1 |
{- generated by Isabelle -}
|
|
2 |
|
|
3 |
{- Title: Tools/Haskell/Completion.hs
|
|
4 |
Author: Makarius
|
|
5 |
LICENSE: BSD 3-clause (Isabelle)
|
|
6 |
|
|
7 |
Completion of names.
|
|
8 |
|
|
9 |
See also "$ISABELLE_HOME/src/Pure/General/completion.ML".
|
|
10 |
-}
|
|
11 |
|
69289
|
12 |
module Isabelle.Completion (
|
|
13 |
Name, T, names, none, make, markup_element, markup_report, make_report
|
|
14 |
) where
|
69288
|
15 |
|
|
16 |
import qualified Data.List as List
|
|
17 |
|
|
18 |
import Isabelle.Library
|
|
19 |
import qualified Isabelle.Properties as Properties
|
|
20 |
import qualified Isabelle.Markup as Markup
|
|
21 |
import qualified Isabelle.XML.Encode as Encode
|
|
22 |
import qualified Isabelle.XML as XML
|
|
23 |
import qualified Isabelle.YXML as YXML
|
|
24 |
|
|
25 |
|
|
26 |
type Name = (String, (String, String)) -- external name, kind, internal name
|
|
27 |
data T = Completion Properties.T Int [Name] -- position, total length, names
|
|
28 |
|
|
29 |
names :: Int -> Properties.T -> [Name] -> T
|
|
30 |
names limit props names = Completion props (length names) (take limit names)
|
|
31 |
|
|
32 |
none :: T
|
|
33 |
none = names 0 [] []
|
|
34 |
|
|
35 |
make :: Int -> (String, Properties.T) -> ((String -> Bool) -> [Name]) -> T
|
|
36 |
make limit (name, props) make_names =
|
|
37 |
if name /= "" && name /= "_"
|
|
38 |
then names limit props (make_names $ List.isPrefixOf $ clean_name name)
|
|
39 |
else none
|
|
40 |
|
69289
|
41 |
markup_element :: T -> (Markup.T, XML.Body)
|
|
42 |
markup_element (Completion props total names) =
|
|
43 |
if not (null names) then
|
|
44 |
let
|
|
45 |
markup = Markup.properties props Markup.completion
|
|
46 |
body =
|
|
47 |
Encode.pair Encode.int
|
|
48 |
(Encode.list (Encode.pair Encode.string (Encode.pair Encode.string Encode.string)))
|
|
49 |
(total, names)
|
|
50 |
in (markup, body)
|
|
51 |
else (Markup.empty, [])
|
69288
|
52 |
|
69289
|
53 |
markup_report :: [T] -> String
|
|
54 |
markup_report [] = ""
|
|
55 |
markup_report elems =
|
69290
|
56 |
YXML.string_of $ XML.Elem (Markup.report, map (XML.Elem . markup_element) elems)
|
69289
|
57 |
|
|
58 |
make_report :: Int -> (String, Properties.T) -> ((String -> Bool) -> [Name]) -> String
|
|
59 |
make_report limit name_props make_names =
|
|
60 |
markup_report [make limit name_props make_names]
|