From 6471a30a58334aedb32f8fb90c720746306c8aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 1 May 2020 13:03:49 +0200 Subject: Server make-routes now support custom regexes. --- module/server/macro.scm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'module/server/macro.scm') 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))))))) -- cgit v1.2.3