mirror of https://codeberg.org/cage/tinmop/
- added a new parser just for gopher address; they are not IRI as the
selector part can contains arbitrary characters even that ones that are not allowed in IRI's path component.
This commit is contained in:
parent
9b6e6a9f15
commit
60f33d81a9
|
@ -316,11 +316,32 @@
|
||||||
(defun parse-text-file (data)
|
(defun parse-text-file (data)
|
||||||
(parse 'text-file data))
|
(parse 'text-file data))
|
||||||
|
|
||||||
|
(defrule gopher-url (and (+ (not #\:))
|
||||||
|
"://"
|
||||||
|
(or (and (+ (not #\:))
|
||||||
|
#\:
|
||||||
|
(+ (not #\/))
|
||||||
|
#\/)
|
||||||
|
(and (+ (not #\/))
|
||||||
|
#\/))
|
||||||
|
(and (+ (not #\/))
|
||||||
|
#\/)
|
||||||
|
(* (character-ranges (#\u0000 #\uffff))))
|
||||||
|
(:function (lambda (a)
|
||||||
|
(let* ((host-port (third a))
|
||||||
|
(host (coerce (first host-port) 'string))
|
||||||
|
(port (if (third host-port)
|
||||||
|
(parse-integer (coerce (third host-port) 'string))
|
||||||
|
70))
|
||||||
|
(type-path (fourth a))
|
||||||
|
(type (coerce (car type-path) 'string))
|
||||||
|
(path (coerce (fifth a) 'string)))
|
||||||
|
(list host port path type)))))
|
||||||
|
|
||||||
(defun parse-iri (iri)
|
(defun parse-iri (iri)
|
||||||
(let* ((parsed (iri:iri-parse iri))
|
(let* ((parsed (parse 'gopher-url iri))
|
||||||
(host (uri:host parsed))
|
(host (first parsed))
|
||||||
(port (or (uri:port parsed) 70))
|
(port (second parsed))
|
||||||
(path (uri:path parsed))
|
(selector (third parsed))
|
||||||
(type (second (fs:split-path-elements path)))
|
(type (fourth parsed)))
|
||||||
(selector (subseq path (+ 2 (length type)))))
|
|
||||||
(values host port type selector)))
|
(values host port type selector)))
|
||||||
|
|
Loading…
Reference in New Issue