diff --git a/docs/src/manpage.md b/docs/src/manpage.md index de4fb8f71..75fdf683c 100644 --- a/docs/src/manpage.md +++ b/docs/src/manpage.md @@ -3054,5 +3054,5 @@ SEE ALSO - 2022-01-09 MILLER(1) + 2022-01-10 MILLER(1) diff --git a/docs/src/manpage.txt b/docs/src/manpage.txt index ce925ef04..26c23ee81 100644 --- a/docs/src/manpage.txt +++ b/docs/src/manpage.txt @@ -3033,4 +3033,4 @@ SEE ALSO - 2022-01-09 MILLER(1) + 2022-01-10 MILLER(1) diff --git a/docs/src/new-in-miller-6.md b/docs/src/new-in-miller-6.md index f859b3479..c2159a81a 100644 --- a/docs/src/new-in-miller-6.md +++ b/docs/src/new-in-miller-6.md @@ -237,6 +237,18 @@ For example (see [https://github.com/johnkerl/miller/issues/178](https://github. ] +### Deduping of repeated field names + +By default, field names are deduped for all file formats except JSON / JSON Lines. So if you +have an input record with `x=8,x=9` then the second field's key is renamed to +`x_2` and so on -- the record scans as `x=8,x_2=9`. Use `mlr +--no-dedupe-field-names` to suppress this, and have the record be scanned as +`x=9`. + +For JSON and JSON Lines, the last duplicated key in an input record is always retained, +regardless of `mlr --no-dedupe-field-names`: `{"x":8,"x":9}` scans as if it +were `{"x":9}`. + ### Regex support for IFS and IPS You can now split fields on whitespace when whitespace is a mix of tabs and @@ -304,9 +316,24 @@ IFS and IPS can be regular expressions now. Please see the section on [multi-cha ### Emit statements -* Emitting a map-valued expression now requires either a temporary variable or the new `emit1` keyword. Please see the -[page on emit statements](reference-dsl-output-statements.md#emit1-and-emitemitpemitf) for more information. -* By default, field names are deduped for all file formats except JSON. So if you have an input record with `x=8,x=9` then the second field's key is renamed to `x_2` and so on -- the record scans as `x=8,x_2=9`. Use `mlr --no-dedupe-field-names` to suppress this, and have the record be scanned as `x=9`. For JSON, the last duplicated key in an input record is always retained, regardless of `mlr --no-dedupe-field-names`: `{"x":8,"x":9}` scans as if it were `{"x":9}`. +Variables must be non-indexed on `emit`. To emit an indexed variable now requires the new `emit1` keyword. + +
+mlr5 -n put 'end {@input={"a":1}; emit @input["a"]}'
+
+
+input=1
+
+ +
+mlr -n put 'end {@input={"a":1}; emit1 {"input":@input["a"]}}'
+
+
+input=1
+
+ +Please see the [section on emit statements](reference-dsl-output-statements.md#emit1-and-emitemitpemitf) +for more information. ## Developer-specific aspects diff --git a/docs/src/new-in-miller-6.md.in b/docs/src/new-in-miller-6.md.in index e0397cc45..1530417ec 100644 --- a/docs/src/new-in-miller-6.md.in +++ b/docs/src/new-in-miller-6.md.in @@ -191,6 +191,18 @@ GENMD-RUN-COMMAND echo '{ "x": 1.230, "y": 1.230000000 }' | mlr --json cat GENMD-EOF +### Deduping of repeated field names + +By default, field names are deduped for all file formats except JSON / JSON Lines. So if you +have an input record with `x=8,x=9` then the second field's key is renamed to +`x_2` and so on -- the record scans as `x=8,x_2=9`. Use `mlr +--no-dedupe-field-names` to suppress this, and have the record be scanned as +`x=9`. + +For JSON and JSON Lines, the last duplicated key in an input record is always retained, +regardless of `mlr --no-dedupe-field-names`: `{"x":8,"x":9}` scans as if it +were `{"x":9}`. + ### Regex support for IFS and IPS You can now split fields on whitespace when whitespace is a mix of tabs and @@ -258,9 +270,19 @@ IFS and IPS can be regular expressions now. Please see the section on [multi-cha ### Emit statements -* Emitting a map-valued expression now requires either a temporary variable or the new `emit1` keyword. Please see the -[page on emit statements](reference-dsl-output-statements.md#emit1-and-emitemitpemitf) for more information. -* By default, field names are deduped for all file formats except JSON. So if you have an input record with `x=8,x=9` then the second field's key is renamed to `x_2` and so on -- the record scans as `x=8,x_2=9`. Use `mlr --no-dedupe-field-names` to suppress this, and have the record be scanned as `x=9`. For JSON, the last duplicated key in an input record is always retained, regardless of `mlr --no-dedupe-field-names`: `{"x":8,"x":9}` scans as if it were `{"x":9}`. +Variables must be non-indexed on `emit`. To emit an indexed variable now requires the new `emit1` keyword. + +GENMD-CARDIFY-HIGHLIGHT-ONE +mlr5 -n put 'end {@input={"a":1}; emit @input["a"]}' +input=1 +GENMD-EOF + +GENMD-RUN-COMMAND +mlr -n put 'end {@input={"a":1}; emit1 {"input":@input["a"]}}' +GENMD-EOF + +Please see the [section on emit statements](reference-dsl-output-statements.md#emit1-and-emitemitpemitf) +for more information. ## Developer-specific aspects diff --git a/docs/src/reference-dsl-operators.md b/docs/src/reference-dsl-operators.md index 50628c56c..f1d1a944b 100644 --- a/docs/src/reference-dsl-operators.md +++ b/docs/src/reference-dsl-operators.md @@ -46,6 +46,9 @@ Operators are listed in order of decreasing precedence, highest first. | `? :` | right to left | | `=` | N/A for Miller (there is no $a=$b=$c) | +See also the [section on parsing and operator precedence in the REPL](repl.md#parsing-and-operator-precedence) +for information on how to examine operator precedence interactively. + ## Operator and function semantics * Functions are often pass-throughs straight to the system-standard Go libraries. diff --git a/docs/src/reference-dsl-operators.md.in b/docs/src/reference-dsl-operators.md.in index 47344031f..cb35574e9 100644 --- a/docs/src/reference-dsl-operators.md.in +++ b/docs/src/reference-dsl-operators.md.in @@ -30,6 +30,9 @@ Operators are listed in order of decreasing precedence, highest first. | `? :` | right to left | | `=` | N/A for Miller (there is no $a=$b=$c) | +See also the [section on parsing and operator precedence in the REPL](repl.md#parsing-and-operator-precedence) +for information on how to examine operator precedence interactively. + ## Operator and function semantics * Functions are often pass-throughs straight to the system-standard Go libraries. diff --git a/docs/src/reference-dsl-output-statements.md b/docs/src/reference-dsl-output-statements.md index 84a839f44..9638cd3aa 100644 --- a/docs/src/reference-dsl-output-statements.md +++ b/docs/src/reference-dsl-output-statements.md @@ -363,23 +363,49 @@ So, `emit1` can handle syntactic richness in the one thing being emitted; `emitf`, `emit`, and `emitp` can handle syntactic richness in the side-by-side placement, indexing, and redirection. -(Mnemonic: If all you want is to insert a new record into the record stream, `emit1` is probably the one you want.) +(Mnemonic: If all you want is to insert a new record into the record stream, `emit1` is probably the _one_ you want.) What this means is that if you want to emit an expression which evaluates to a map, you can do quite simply -
-  mlr --c2p --from example.csv put -q '
-    emit1 mapsum({"id": NR}, $*)
-  '
+
+mlr --c2p --from example.csv put -q '
+  emit1 mapsum({"id": NR}, $*)
+'
+
+
+id color  shape    flag  k  index quantity rate
+1  yellow triangle true  1  11    43.6498  9.8870
+2  red    square   true  2  15    79.2778  0.0130
+3  red    circle   true  3  16    13.8103  2.9010
+4  red    square   false 4  48    77.5542  7.4670
+5  purple triangle false 5  51    81.2290  8.5910
+6  red    square   false 6  64    77.1991  9.5310
+7  purple triangle false 7  65    80.1405  5.8240
+8  yellow circle   true  8  73    63.9785  4.2370
+9  yellow circle   true  9  87    63.5058  8.3350
+10 purple square   false 10 91    72.3735  8.2430
 
And if you want indexing, redirects, etc., just assign to a temporary variable and use one of the other emit variants: -
-  mlr --c2p --from example.csv put -q '
-    o = mapsum({"id": NR}, $*);
-    emit > stderr, o;
-  '
+
+mlr --c2p --from example.csv put -q '
+  o = mapsum({"id": NR}, $*);
+  emit o;
+'
+
+
+id color  shape    flag  k  index quantity rate
+1  yellow triangle true  1  11    43.6498  9.8870
+2  red    square   true  2  15    79.2778  0.0130
+3  red    circle   true  3  16    13.8103  2.9010
+4  red    square   false 4  48    77.5542  7.4670
+5  purple triangle false 5  51    81.2290  8.5910
+6  red    square   false 6  64    77.1991  9.5310
+7  purple triangle false 7  65    80.1405  5.8240
+8  yellow circle   true  8  73    63.9785  4.2370
+9  yellow circle   true  9  87    63.5058  8.3350
+10 purple square   false 10 91    72.3735  8.2430
 
## Emitf statements diff --git a/docs/src/reference-dsl-output-statements.md.in b/docs/src/reference-dsl-output-statements.md.in index b9da227c2..0f7bf9661 100644 --- a/docs/src/reference-dsl-output-statements.md.in +++ b/docs/src/reference-dsl-output-statements.md.in @@ -174,23 +174,23 @@ So, `emit1` can handle syntactic richness in the one thing being emitted; `emitf`, `emit`, and `emitp` can handle syntactic richness in the side-by-side placement, indexing, and redirection. -(Mnemonic: If all you want is to insert a new record into the record stream, `emit1` is probably the one you want.) +(Mnemonic: If all you want is to insert a new record into the record stream, `emit1` is probably the _one_ you want.) What this means is that if you want to emit an expression which evaluates to a map, you can do quite simply -GENMD-CARDIFY - mlr --c2p --from example.csv put -q ' - emit1 mapsum({"id": NR}, $*) - ' +GENMD-RUN-COMMAND +mlr --c2p --from example.csv put -q ' + emit1 mapsum({"id": NR}, $*) +' GENMD-EOF And if you want indexing, redirects, etc., just assign to a temporary variable and use one of the other emit variants: -GENMD-CARDIFY - mlr --c2p --from example.csv put -q ' - o = mapsum({"id": NR}, $*); - emit > stderr, o; - ' +GENMD-RUN-COMMAND +mlr --c2p --from example.csv put -q ' + o = mapsum({"id": NR}, $*); + emit o; +' GENMD-EOF ## Emitf statements diff --git a/docs/src/repl.md b/docs/src/repl.md index 8a23605d0..326b62771 100644 --- a/docs/src/repl.md +++ b/docs/src/repl.md @@ -207,6 +207,71 @@ Skip until deep into a larger file, then inspect a record: }
+## Parsing and operator precedence + +You can invoke `mlr repl` with the `-v` or `-d` flags to show parse trees for expressions you enter. +(The `-v` and `-d` flags differ only in the format they use to present the parse trees.) +For example, if you have any questions about operator precedence, you can check the +[operator-precedence section](reference-dsl-operators.md#operator-precedence) -- or, you can +try it out and see for yourself: + +
+mlr repl -v
+
+
+Miller 6.0.0-rc1 REPL for darwin/amd64/go1.16.5
+Docs: https://miller.readthedocs.io
+Type ':h' or ':help' for online help; ':q' or ':quit' to quit.
+[mlr] x = 1 * 2 + 3
+* statement block
+    * assignment "="
+        * local variable "x"
+        * operator "+"
+            * operator "*"
+                * int literal "1"
+                * int literal "2"
+            * int literal "3"
+[mlr] x = 1 + 2 * 3
+* statement block
+    * assignment "="
+        * local variable "x"
+        * operator "+"
+            * int literal "1"
+            * operator "*"
+                * int literal "2"
+                * int literal "3"
+
+ +
+mlr repl -d
+
+
+$ mrpl -d
+Miller 6.0.0-rc1 REPL for darwin/amd64/go1.16.5
+Docs: https://miller.readthedocs.io
+Type ':h' or ':help' for online help; ':q' or ':quit' to quit.
+[mlr] x = 1 * 2 + 3
+(statement-block
+    (=
+        x
+        (+
+            (* 1 2)
+            3
+        )
+    )
+)
+[mlr] x = 1 + 2 * 3
+(statement-block
+    (=
+        x
+        (+
+            1
+            (* 2 3)
+        )
+    )
+)
+
+ ## History-editing No command-line-history-editing feature is built in but **rlwrap mlr repl** is a diff --git a/docs/src/repl.md.in b/docs/src/repl.md.in index 987199653..c15e635f0 100644 --- a/docs/src/repl.md.in +++ b/docs/src/repl.md.in @@ -157,6 +157,67 @@ mlr repl --csv } GENMD-EOF +## Parsing and operator precedence + +You can invoke `mlr repl` with the `-v` or `-d` flags to show parse trees for expressions you enter. +(The `-v` and `-d` flags differ only in the format they use to present the parse trees.) +For example, if you have any questions about operator precedence, you can check the +[operator-precedence section](reference-dsl-operators.md#operator-precedence) -- or, you can +try it out and see for yourself: + +GENMD-CARDIFY-HIGHLIGHT-ONE +mlr repl -v +Miller 6.0.0-rc1 REPL for darwin/amd64/go1.16.5 +Docs: https://miller.readthedocs.io +Type ':h' or ':help' for online help; ':q' or ':quit' to quit. +[mlr] x = 1 * 2 + 3 +* statement block + * assignment "=" + * local variable "x" + * operator "+" + * operator "*" + * int literal "1" + * int literal "2" + * int literal "3" +[mlr] x = 1 + 2 * 3 +* statement block + * assignment "=" + * local variable "x" + * operator "+" + * int literal "1" + * operator "*" + * int literal "2" + * int literal "3" +GENMD-EOF + +GENMD-CARDIFY-HIGHLIGHT-ONE +mlr repl -d +$ mrpl -d +Miller 6.0.0-rc1 REPL for darwin/amd64/go1.16.5 +Docs: https://miller.readthedocs.io +Type ':h' or ':help' for online help; ':q' or ':quit' to quit. +[mlr] x = 1 * 2 + 3 +(statement-block + (= + x + (+ + (* 1 2) + 3 + ) + ) +) +[mlr] x = 1 + 2 * 3 +(statement-block + (= + x + (+ + 1 + (* 2 3) + ) + ) +) +GENMD-EOF + ## History-editing No command-line-history-editing feature is built in but **rlwrap mlr repl** is a diff --git a/man/manpage.txt b/man/manpage.txt index ce925ef04..26c23ee81 100644 --- a/man/manpage.txt +++ b/man/manpage.txt @@ -3033,4 +3033,4 @@ SEE ALSO - 2022-01-09 MILLER(1) + 2022-01-10 MILLER(1) diff --git a/man/mlr.1 b/man/mlr.1 index c103c459a..1accdb255 100644 --- a/man/mlr.1 +++ b/man/mlr.1 @@ -2,12 +2,12 @@ .\" Title: mlr .\" Author: [see the "AUTHOR" section] .\" Generator: ./mkman.rb -.\" Date: 2022-01-09 +.\" Date: 2022-01-10 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "MILLER" "1" "2022-01-09" "\ \&" "\ \&" +.TH "MILLER" "1" "2022-01-10" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Portability definitions .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/todo.txt b/todo.txt index 3a63c74da..d594fd674 100644 --- a/todo.txt +++ b/todo.txt @@ -3,13 +3,10 @@ PUNCHDOWN LIST ---------------------------------------------------------------- -* field-dedupe separate section at nim6 -* mrpl -v/-d doc -* emit1 note * document cloudthings, e.g. o go.yml o codespell.yml - - codespell --check-filenames --skip *.csv,*.dkvp,*.txt,*.js,*.html,*.map,./tags,./test/cases --ignore-words-list denom,inTerm,inout,iput,nd,nin,numer,Wit,te,wee + - codespell --check-filenames --skip *.csv,*.dkvp,*.txt,*.js,*.html,*.map,./tags,./test/cases --ignore-words-list denom,inTerm,inout,iput,nd,nin,numer,Wit,te,wee o readthedocs triggers * sync-print option; or (yuck) another xprint variant; or ...; emph dump/eprint ? trace-mode ? @@ -318,7 +315,7 @@ MAYBES * dotted-syntax support in verbs? -* repl as verb -- ? 'put --repl' maybe +* repl as verb -- ? 'put --repl' maybe * json-triple-quote -- what can be done here?