src/Pure/General/url.ML
changeset 16195 0eb3c15298cd
parent 15627 7a108ae4c798
child 19305 5c16895d548b
equal deleted inserted replaced
16194:3d192ab9907b 16195:0eb3c15298cd
     1 (*  Title:      Pure/General/url.ML
     1 (*  Title:      Pure/General/url.ML
     2     ID:         $Id$
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     4 
     5 Basic URLs.  See RFC 1738.
     5 Basic URLs, see RFC 1738.
     6 *)
     6 *)
     7 
     7 
     8 signature URL =
     8 signature URL =
     9 sig
     9 sig
    10   datatype T =
    10   datatype T =
    50 
    50 
    51 (* unpack *)
    51 (* unpack *)
    52 
    52 
    53 local
    53 local
    54 
    54 
    55 fun gen_host quant = (quant (not_equal "/" andf Symbol.not_eof) >> implode) --|
    55 val scan_host =
       
    56   (Scan.any1 (not_equal "/" andf Symbol.not_eof) >> implode) --|
    56   Scan.ahead ($$ "/" || Scan.one Symbol.is_eof);
    57   Scan.ahead ($$ "/" || Scan.one Symbol.is_eof);
    57 
    58 
    58 val scan_host1 = gen_host Scan.any1;
       
    59 val scan_path = Scan.any Symbol.not_eof >> (Path.unpack o implode);
    59 val scan_path = Scan.any Symbol.not_eof >> (Path.unpack o implode);
    60 val scan_path_root = Scan.any Symbol.not_eof >> (Path.unpack o (curry (op^) "/") o implode);
    60 val scan_path_root = Scan.any Symbol.not_eof >> (Path.unpack o implode o cons "/");
    61 
    61 
    62 val scan_url =
    62 val scan_url =
    63   Scan.unless (Scan.this_string "file:" ||
    63   Scan.unless (Scan.this_string "file:" ||
    64     Scan.this_string "http:" || Scan.this_string "ftp:") scan_path >> File ||
    64     Scan.this_string "http:" || Scan.this_string "ftp:") scan_path >> File ||
    65   Scan.this_string "file:///" |-- scan_path_root >> File ||
    65   Scan.this_string "file:///" |-- scan_path_root >> File ||
    66   Scan.this_string "file://localhost/" |-- scan_path_root >> File ||
    66   Scan.this_string "file://localhost/" |-- scan_path_root >> File ||
    67   Scan.this_string "file://" |-- scan_host1 -- scan_path >> RemoteFile ||
    67   Scan.this_string "file://" |-- scan_host -- scan_path >> RemoteFile ||
    68   Scan.this_string "http://" |-- scan_host1 -- scan_path >> Http ||
    68   Scan.this_string "http://" |-- scan_host -- scan_path >> Http ||
    69   Scan.this_string "ftp://" |-- scan_host1 -- scan_path >> Ftp ||
    69   Scan.this_string "ftp://" |-- scan_host -- scan_path >> Ftp;
    70   Scan.this_string "file://" |-- scan_host1 -- scan_path >> Ftp (* or other proto *)
       
    71 
    70 
    72 in
    71 in
    73 
    72 
    74 fun unpack s = Symbol.scanner "Malformed URL" scan_url (Symbol.explode s);
    73 fun unpack s = Symbol.scanner "Malformed URL" scan_url (Symbol.explode s);
    75 
    74