diff --git a/languages/nu.scm b/languages/nu.scm index b6306c6..eb1081a 100644 --- a/languages/nu.scm +++ b/languages/nu.scm @@ -258,8 +258,22 @@ scrutinee: _? @append_space (match_arm)? @prepend_spaced_softline (default_arm)? @prepend_spaced_softline + "}"? @prepend_spaced_softline ) +; append delimiter after match_arms in single line match expressions +(ctrl_match + "match" + scrutinee: _ + (_) @append_delimiter + . + (_) + (#delimiter! ",") + (#single_line_only!) +) + +(match_pattern "|" @prepend_spaced_softline @append_space ) + ;; data structures (command_list [ @@ -280,16 +294,31 @@ ) @prepend_input_softline (list_body - entry: _ @append_space + (_) @append_delimiter + . + (_) + (#delimiter! ",") + (#single_line_only!) +) +(list_body + entry: (_) @append_space . - entry: _ @prepend_spaced_softline + entry: (_) @prepend_spaced_softline ) ;; match_arm (val_list - entry: _ @append_space + entry: (_) @append_delimiter + ;; unlike list expressions, list patterns include commas as anonymous nodes. + ;; this is required to avoid adding multiple commas + ","* @do_nothing + entry: (_) + (#delimiter! ",") +) +(val_list . - entry: _ @prepend_spaced_softline + entry: (_) + entry: (_) @prepend_spaced_softline ) (val_table @@ -297,11 +326,28 @@ ) (val_record - entry: (record_entry) @append_space + entry: (_) @append_delimiter + ;; unlike record expressions, record patterns include commas as anonymous nodes. + ;; this is required to avoid adding multiple commas + ","* @do_nothing + entry: (_) + (#delimiter! ",") +) +(val_record . - entry: (record_entry) @prepend_spaced_softline + ;; record patterns can use `{ $foo }` as a shorthand for `{ foo: $foo }` + ;; so we can's use record_entry here + entry: (_) + entry: (_) @prepend_spaced_softline ) +(record_body + entry: (record_entry) @append_delimiter + . + entry: (record_entry) + (#delimiter! ",") + (#single_line_only!) +) (record_body entry: (record_entry) @append_space . diff --git a/test/expected_ctrl.nu b/test/expected_ctrl.nu index 4c4c150..4363612 100644 --- a/test/expected_ctrl.nu +++ b/test/expected_ctrl.nu @@ -1,5 +1,5 @@ # for -for i in [1 2 3] { +for i in [1, 2, 3] { # if if (true or false) { print "break"; break # break @@ -14,16 +14,20 @@ alias ll = ls -l # alias comment ls | where $in.name == 'foo' | where {|e| $e.item.name !~ $'^($e.index + 1)' } # match -let foo = {name: 'bar' count: 7} +let foo = {name: 'bar', count: 7} match $foo { - {name: 'bar' count: $it} if $it < 5 => ($it + 3) # match arm comment + {name: 'bar', count: $it} if $it < 5 => ($it + 3) # match arm comment # match comment - {name: 'bar' count: $it} if not ($it >= 5) => ($it + 7) + {name: 'bar', count: $it} if not ($it >= 5) => ($it + 7) + # record shorthand + {$name, $count} => $'($name): ($count)' _ => { exit 0 } } match $foo { - [a b c] => 0 + [a, b, c] => 0 + a | b | c => 42 } +match $foo { null => { return "default" }, 1 => "one", 2 => "two", $val => $val } # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop diff --git a/test/expected_data.nu b/test/expected_data.nu index d1ffe71..6deb081 100644 --- a/test/expected_data.nu +++ b/test/expected_data.nu @@ -38,7 +38,7 @@ export const config = { { name: ws_listener pos: left - events: [aerospace_workspace_change space_windows_change] + events: [aerospace_workspace_change, space_windows_change] args: { updates: on drawing: off @@ -48,7 +48,7 @@ export const config = { { name: front_app pos: left - events: [front_app_switched aerospace_mode_change] + events: [front_app_switched, aerospace_mode_change] args: { label.color: $colors.black icon.color: $colors.black @@ -112,7 +112,7 @@ export const config = { } { name: battery - events: [system_woke power_source_change] + events: [system_woke, power_source_change] args: { update_freq: 120 script: '{}/battery.nu' @@ -247,7 +247,7 @@ export const config = { ] } -const table = [[a b]; [1 2] [2 [4 4]]] -const table_no_row = [[a b]; ] +const table = [[a, b]; [1, 2] [2, [4, 4]]] +const table_no_row = [[a, b]; ] mut foo: record<"a", b, "c": int, d: list> = {} diff --git a/test/expected_exe.nu b/test/expected_exe.nu index 9e6dae6..03d86e0 100644 --- a/test/expected_exe.nu +++ b/test/expected_exe.nu @@ -21,13 +21,13 @@ def modify_args_per_workspace [ ) let extra = ( if $sid == $focused_sid { - {highlight: on border_color: $colors.green} + {highlight: on, border_color: $colors.green} } else { - {highlight: off border_color: $colors.fg} + {highlight: off, border_color: $colors.fg} } ) - ['--set' $"space.($sid)"] + ['--set', $"space.($sid)"] | append ( if (($icons | is-empty) and ($sid != $focused_sid)) { [ @@ -58,14 +58,14 @@ def workspace_modification_args [ let ids_to_modify = ( if ($last_sid | is-empty) { (aerospace list-workspaces --all | lines) } else { - [$focused_sid $last_sid] + [$focused_sid, $last_sid] } ) $ids_to_modify | uniq | each { modify_args_per_workspace $in $focused_sid } | flatten - | append ["--set" $name $"label=($focused_sid)"] + | append ["--set", $name, $"label=($focused_sid)"] } # remained for other possible signals diff --git a/test/input_ctrl.nu b/test/input_ctrl.nu index 9903493..061ba19 100644 --- a/test/input_ctrl.nu +++ b/test/input_ctrl.nu @@ -19,11 +19,15 @@ match $foo { { name: 'bar' count: $it } if $it < 5 => ($it + 3), # match arm comment # match comment { name: 'bar' count: $it } if not ($it >= 5) => ($it + 7), + # record shorthand + { $name $count } => $'($name): ($count)', _ => {exit 0} } match $foo { [ a b c] => 0 + a|b|c => 42 } +match $foo {null => {return "default"} 1 => "one" 2 => "two" $val => $val} # while mut x = 0; while $x < 10 { $x = $x + 1 }; $x # while comment # loop