[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Scheme Mode and Regular Expression Literals
From: |
Stefan Monnier |
Subject: |
Re: Scheme Mode and Regular Expression Literals |
Date: |
Thu, 14 Mar 2024 09:34:10 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
> ((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`.
If they can span several lines then matching the whole #/.../ with
a regexp is definitely the wrong approach.
If not, that rule can be made to work but it has to check that the
leading #/ is not inside a string or comment.
The more robust approach is to match only #/ here and then use
a function which checks the resulting `syntax-ppss` to handle the rest
of the regexp.
See `octave-syntax-propertize-function` for an example of the structure
where we use the regexp "\\(?:^\\|[[({,; ]\\)\\('\\)" to match the
beginning of a quoted string, and then use
`octave-syntax-propertize-sqs` to process its contents (and use that as
well at the beginning of the function in case `syntax-propertize` is
called with start in the middle of such a string (or in our case,
regexp)).
Stefan