Skip to content

Instantly share code, notes, and snippets.

@yanndegat
Created March 6, 2021 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanndegat/329737d2bf28901d3cfdccae600537cc to your computer and use it in GitHub Desktop.
Save yanndegat/329737d2bf28901d3cfdccae600537cc to your computer and use it in GitHub Desktop.
gerbil srfi 115 issue
(import :std/srfi/115) [47/1454]
;; URL parsing regexp
;; this is roughly following the regexp in Appendix B of rfc 3986, except for using
;; `*' instead of `+' for the scheme part (it is checked later anyway, and
;; we don't want to parse it as a path element), and the user@host:port is
;; parsed here.
(define rx-url
(regexp '(+ bos
(?? ($ (* (~ (":/?#")))) ":") ; 1- scheme opt
(?? "//" ; slash-slash authority opt
(?? ($ (* (~ ("/?#@")))) "@") ; 2- user@ opt
(?? (or ;
(?? "[" ($ (* (or alnum ":")) ; 3- ipv6 host opt
":" ;
(* (or alnum ":"))) "]") ;
(?? ($ (* (~ ("/?#:"))))))) ; 4- host opt
(?? ":" ($ (* num)))) ; 5- :port opt
($ (* (~ ("?#")))) ; 6- path
(?? "?" ($ (* (~ ("#"))))) ; 7- query
(?? "#" ($ (* any))) ; 8- fragment
eos)))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
(displayln (regexp-match-submatch
(regexp-search rx-url "ssh://git@host.com:22/foo/bar.git?ref=master&foo=bar")
4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment