diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-01 13:03:49 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2020-05-01 13:03:49 +0200 |
commit | 6471a30a58334aedb32f8fb90c720746306c8aae (patch) | |
tree | 189bd049db7772d1a879e3baa788056170e1e325 /module | |
parent | Update error on /calendar/ endpoint. (diff) | |
download | calp-6471a30a58334aedb32f8fb90c720746306c8aae.tar.gz calp-6471a30a58334aedb32f8fb90c720746306c8aae.tar.xz |
Server make-routes now support custom regexes.
Diffstat (limited to '')
-rw-r--r-- | module/server/macro.scm | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/module/server/macro.scm b/module/server/macro.scm index b9ce94bb..28565c3b 100644 --- a/module/server/macro.scm +++ b/module/server/macro.scm @@ -9,15 +9,28 @@ (define-public (parse-endpoint-string str) - (let ((rx (make-regexp ":([^/.]+)"))) + (let ((rx (make-regexp ":([^/.]+)(\\{([^}]+)\\})?([.])?"))) (let loop ((str str) (string "") (tokens '())) (let ((m (regexp-exec rx str 0))) (if (not m) + ;; done (values (string-append string str) (reverse tokens)) + (loop (match:suffix m) - (string-append string (match:prefix m) "([^/.]+)") + (string-append string (match:prefix m) + (aif (match:substring m 3) + (string-append "(" it ")") + "([^/.]+)") + ;; period directly following matched variable. + ;; since many variables break on period, we often + ;; want to match a literal period directly after them. + ;; Ideally all periods outside of pattern should be + ;; matched literally, but that's harder to implement. + (regexp-quote + (aif (match:substring m 4) + "." ""))) (cons (string->symbol (match:substring m 1)) tokens))))))) |