[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme Mode and Regular Expression Literals
From: |
Mattias Engdegård |
Subject: |
Re: Scheme Mode and Regular Expression Literals |
Date: |
Thu, 14 Mar 2024 12:38:53 +0100 |
> (syntax-propertize-rules
> + ;; For #/regexp/ syntax
> + ("\\(#\\)/\\(\\\\/\\|\\\\\\\\\\|.\\)*?\\(/\\)"
> + (1 "|")
> + (3 "|"))
That amount of leaning toothpicks confuses even someone used to reading Elisp
regexps so I'm switching notation here (`syntax-propertize-rules` permits
regexps in rx). The above means:
((rx (group "#") "/"
(*? (group (| "\\/" "\\\\" nonl)))
(group "/"))
(1 "|")
(3 "|"))
This is a tad too ambiguous; it will match "#/ab\/", for instance, which
probably wasn't intended.
What about the more robust
((rx (group "#") "/"
(* (| (: "\\" nonl)
(not (in "\n/\\"))))
(group "/"))
(1 "|")
(2 "|"))
instead?
The Gauche documentation isn't entirely clear on how literal newlines are lexed
inside this construct.
If newlines can be part of regexp literals, remove the \n from the third line.
If backslashed newlines are allowed, change `nonl` to `anychar`.