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 |