aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2024-07-26 09:28:35 +1000
committerSteve Bennett <steveb@workware.net.au>2024-07-26 09:28:35 +1000
commita129dd0bf423a62089408151594ad11da76813fb (patch)
treeb79c647134ea25349dd70efee9cc50e293faae73
parentfd88168e21ae05cd42b26056eae400ea3df48046 (diff)
downloadjimtcl-leval.zip
jimtcl-leval.tar.gz
jimtcl-leval.tar.bz2
leval is now lsubstleval
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim.c22
-rw-r--r--jim_tcl.txt16
-rw-r--r--tests/lsubst.test (renamed from tests/leval.test)70
3 files changed, 54 insertions, 54 deletions
diff --git a/jim.c b/jim.c
index c87658c..f487c73 100644
--- a/jim.c
+++ b/jim.c
@@ -11136,16 +11136,16 @@ static Jim_Obj *JimInterpolateTokens(Jim_Interp *interp, const ScriptToken * tok
return objPtr;
}
-#define JIM_LEVAL_LINE 0x0001
+#define JIM_LSUBST_LINE 0x0001
-/* Parse a string as an 'leval' argument and sets the interp result.
+/* Parse a string as an 'lsubst' argument and sets the interp result.
* Return JIM_OK if ok, or JIM_ERR on error.
*
* Modelled on Jim_EvalObj()
*
- * If flags contains JIM_LEVAL_LINE, each "statement" is returned as list of {command arg...}
+ * If flags contains JIM_LSUBST_LINE, each "statement" is returned as list of {command arg...}
*/
-static int JimListEvalObj(Jim_Interp *interp, struct Jim_Obj *objPtr, unsigned flags)
+static int JimListSubstObj(Jim_Interp *interp, struct Jim_Obj *objPtr, unsigned flags)
{
int i;
ScriptObj *script;
@@ -11181,7 +11181,7 @@ static int JimListEvalObj(Jim_Interp *interp, struct Jim_Obj *objPtr, unsigned f
/* Skip the JIM_TT_LINE token */
i++;
- if (flags & JIM_LEVAL_LINE) {
+ if (flags & JIM_LSUBST_LINE) {
lineListObj = Jim_NewListObj(interp, NULL, 0);
}
@@ -11225,7 +11225,7 @@ static int JimListEvalObj(Jim_Interp *interp, struct Jim_Obj *objPtr, unsigned f
Jim_DecrRefCount(interp, wordObjPtr);
}
- if (flags & JIM_LEVAL_LINE) {
+ if (flags & JIM_LSUBST_LINE) {
Jim_ListAppendElement(interp, resultListObj, lineListObj);
}
}
@@ -15701,14 +15701,14 @@ static int Jim_SubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *ar
return JIM_OK;
}
-/* [leval] */
-static int Jim_LevalCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+/* [lsubst] */
+static int Jim_LsubstCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
if (argc == 2) {
- return JimListEvalObj(interp, argv[1], 0);
+ return JimListSubstObj(interp, argv[1], 0);
}
if (argc == 3 && Jim_CompareStringImmediate(interp, argv[1], "-line")) {
- return JimListEvalObj(interp, argv[2], JIM_LEVAL_LINE);
+ return JimListSubstObj(interp, argv[2], JIM_LSUBST_LINE);
}
Jim_WrongNumArgs(interp, 1, argv, "?-line? string");
return JIM_ERR;
@@ -16620,7 +16620,7 @@ static const struct {
{"rename", Jim_RenameCoreCommand},
{"dict", Jim_DictCoreCommand},
{"subst", Jim_SubstCoreCommand},
- {"leval", Jim_LevalCoreCommand},
+ {"lsubst", Jim_LsubstCoreCommand},
{"info", Jim_InfoCoreCommand},
{"exists", Jim_ExistsCoreCommand},
{"split", Jim_SplitCoreCommand},
diff --git a/jim_tcl.txt b/jim_tcl.txt
index e63bad3..c23e87c 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -63,7 +63,7 @@ Changes since 0.82
7. Add support for hinting with `history hints`
8. Support for `proc` statics by reference (lexical closure) rather than by value
9. `regsub` now supports '-command' (per Tcl 8.7)
-10. New `leval` command to create lists using subst-style substitution
+10. New `lsubst` command to create lists using subst-style substitution
Changes between 0.81 and 0.82
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -3121,10 +3121,10 @@ than variables, a list of unassigned elements is returned.
a=1,b=2
----
-leval
+lsubst
~~~~
-+*leval ?-line?* 'string'+
++*lsubst ?-line?* 'string'+
This command is similar to `list` in that it creates a list, but uses
the same rules as scripts when constructing the elements of the list.
@@ -3139,7 +3139,7 @@ Consider the following example.
set x 1
set y {2 3}
set z 3
- leval {
+ lsubst {
# This is a list with interpolation
$x; # The x variable
{*}$y; # The y variable expanded
@@ -3149,7 +3149,7 @@ Consider the following example.
}
---
-The result of `leval` is the following list with 7 elements.
+The result of `lsubst` is the following list with 7 elements.
---
1 2 3 abc 4 5 33
@@ -3160,12 +3160,12 @@ as a data structure as it easily allows for comments and variable and command
substitution.
Sometimes it is useful to return each "command" as a separate list rather than
-simply running all the words together. This can be accomplished with `leval -line`.
+simply running all the words together. This can be accomplished with `lsubst -line`.
Consider the following example.
---
- leval -line {
+ lsubst -line {
# two "lines" because of the semicolon
one a; two b
# one line with three elements
@@ -3173,7 +3173,7 @@ Consider the following example.
}
---
-The result of `leval -line` is the following list with 3 elements, one for each "command".
+The result of `lsubst -line` is the following list with 3 elements, one for each "command".
---
{one a} {two b} {a b c}
diff --git a/tests/leval.test b/tests/lsubst.test
index f65e82a..1c2c082 100644
--- a/tests/leval.test
+++ b/tests/lsubst.test
@@ -1,31 +1,31 @@
source [file dirname [info script]]/testing.tcl
-needs cmd leval
+needs cmd lsubst
-test leval-1.1 {no args} -body {
- leval
-} -returnCodes error -result {wrong # args: should be "leval ?-line? string"}
+test lsubst-1.1 {no args} -body {
+ lsubst
+} -returnCodes error -result {wrong # args: should be "lsubst ?-line? string"}
-test leval-1.2 {too many args} -body {
- leval a b c
-} -returnCodes error -result {wrong # args: should be "leval ?-line? string"}
+test lsubst-1.2 {too many args} -body {
+ lsubst a b c
+} -returnCodes error -result {wrong # args: should be "lsubst ?-line? string"}
-test leval-1.3 {basic, no subst} -body {
- leval {a b c}
+test lsubst-1.3 {basic, no subst} -body {
+ lsubst {a b c}
} -result {a b c}
-test leval-1.4 {basics, vars} -body {
+test lsubst-1.4 {basics, vars} -body {
set a 1
set b "2 3"
set c "4 5 6"
set d ".1"
- leval {$a $b $c$d}
+ lsubst {$a $b $c$d}
} -result {1 {2 3} {4 5 6.1}}
-test leval-1.5 {comments} -body {
+test lsubst-1.5 {comments} -body {
# It is helpful to be able to include comments in a list definition
# just like in a script
- leval {
+ lsubst {
# comment line
1
2 3
@@ -36,9 +36,9 @@ test leval-1.5 {comments} -body {
}
} -result {1 2 3 4 5}
-test leval-1.6 {commands} -body {
+test lsubst-1.6 {commands} -body {
set a 0
- leval {
+ lsubst {
[incr a]
[incr a]
[list d e]
@@ -46,24 +46,24 @@ test leval-1.6 {commands} -body {
}
} -result {1 2 {d e} fghi}
-test leval-1.7 {expand} -body {
+test lsubst-1.7 {expand} -body {
set a {1 2}
set space " "
set b {3 4 5}
- leval {
+ lsubst {
{*}$a
{*}$a$space$b$space[list 6 7]
}
} -result {1 2 1 2 3 4 5 6 7}
-test leval-1.8 {empty case} -body {
- leval {
+test lsubst-1.8 {empty case} -body {
+ lsubst {
# Nothing
}
} -result {}
-test leval-1.9 {backslash escapes} -body {
- leval {
+test lsubst-1.9 {backslash escapes} -body {
+ lsubst {
# char escapes
\r\n\t
# unicode escapes
@@ -73,10 +73,10 @@ test leval-1.9 {backslash escapes} -body {
}
} -result [list \r\n\t \u00b5 AB]
-test leval-1.10 {simple -line} -body {
+test lsubst-1.10 {simple -line} -body {
set a {1 2}
set b {3 4 5}
- leval -line {
+ lsubst -line {
# This line won't produce a list, but the next will produce a list with two elements
{*}$a
# And this one will have three elements
@@ -84,49 +84,49 @@ test leval-1.10 {simple -line} -body {
}
} -result {{1 2} {one two {3 4 5}}}
-test leval-2.1 {error, missing [} -body {
- leval {
+test lsubst-2.1 {error, missing [} -body {
+ lsubst {
# Missing bracket
[string cat
}
} -returnCodes error -result {unmatched "["}
-test leval-2.2 {error, invalid command} -body {
- leval {
+test lsubst-2.2 {error, invalid command} -body {
+ lsubst {
a
[dummy]
b
}
} -returnCodes error -result {invalid command name "dummy"}
-test leval-2.3 {error, unset variable} -body {
- leval {
+test lsubst-2.3 {error, unset variable} -body {
+ lsubst {
a
$doesnotexist
b
}
} -returnCodes error -result {can't read "doesnotexist": no such variable}
-test leval-2.4 {break} -body {
- leval {
+test lsubst-2.4 {break} -body {
+ lsubst {
a
[break]
b
}
} -returnCodes error -result {invoked "break" outside of a loop}
-test leval-2.5 {continue} -body {
- leval {
+test lsubst-2.5 {continue} -body {
+ lsubst {
a
[continue]
b
}
} -returnCodes error -result {invoked "continue" outside of a loop}
-test leval-3.1 {preservation of line numbers} -body {
+test lsubst-3.1 {preservation of line numbers} -body {
set x abc
set src1 [info source $x]
- set list [leval {
+ set list [lsubst {
a
$x
b