Skip to content

Commit 9c29f0c

Browse files
authored
Multiple on-line-help issues from #908 (#913)
* Populate help strings for systime, systimeint, and uptime DSL functions * Extend help strings for joink, joinv, and joinkv * Expand on-line help for ssub/sub/gsub * doc artifacts
1 parent 4a2d772 commit 9c29f0c

File tree

7 files changed

+144
-56
lines changed

7 files changed

+144
-56
lines changed

docs/src/csv-with-and-without-headers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ a,b,c
238238
<pre class="pre-non-highlight-in-pair">
239239
a,b,c
240240
1,2,3
241-
4,5
241+
4,5,
242242
6,7,8,9
243243
</pre>
244244

@@ -255,7 +255,7 @@ or, more simply,
255255
<pre class="pre-non-highlight-in-pair">
256256
a,b,c
257257
1,2,3
258-
4,5
258+
4,5,
259259
6,7,8,9
260260
</pre>
261261

docs/src/manpage.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,12 @@ FUNCTIONS FOR FILTER/PUT
22232223

22242224
gsub
22252225
(class=string #args=3) '$name=gsub($name, "old", "new")' (replace all).
2226+
Examples:
2227+
gsub("ababab", "ab", "XY") gives "XYXYXY"
2228+
gsub("abc.def", ".", "X") gives "XXXXXXX"
2229+
gsub("abc.def", "\.", "X") gives "abcXdef"
2230+
gsub("abcdefg", "[ce]", "X") gives "abXdXfg"
2231+
gsub("prefix4529:suffix8567", "(....ix)([0-9]+)", "[\1 : \2]") gives "[prefix : 4529]:[suffix : 8567]"
22262232

22272233
haskey
22282234
(class=collections #args=2) True/false if map has/hasn't key, e.g. 'haskey($*, "a")' or 'haskey(mymap, mykey)', or true/false if array index is in bounds / out of bounds. Error if 1st argument is not a map or array. Note -n..-1 alias to 1..n in Miller arrays.
@@ -2303,19 +2309,19 @@ FUNCTIONS FOR FILTER/PUT
23032309
(class=typing #args=1) True if field is present with string (including empty-string) value
23042310

23052311
joink
2306-
(class=conversion #args=2) Makes string from map/array keys.
2312+
(class=conversion #args=2) Makes string from map/array keys. First argument is map/array; second is separator string.
23072313
Examples:
23082314
joink({"a":3,"b":4,"c":5}, ",") = "a,b,c".
23092315
joink([1,2,3], ",") = "1,2,3".
23102316

23112317
joinkv
2312-
(class=conversion #args=3) Makes string from map/array key-value pairs.
2318+
(class=conversion #args=3) Makes string from map/array key-value pairs. First argument is map/array; second is pair-separator string; third is field-separator string. Mnemonic: the "=" comes before the "," in the output and in the arguments to joinkv.
23132319
Examples:
23142320
joinkv([3,4,5], "=", ",") = "1=3,2=4,3=5"
2315-
joinkv({"a":3,"b":4,"c":5}, "=", ",") = "a=3,b=4,c=5"
2321+
joinkv({"a":3,"b":4,"c":5}, ":", ";") = "a:3;b:4;c:5"
23162322

23172323
joinv
2318-
(class=conversion #args=2) Makes string from map/array values.
2324+
(class=conversion #args=2) Makes string from map/array values. First argument is map/array; second is separator string.
23192325
Examples:
23202326
joinv([3,4,5], ",") = "3,4,5"
23212327
joinv({"a":3,"b":4,"c":5}, ",") = "3,4,5"
@@ -2519,6 +2525,8 @@ FUNCTIONS FOR FILTER/PUT
25192525

25202526
ssub
25212527
(class=string #args=3) Like sub but does no regexing. No characters are special.
2528+
Example:
2529+
ssub("abc.def", ".", "X") gives "abcXdef"
25222530

25232531
strftime
25242532
(class=time #args=2) Formats seconds since the epoch as timestamp. Format strings are as in the C library (please see "man strftime" on your system), with the Miller-specific addition of "%1S" through "%9S" which format the seconds with 1 through 9 decimal places, respectively. ("%S" uses no decimal places.) See also strftime_local.
@@ -2560,6 +2568,12 @@ FUNCTIONS FOR FILTER/PUT
25602568

25612569
sub
25622570
(class=string #args=3) '$name=sub($name, "old", "new")' (replace once).
2571+
Examples:
2572+
sub("ababab", "ab", "XY") gives "XYabab"
2573+
sub("abc.def", ".", "X") gives "Xbc.def"
2574+
sub("abc.def", "\.", "X") gives "abcXdef"
2575+
sub("abcdefg", "[ce]", "X") gives "abXdefg"
2576+
sub("prefix4529:suffix8567", "suffix([0-9]+)", "name\1") gives "prefix4529:name8567"
25632577

25642578
substr
25652579
(class=string #args=3) substr is an alias for substr0. See also substr1. Miller is generally 1-up with all array and string indices, but, this is a backward-compatibility issue with Miller 5 and below. Arrays are new in Miller 6; the substr function is older.
@@ -2574,10 +2588,10 @@ FUNCTIONS FOR FILTER/PUT
25742588
(class=system #args=1) Run command string, yielding its stdout minus final carriage return.
25752589

25762590
systime
2577-
(class=time #args=0) help string will go here
2591+
(class=time #args=0) Returns the system time in floating-point seconds since the epoch.
25782592

25792593
systimeint
2580-
(class=time #args=0) help string will go here
2594+
(class=time #args=0) Returns the system time in integer seconds since the epoch.
25812595

25822596
tan
25832597
(class=math #args=1) Trigonometric tangent.
@@ -2617,7 +2631,7 @@ FUNCTIONS FOR FILTER/PUT
26172631
is_error(unformatx("{}h{}m{}s", "3:47:22")) gives true.
26182632

26192633
uptime
2620-
(class=time #args=0) help string will go here
2634+
(class=time #args=0) Returns the time in floating-point seconds since the current Miller program was started.
26212635

26222636
urand
26232637
(class=math #args=0) Floating-point numbers uniformly distributed on the unit interval.
@@ -3134,5 +3148,5 @@ SEE ALSO
31343148

31353149

31363150

3137-
2022-02-01 MILLER(1)
3151+
2022-02-05 MILLER(1)
31383152
</pre>

docs/src/manpage.txt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,6 +2202,12 @@ FUNCTIONS FOR FILTER/PUT
22022202

22032203
gsub
22042204
(class=string #args=3) '$name=gsub($name, "old", "new")' (replace all).
2205+
Examples:
2206+
gsub("ababab", "ab", "XY") gives "XYXYXY"
2207+
gsub("abc.def", ".", "X") gives "XXXXXXX"
2208+
gsub("abc.def", "\.", "X") gives "abcXdef"
2209+
gsub("abcdefg", "[ce]", "X") gives "abXdXfg"
2210+
gsub("prefix4529:suffix8567", "(....ix)([0-9]+)", "[\1 : \2]") gives "[prefix : 4529]:[suffix : 8567]"
22052211

22062212
haskey
22072213
(class=collections #args=2) True/false if map has/hasn't key, e.g. 'haskey($*, "a")' or 'haskey(mymap, mykey)', or true/false if array index is in bounds / out of bounds. Error if 1st argument is not a map or array. Note -n..-1 alias to 1..n in Miller arrays.
@@ -2282,19 +2288,19 @@ FUNCTIONS FOR FILTER/PUT
22822288
(class=typing #args=1) True if field is present with string (including empty-string) value
22832289

22842290
joink
2285-
(class=conversion #args=2) Makes string from map/array keys.
2291+
(class=conversion #args=2) Makes string from map/array keys. First argument is map/array; second is separator string.
22862292
Examples:
22872293
joink({"a":3,"b":4,"c":5}, ",") = "a,b,c".
22882294
joink([1,2,3], ",") = "1,2,3".
22892295

22902296
joinkv
2291-
(class=conversion #args=3) Makes string from map/array key-value pairs.
2297+
(class=conversion #args=3) Makes string from map/array key-value pairs. First argument is map/array; second is pair-separator string; third is field-separator string. Mnemonic: the "=" comes before the "," in the output and in the arguments to joinkv.
22922298
Examples:
22932299
joinkv([3,4,5], "=", ",") = "1=3,2=4,3=5"
2294-
joinkv({"a":3,"b":4,"c":5}, "=", ",") = "a=3,b=4,c=5"
2300+
joinkv({"a":3,"b":4,"c":5}, ":", ";") = "a:3;b:4;c:5"
22952301

22962302
joinv
2297-
(class=conversion #args=2) Makes string from map/array values.
2303+
(class=conversion #args=2) Makes string from map/array values. First argument is map/array; second is separator string.
22982304
Examples:
22992305
joinv([3,4,5], ",") = "3,4,5"
23002306
joinv({"a":3,"b":4,"c":5}, ",") = "3,4,5"
@@ -2498,6 +2504,8 @@ FUNCTIONS FOR FILTER/PUT
24982504

24992505
ssub
25002506
(class=string #args=3) Like sub but does no regexing. No characters are special.
2507+
Example:
2508+
ssub("abc.def", ".", "X") gives "abcXdef"
25012509

25022510
strftime
25032511
(class=time #args=2) Formats seconds since the epoch as timestamp. Format strings are as in the C library (please see "man strftime" on your system), with the Miller-specific addition of "%1S" through "%9S" which format the seconds with 1 through 9 decimal places, respectively. ("%S" uses no decimal places.) See also strftime_local.
@@ -2539,6 +2547,12 @@ FUNCTIONS FOR FILTER/PUT
25392547

25402548
sub
25412549
(class=string #args=3) '$name=sub($name, "old", "new")' (replace once).
2550+
Examples:
2551+
sub("ababab", "ab", "XY") gives "XYabab"
2552+
sub("abc.def", ".", "X") gives "Xbc.def"
2553+
sub("abc.def", "\.", "X") gives "abcXdef"
2554+
sub("abcdefg", "[ce]", "X") gives "abXdefg"
2555+
sub("prefix4529:suffix8567", "suffix([0-9]+)", "name\1") gives "prefix4529:name8567"
25422556

25432557
substr
25442558
(class=string #args=3) substr is an alias for substr0. See also substr1. Miller is generally 1-up with all array and string indices, but, this is a backward-compatibility issue with Miller 5 and below. Arrays are new in Miller 6; the substr function is older.
@@ -2553,10 +2567,10 @@ FUNCTIONS FOR FILTER/PUT
25532567
(class=system #args=1) Run command string, yielding its stdout minus final carriage return.
25542568

25552569
systime
2556-
(class=time #args=0) help string will go here
2570+
(class=time #args=0) Returns the system time in floating-point seconds since the epoch.
25572571

25582572
systimeint
2559-
(class=time #args=0) help string will go here
2573+
(class=time #args=0) Returns the system time in integer seconds since the epoch.
25602574

25612575
tan
25622576
(class=math #args=1) Trigonometric tangent.
@@ -2596,7 +2610,7 @@ FUNCTIONS FOR FILTER/PUT
25962610
is_error(unformatx("{}h{}m{}s", "3:47:22")) gives true.
25972611

25982612
uptime
2599-
(class=time #args=0) help string will go here
2613+
(class=time #args=0) Returns the time in floating-point seconds since the current Miller program was started.
26002614

26012615
urand
26022616
(class=math #args=0) Floating-point numbers uniformly distributed on the unit interval.
@@ -3113,4 +3127,4 @@ SEE ALSO
31133127

31143128

31153129

3116-
2022-02-01 MILLER(1)
3130+
2022-02-05 MILLER(1)

docs/src/reference-dsl-builtin-functions.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ int (class=conversion #args=1) Convert int/float/bool/string to int.
505505

506506
### joink
507507
<pre class="pre-non-highlight-non-pair">
508-
joink (class=conversion #args=2) Makes string from map/array keys.
508+
joink (class=conversion #args=2) Makes string from map/array keys. First argument is map/array; second is separator string.
509509
Examples:
510510
joink({"a":3,"b":4,"c":5}, ",") = "a,b,c".
511511
joink([1,2,3], ",") = "1,2,3".
@@ -514,16 +514,16 @@ joink([1,2,3], ",") = "1,2,3".
514514

515515
### joinkv
516516
<pre class="pre-non-highlight-non-pair">
517-
joinkv (class=conversion #args=3) Makes string from map/array key-value pairs.
517+
joinkv (class=conversion #args=3) Makes string from map/array key-value pairs. First argument is map/array; second is pair-separator string; third is field-separator string. Mnemonic: the "=" comes before the "," in the output and in the arguments to joinkv.
518518
Examples:
519519
joinkv([3,4,5], "=", ",") = "1=3,2=4,3=5"
520-
joinkv({"a":3,"b":4,"c":5}, "=", ",") = "a=3,b=4,c=5"
520+
joinkv({"a":3,"b":4,"c":5}, ":", ";") = "a:3;b:4;c:5"
521521
</pre>
522522

523523

524524
### joinv
525525
<pre class="pre-non-highlight-non-pair">
526-
joinv (class=conversion #args=2) Makes string from map/array values.
526+
joinv (class=conversion #args=2) Makes string from map/array values. First argument is map/array; second is separator string.
527527
Examples:
528528
joinv([3,4,5], ",") = "3,4,5"
529529
joinv({"a":3,"b":4,"c":5}, ",") = "3,4,5"
@@ -940,6 +940,12 @@ format("{}:{}:{}", 1,2,3,4) gives "1:2:3".
940940
### gsub
941941
<pre class="pre-non-highlight-non-pair">
942942
gsub (class=string #args=3) '$name=gsub($name, "old", "new")' (replace all).
943+
Examples:
944+
gsub("ababab", "ab", "XY") gives "XYXYXY"
945+
gsub("abc.def", ".", "X") gives "XXXXXXX"
946+
gsub("abc.def", "\.", "X") gives "abcXdef"
947+
gsub("abcdefg", "[ce]", "X") gives "abXdXfg"
948+
gsub("prefix4529:suffix8567", "(....ix)([0-9]+)", "[\1 : \2]") gives "[prefix : 4529]:[suffix : 8567]"
943949
</pre>
944950

945951

@@ -970,6 +976,8 @@ rstrip (class=string #args=1) Strip trailing whitespace from string.
970976
### ssub
971977
<pre class="pre-non-highlight-non-pair">
972978
ssub (class=string #args=3) Like sub but does no regexing. No characters are special.
979+
Example:
980+
ssub("abc.def", ".", "X") gives "abcXdef"
973981
</pre>
974982

975983

@@ -988,6 +996,12 @@ strlen (class=string #args=1) String length.
988996
### sub
989997
<pre class="pre-non-highlight-non-pair">
990998
sub (class=string #args=3) '$name=sub($name, "old", "new")' (replace once).
999+
Examples:
1000+
sub("ababab", "ab", "XY") gives "XYabab"
1001+
sub("abc.def", ".", "X") gives "Xbc.def"
1002+
sub("abc.def", "\.", "X") gives "abcXdef"
1003+
sub("abcdefg", "[ce]", "X") gives "abXdefg"
1004+
sub("prefix4529:suffix8567", "suffix([0-9]+)", "name\1") gives "prefix4529:name8567"
9911005
</pre>
9921006

9931007

@@ -1246,19 +1260,19 @@ strptime_local("2015-08-28 13:33:21", "%Y-%m-%d %H:%M:%S", "Asia/Istanbul")
12461260

12471261
### systime
12481262
<pre class="pre-non-highlight-non-pair">
1249-
systime (class=time #args=0) help string will go here
1263+
systime (class=time #args=0) Returns the system time in floating-point seconds since the epoch.
12501264
</pre>
12511265

12521266

12531267
### systimeint
12541268
<pre class="pre-non-highlight-non-pair">
1255-
systimeint (class=time #args=0) help string will go here
1269+
systimeint (class=time #args=0) Returns the system time in integer seconds since the epoch.
12561270
</pre>
12571271

12581272

12591273
### uptime
12601274
<pre class="pre-non-highlight-non-pair">
1261-
uptime (class=time #args=0) help string will go here
1275+
uptime (class=time #args=0) Returns the time in floating-point seconds since the current Miller program was started.
12621276
</pre>
12631277

12641278
## Typing functions

internal/pkg/dsl/cst/builtin_function_manager.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,6 @@ func makeBuiltinFunctionLookupTable() []BuiltinFunctionInfo {
403403
unaryFunc: bifs.BIF_collapse_whitespace,
404404
},
405405

406-
{
407-
name: "gsub",
408-
class: FUNC_CLASS_STRING,
409-
help: `'$name=gsub($name, "old", "new")' (replace all).`,
410-
ternaryFunc: bifs.BIF_gsub,
411-
},
412-
413406
{
414407
name: "lstrip",
415408
class: FUNC_CLASS_STRING,
@@ -457,13 +450,37 @@ func makeBuiltinFunctionLookupTable() []BuiltinFunctionInfo {
457450
class: FUNC_CLASS_STRING,
458451
help: `Like sub but does no regexing. No characters are special.`,
459452
ternaryFunc: bifs.BIF_ssub,
453+
examples: []string{
454+
`ssub("abc.def", ".", "X") gives "abcXdef"`,
455+
},
460456
},
461457

462458
{
463459
name: "sub",
464460
class: FUNC_CLASS_STRING,
465461
help: `'$name=sub($name, "old", "new")' (replace once).`,
466462
ternaryFunc: bifs.BIF_sub,
463+
examples: []string{
464+
`sub("ababab", "ab", "XY") gives "XYabab"`,
465+
`sub("abc.def", ".", "X") gives "Xbc.def"`,
466+
`sub("abc.def", "\.", "X") gives "abcXdef"`,
467+
`sub("abcdefg", "[ce]", "X") gives "abXdefg"`,
468+
`sub("prefix4529:suffix8567", "suffix([0-9]+)", "name\1") gives "prefix4529:name8567"`,
469+
},
470+
},
471+
472+
{
473+
name: "gsub",
474+
class: FUNC_CLASS_STRING,
475+
help: `'$name=gsub($name, "old", "new")' (replace all).`,
476+
ternaryFunc: bifs.BIF_gsub,
477+
examples: []string{
478+
`gsub("ababab", "ab", "XY") gives "XYXYXY"`,
479+
`gsub("abc.def", ".", "X") gives "XXXXXXX"`,
480+
`gsub("abc.def", "\.", "X") gives "abcXdef"`,
481+
`gsub("abcdefg", "[ce]", "X") gives "abXdXfg"`,
482+
`gsub("prefix4529:suffix8567", "(....ix)([0-9]+)", "[\1 : \2]") gives "[prefix : 4529]:[suffix : 8567]"`,
483+
},
467484
},
468485

469486
{
@@ -1081,21 +1098,21 @@ strftime_local.`,
10811098
{
10821099
name: "systime",
10831100
class: FUNC_CLASS_TIME,
1084-
help: "help string will go here",
1101+
help: "Returns the system time in floating-point seconds since the epoch.",
10851102
zaryFunc: bifs.BIF_systime,
10861103
},
10871104

10881105
{
10891106
name: "systimeint",
10901107
class: FUNC_CLASS_TIME,
1091-
help: "help string will go here",
1108+
help: "Returns the system time in integer seconds since the epoch.",
10921109
zaryFunc: bifs.BIF_systimeint,
10931110
},
10941111

10951112
{
10961113
name: "uptime",
10971114
class: FUNC_CLASS_TIME,
1098-
help: "help string will go here",
1115+
help: "Returns the time in floating-point seconds since the current Miller program was started.",
10991116
zaryFunc: bifs.BIF_uptime,
11001117
},
11011118

@@ -1417,7 +1434,7 @@ strftime_local.`,
14171434
{
14181435
name: "joink",
14191436
class: FUNC_CLASS_CONVERSION,
1420-
help: `Makes string from map/array keys.`,
1437+
help: `Makes string from map/array keys. First argument is map/array; second is separator string.`,
14211438
examples: []string{
14221439
`joink({"a":3,"b":4,"c":5}, ",") = "a,b,c".`,
14231440
`joink([1,2,3], ",") = "1,2,3".`,
@@ -1428,7 +1445,7 @@ strftime_local.`,
14281445
{
14291446
name: "joinv",
14301447
class: FUNC_CLASS_CONVERSION,
1431-
help: `Makes string from map/array values.`,
1448+
help: `Makes string from map/array values. First argument is map/array; second is separator string.`,
14321449
examples: []string{
14331450
`joinv([3,4,5], ",") = "3,4,5"`,
14341451
`joinv({"a":3,"b":4,"c":5}, ",") = "3,4,5"`,
@@ -1439,10 +1456,11 @@ strftime_local.`,
14391456
{
14401457
name: "joinkv",
14411458
class: FUNC_CLASS_CONVERSION,
1442-
help: `Makes string from map/array key-value pairs.`,
1459+
help: `Makes string from map/array key-value pairs. First argument is map/array;
1460+
second is pair-separator string; third is field-separator string. Mnemonic: the "=" comes before the "," in the output and in the arguments to joinkv.`,
14431461
examples: []string{
14441462
`joinkv([3,4,5], "=", ",") = "1=3,2=4,3=5"`,
1445-
`joinkv({"a":3,"b":4,"c":5}, "=", ",") = "a=3,b=4,c=5"`,
1463+
`joinkv({"a":3,"b":4,"c":5}, ":", ";") = "a:3;b:4;c:5"`,
14461464
},
14471465
ternaryFunc: bifs.BIF_joinkv,
14481466
},

0 commit comments

Comments
 (0)