1
0
Fork 0

- 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:
cage 2022-08-29 17:44:24 +02:00
parent 9b6e6a9f15
commit 60f33d81a9
1 changed files with 27 additions and 6 deletions

View File

@ -316,11 +316,32 @@
(defun 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)
(let* ((parsed (iri:iri-parse iri))
(host (uri:host parsed))
(port (or (uri:port parsed) 70))
(path (uri:path parsed))
(type (second (fs:split-path-elements path)))
(selector (subseq path (+ 2 (length type)))))
(let* ((parsed (parse 'gopher-url iri))
(host (first parsed))
(port (second parsed))
(selector (third parsed))
(type (fourth parsed)))
(values host port type selector)))