From 6ff686fa8fa45ba12e31cfa6dfdcf9e1a38a26ce Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sat, 25 Dec 2021 12:51:44 -0500 Subject: [PATCH] Docs for funct keyword --- docs/src/manpage.md | 5 +++++ docs/src/manpage.txt | 5 +++++ docs/src/reference-dsl-variables.md | 5 +++++ internal/pkg/dsl/cst/keyword_usage.go | 8 ++++++++ man/manpage.txt | 5 +++++ man/mlr.1 | 11 +++++++++++ test/cases/dsl-typedecl/0016/cmd | 1 + test/cases/dsl-typedecl/0016/experr | 0 test/cases/dsl-typedecl/0016/expout | 10 ++++++++++ test/cases/dsl-typedecl/0016/mlr | 9 +++++++++ todo.txt | 1 - 11 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 test/cases/dsl-typedecl/0016/cmd create mode 100644 test/cases/dsl-typedecl/0016/experr create mode 100644 test/cases/dsl-typedecl/0016/expout create mode 100644 test/cases/dsl-typedecl/0016/mlr diff --git a/docs/src/manpage.md b/docs/src/manpage.md index e6ed7dd25..483c1e7c0 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -2854,6 +2854,11 @@ KEYWORDS FOR PUT AND FILTER Example: 'func f(a,b) { return sqrt(a**2+b**2)} $d = f($x, $y)' + funct + funct: used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }' + if if: starts an if/elif/elif chain. The body statements must be wrapped in curly braces. diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index 77f07daf2..7c449a3bd 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -2833,6 +2833,11 @@ KEYWORDS FOR PUT AND FILTER Example: 'func f(a,b) { return sqrt(a**2+b**2)} $d = f($x, $y)' + funct + funct: used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }' + if if: starts an if/elif/elif chain. The body statements must be wrapped in curly braces. diff --git a/docs/src/reference-dsl-variables.md b/docs/src/reference-dsl-variables.md index 35166e1cc..1f377222d 100644 --- a/docs/src/reference-dsl-variables.md +++ b/docs/src/reference-dsl-variables.md @@ -871,6 +871,7 @@ filter float for func +funct if in int @@ -1106,6 +1107,10 @@ func: used for defining a user-defined function. Example: 'func f(a,b) { return sqrt(a**2+b**2)} $d = f($x, $y)' +funct: used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }' + if: starts an if/elif/elif chain. The body statements must be wrapped in curly braces. diff --git a/internal/pkg/dsl/cst/keyword_usage.go b/internal/pkg/dsl/cst/keyword_usage.go index 0972cbce8..44e7fcdc2 100644 --- a/internal/pkg/dsl/cst/keyword_usage.go +++ b/internal/pkg/dsl/cst/keyword_usage.go @@ -40,6 +40,7 @@ var KEYWORD_USAGE_TABLE = []tKeywordUsageEntry{ {"float", floatKeywordUsage}, {"for", forKeywordUsage}, {"func", funcKeywordUsage}, + {"funct", functKeywordUsage}, {"if", ifKeywordUsage}, {"in", inKeywordUsage}, {"int", intKeywordUsage}, @@ -402,6 +403,13 @@ func funcKeywordUsage() { Example: 'func f(a,b) { return sqrt(a**2+b**2)} $d = f($x, $y)'`) } +func functKeywordUsage() { + fmt.Println( + `used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }'`) +} + func ifKeywordUsage() { fmt.Println( `starts an if/elif/elif chain. The body statements must be wrapped diff --git a/man/manpage.txt b/man/manpage.txt index 77f07daf2..7c449a3bd 100644 --- a/man/manpage.txt +++ b/man/manpage.txt @@ -2833,6 +2833,11 @@ KEYWORDS FOR PUT AND FILTER Example: 'func f(a,b) { return sqrt(a**2+b**2)} $d = f($x, $y)' + funct + funct: used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }' + if if: starts an if/elif/elif chain. The body statements must be wrapped in curly braces. diff --git a/man/mlr.1 b/man/mlr.1 index df93c3401..3b44eea18 100644 --- a/man/mlr.1 +++ b/man/mlr.1 @@ -4724,6 +4724,17 @@ func: used for defining a user-defined function. .fi .if n \{\ .RE +.SS "funct" +.if n \{\ +.RS 0 +.\} +.nf +funct: used for saying that a function argument is a user-defined function. + + Example: 'func g(num a, num b, funct f) :num { return f(a**2+b**2) }' +.fi +.if n \{\ +.RE .SS "if" .if n \{\ .RS 0 diff --git a/test/cases/dsl-typedecl/0016/cmd b/test/cases/dsl-typedecl/0016/cmd new file mode 100644 index 000000000..d90d35f48 --- /dev/null +++ b/test/cases/dsl-typedecl/0016/cmd @@ -0,0 +1 @@ +mlr --from test/input/abixy put -f ${CASEDIR}/mlr diff --git a/test/cases/dsl-typedecl/0016/experr b/test/cases/dsl-typedecl/0016/experr new file mode 100644 index 000000000..e69de29bb diff --git a/test/cases/dsl-typedecl/0016/expout b/test/cases/dsl-typedecl/0016/expout new file mode 100644 index 000000000..5287ed70b --- /dev/null +++ b/test/cases/dsl-typedecl/0016/expout @@ -0,0 +1,10 @@ +a=pan,b=pan,i=1,x=0.3467901443380824,y=0.7268028627434533,d=0.8052985815845617 +a=eks,b=pan,i=2,x=0.7586799647899636,y=0.5221511083334797,d=0.9209978658539777 +a=wye,b=wye,i=3,x=0.20460330576630303,y=0.33831852551664776,d=0.3953756915115773 +a=eks,b=wye,i=4,x=0.38139939387114097,y=0.13418874328430463,d=0.40431685157744135 +a=wye,b=pan,i=5,x=0.5732889198020006,y=0.8636244699032729,d=1.036584492737304 +a=zee,b=pan,i=6,x=0.5271261600918548,y=0.49322128674835697,d=0.7218928080781029 +a=eks,b=zee,i=7,x=0.6117840605678454,y=0.1878849191181694,d=0.6399847495033941 +a=zee,b=wye,i=8,x=0.5985540091064224,y=0.976181385699006,d=1.1450751065334548 +a=hat,b=wye,i=9,x=0.03144187646093577,y=0.7495507603507059,d=0.750209926579025 +a=pan,b=wye,i=10,x=0.5026260055412137,y=0.9526183602969864,d=1.0770861812414247 diff --git a/test/cases/dsl-typedecl/0016/mlr b/test/cases/dsl-typedecl/0016/mlr new file mode 100644 index 000000000..b2671db17 --- /dev/null +++ b/test/cases/dsl-typedecl/0016/mlr @@ -0,0 +1,9 @@ +func f(x) { + return sqrt(x) +}; + +func g(num a, num b, funct f) :num { + return f(a**2+b**2) +}; + +$d = g($x, $y, f); diff --git a/todo.txt b/todo.txt index 2c6812e11..6edbca2ed 100644 --- a/todo.txt +++ b/todo.txt @@ -4,7 +4,6 @@ PUNCHDOWN LIST * blockers: - fractional-strptime - improved regex doc w/ lots of examples - - kw olh for func and funct both - cmp-matrices - all-contribs: twi dm - license triple-checks