summaryrefslogtreecommitdiffstats
path: root/txr.1
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-08-15 08:41:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-08-15 08:41:30 -0700
commit6742e3e96b3387bbea484c7278305cab1bd5397e (patch)
treef0fcf43a263172806aefb0b327d415d9c3dafb04 /txr.1
parent11ab30bd76f3cc28b364f79398229212e9537de1 (diff)
downloadtxr-6742e3e96b3387bbea484c7278305cab1bd5397e.tar.gz
txr-6742e3e96b3387bbea484c7278305cab1bd5397e.tar.bz2
txr-6742e3e96b3387bbea484c7278305cab1bd5397e.zip
Allow slashes in regex passed to regex-parse.
* parser.l (SREGEX): New start state, for stand-alone regex parsing. (grammar): All REGEX state rules are active in the SREGEX state also. The rule for the / character returns a REGCHAR if in the SREGEX state, so it is treated as an ordinary character. * txr.1: Updated regex-parse documentation about the treatment of the slash. Also added notes about double escaping when a string literal is passed to regex-parse.
Diffstat (limited to 'txr.1')
-rw-r--r--txr.135
1 files changed, 32 insertions, 3 deletions
diff --git a/txr.1 b/txr.1
index 154a5277..e7614a6b 100644
--- a/txr.1
+++ b/txr.1
@@ -24836,9 +24836,9 @@ stream.
.desc
The
.code regex-parse
-function parses a character string which contains a regular expression
-(without any surrounding / characters) and turns it into a Lisp data structure
-(the abstract syntax tree representation of the regular expression).
+function parses a character string which contains a regular expression and
+turns it into a Lisp data structure (the abstract syntax tree representation of
+the regular expression).
The regular expression syntax
.code #/RE/
@@ -24871,6 +24871,35 @@ value, that structure is then something
which is suitable as input to
.codn regex-compile .
+There is a small difference in the syntax accepted by
+.code regex-parse
+and the syntax of regular expression literals. Any
+.code /
+(slash) characters occurring in any position within
+.meta string
+are treated as ordinary characters, not as regular expression delimiters.
+The call
+.code (regex-parse "/a/")
+matches three characters: a slash, followed by the letter "a", followed
+by another slash. Note that the slashes are not escaped.
+
+Note: if a
+.code regex-parse
+call is written using a string literal as the
+.meta string
+argument, then note that any backslashes which are to be processed
+by the regular expression must be doubled up, otherwise they belong
+to the string literal:
+
+.cblk
+ (regex-parse "\e*") ;; error, invalid string literal escape
+ (regex-parse "\e\e*") ;; correct: the \e* literal match for *
+.cble
+
+The double backslash in the string literal produces a single backslash
+in the resulting string object that is processed by
+.codn regex-parse .
+
.SS* Hashing Library
.coNP Functions @, make-hash and @ hash
.synb