src/Pure/Tools/find_consts.ML
changeset 62848 e4140efe699e
parent 61335 43848476063c
child 62969 9f394a16c557
equal deleted inserted replaced
62847:1bd1d8492931 62848:e4140efe699e
     9 sig
     9 sig
    10   datatype criterion =
    10   datatype criterion =
    11       Strict of string
    11       Strict of string
    12     | Loose of string
    12     | Loose of string
    13     | Name of string
    13     | Name of string
       
    14   val pretty_consts: Proof.context -> (bool * criterion) list -> Pretty.T
       
    15   val query_parser: (bool * criterion) list parser
    14   val read_query: Position.T -> string -> (bool * criterion) list
    16   val read_query: Position.T -> string -> (bool * criterion) list
    15   val find_consts : Proof.context -> (bool * criterion) list -> unit
    17   val find_consts : Proof.context -> (bool * criterion) list -> unit
    16 end;
    18 end;
    17 
    19 
    18 structure Find_Consts : FIND_CONSTS =
    20 structure Find_Consts : FIND_CONSTS =
   136 val criterion =
   138 val criterion =
   137   Parse.reserved "name" |-- Parse.!!! (Parse.$$$ ":" |-- Parse.xname) >> Name ||
   139   Parse.reserved "name" |-- Parse.!!! (Parse.$$$ ":" |-- Parse.xname) >> Name ||
   138   Parse.reserved "strict" |-- Parse.!!! (Parse.$$$ ":" |-- Parse.typ) >> Strict ||
   140   Parse.reserved "strict" |-- Parse.!!! (Parse.$$$ ":" |-- Parse.typ) >> Strict ||
   139   Parse.typ >> Loose;
   141   Parse.typ >> Loose;
   140 
   142 
   141 val query = Scan.repeat ((Scan.option Parse.minus >> is_none) -- criterion);
       
   142 
       
   143 val query_keywords = Keyword.add_keywords [((":", @{here}), NONE)] Keyword.empty_keywords;
   143 val query_keywords = Keyword.add_keywords [((":", @{here}), NONE)] Keyword.empty_keywords;
   144 
   144 
   145 in
   145 in
   146 
   146 
       
   147 val query_parser = Scan.repeat ((Scan.option Parse.minus >> is_none) -- criterion);
       
   148 
   147 fun read_query pos str =
   149 fun read_query pos str =
   148   Token.explode query_keywords pos str
   150   Token.explode query_keywords pos str
   149   |> filter Token.is_proper
   151   |> filter Token.is_proper
   150   |> Scan.error (Scan.finite Token.stopper (Parse.!!! (query --| Scan.ahead Parse.eof)))
   152   |> Scan.error (Scan.finite Token.stopper (Parse.!!! (query_parser --| Scan.ahead Parse.eof)))
   151   |> #1;
   153   |> #1;
   152 
       
   153 val _ =
       
   154   Outer_Syntax.command @{command_keyword find_consts}
       
   155     "find constants by name / type patterns"
       
   156     (query >> (fn spec =>
       
   157       Toplevel.keep (fn st =>
       
   158         Pretty.writeln (pretty_consts (Toplevel.context_of st) spec))));
       
   159 
   154 
   160 end;
   155 end;
   161 
   156 
   162 
   157 
   163 (* PIDE query operation *)
   158 (* PIDE query operation *)