summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/txr/stdlib/txr-case.tl2
-rw-r--r--tests/011/txr-case.expected1
-rw-r--r--tests/011/txr-case.txr12
-rw-r--r--txr.138
4 files changed, 48 insertions, 5 deletions
diff --git a/share/txr/stdlib/txr-case.tl b/share/txr/stdlib/txr-case.tl
index 4f51ea48..244c58b7 100644
--- a/share/txr/stdlib/txr-case.tl
+++ b/share/txr/stdlib/txr-case.tl
@@ -65,4 +65,6 @@
(defmacro txr-case (input-expr . clauses)
(let ((input (gensym "input-")))
^(let ((,input ,input-expr))
+ (if (streamp ,input)
+ (set ,input (get-lines ,input)))
(txr-case-impl ,input ,*clauses))))
diff --git a/tests/011/txr-case.expected b/tests/011/txr-case.expected
index 4af473e5..e7582780 100644
--- a/tests/011/txr-case.expected
+++ b/tests/011/txr-case.expected
@@ -2,3 +2,4 @@ no match for 09-10-20
match: year 2009, month 10, day 20
no match for July-15-2014
no match for foo
+match: year 2021, month 06, day 16, foo:bar
diff --git a/tests/011/txr-case.txr b/tests/011/txr-case.txr
index 1aa80478..aa234ed8 100644
--- a/tests/011/txr-case.txr
+++ b/tests/011/txr-case.txr
@@ -7,3 +7,15 @@
(txr-if date (y m d) date
(put-line `match: year @y, month @m, day @d`)
(put-line `no match for @date`))))
+@(define notmatch ())
+blah
+@(end)
+@(define stuff (year month day a b))
+@(date year month day)
+@a @b
+@(end)
+@(do (txr-case (make-strlist-input-stream '("2021-06-16"
+ "foo bar"))
+
+ (notmatch () (put-line "notexpected"))
+ (stuff (y m d a b) (put-line `match: year @y, month @m, day @d, @a:@b`))))
diff --git a/txr.1 b/txr.1
index 5a633d4c..1883130c 100644
--- a/txr.1
+++ b/txr.1
@@ -71237,11 +71237,17 @@ which will be interpreted as pattern variables, and may be bound or unbound.
If they are not symbols, then they are treated as expressions (of the
pattern language, not \*(TL) and evaluated accordingly.
-The
+The optional
.meta input
-argument is a list of strings, which may be lazy. It represents the
-lines of the text stream to be processed. If omitted, it defaults to
-.codn nil .
+argument is an object of one of several types. It may be a stream,
+character string or list of strings. If it is a string, then
+it is converted to a list containing that string.
+A list of strings represents zero or more lines of text to be
+processed. If the
+.meta input
+argument is omitted, then it defaults to
+.codn nil ,
+interpreted as an empty list of lines.
The
.meta files
@@ -71353,7 +71359,11 @@ macro invokes the \*(TX pattern matching function
.meta name
on some input given by the
.meta input
-parameter, which is a list of strings, or a single string.
+parameter, whose semantics are the same as the
+.meta input
+argument of the
+.code match-fun
+funtion.
If
.meta name
@@ -71515,6 +71525,24 @@ otherwise the forms are evaluated in order and the value of the last
one specifies the result of
.codn txr-case .
+The value of the input
+.meta input-form
+is expected to be one of the same kinds of objects as given by the
+requirements for the
+.meta input
+argument of the
+.code match-fun
+functions.
+
+If
+.meta input-form
+evaluates to a stream object according to the
+.code streamp
+function, then the stream is converted to a lazy list of lines,
+as if by invoking the
+.code get-lines
+function on that stream; that list then serves as input to the clauses.
+
.coNP Function @ txr-parse
.synb
.mets (txr-parse >> [ source >> [ error-stream