Skip to content

Commit

Permalink
Merge pull request #28 from NotLebedev/block-fixes
Browse files Browse the repository at this point in the history
Fixes to block handling
  • Loading branch information
fdncred authored Sep 11, 2023
2 parents 786689b + 29f5222 commit 79d0e05
Show file tree
Hide file tree
Showing 11 changed files with 201,698 additions and 208,791 deletions.
40 changes: 38 additions & 2 deletions corpus/ctrl/match.nu
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,42 @@ match $x {
(val_variable
(identifier))
(val_number))))
(val_record))
(block))
(default_arm
(val_record))))
(block))))

====
match-002-block
====

match $x {
{key: $val} => {$val | print}
_ => {{}}
}

-----

(nu_script
(ctrl_match
(val_variable
(identifier))
(match_arm
(match_pattern
(val_record
(record_entry
(identifier)
(val_variable
(identifier)))))
(block
(pipeline
(pipe_element
(val_variable
(identifier)))
(pipe_element
(command
(cmd_identifier))))))
(default_arm
(block
(pipeline
(pipe_element
(val_record)))))))
9 changes: 5 additions & 4 deletions corpus/expr/unary-expr.nu
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ expr-002-smoke-test
(pipe_element
(expr_binary
(expr_unary
(pipe_element
(expr_binary
(val_number)
(val_number))))
(pipeline
(pipe_element
(expr_binary
(val_number)
(val_number)))))
(val_number)))))
7 changes: 4 additions & 3 deletions corpus/expr/values.nu
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ values-002-booleans
(val_bool)
(val_bool)
(expr_parenthesized
(pipe_element
(expr_unary
(val_bool))))))))
(pipeline
(pipe_element
(expr_unary
(val_bool)))))))))

=====
values-003-nothing
Expand Down
143 changes: 143 additions & 0 deletions corpus/pipe/blocks.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
====
blocks-001-block
====

if $a {
print qwe
print rty
}

-----

(nu_script
(ctrl_if
(val_variable
(identifier))
(block
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string)))))))
====
blocks-002-block-oneline
====

if $a { print qwe; print rty }

-----

(nu_script
(ctrl_if
(val_variable
(identifier))
(block
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string)))))))
====
blocks-003-braced
====

(print qwe; print rty)

-----

(nu_script
(pipeline
(pipe_element
(expr_parenthesized
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))))))

====
blocks-004-multiline-command
====

(ls
--all
-l
../
)

-----

(nu_script
(pipeline
(pipe_element
(expr_parenthesized
(pipeline
(pipe_element
(command
(cmd_identifier)
(long_flag)
(short_flag)
(val_string))))))))


====
blocks-005-closures
====

let a = {||
print qwe
print rty
}

let b = {|| print qwe; print rty }

-----

(nu_script
(stmt_let
(identifier)
(pipeline
(pipe_element
(val_closure
(parameter_pipes)
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))))))
(stmt_let
(identifier)
(pipeline
(pipe_element
(val_closure
(parameter_pipes)
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string))))
(pipeline
(pipe_element
(command
(cmd_identifier)
(val_string)))))))))
32 changes: 32 additions & 0 deletions corpus/pipe/commands.nu
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,35 @@ foo this is only for testing
(val_string)
(val_string)
(val_string)))))

====
cmd-007-if-oneline
====

if $a { 0 } else { ls | print; ls | print; }

-----

(nu_script
(ctrl_if
(val_variable
(identifier))
(block
(pipeline
(pipe_element
(val_number))))
(block
(pipeline
(pipe_element
(command
(cmd_identifier)))
(pipe_element
(command
(cmd_identifier))))
(pipeline
(pipe_element
(command
(cmd_identifier)))
(pipe_element
(command
(cmd_identifier)))))))
43 changes: 18 additions & 25 deletions corpus/stmt/assignment.nu
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ $var = 42
(assignment
(val_variable
(identifier))
(pipeline
(pipe_element
(val_number)))))
(val_number)))

=====
assignment-002-semicolon
Expand All @@ -26,37 +24,32 @@ $var += 69;
(assignment
(val_variable
(identifier))
(pipeline
(pipe_element
(val_number)))))
(val_number)))

=====
assignment-003-assignment-to-a-pipeline
=====

$x ++= [1 2 3] | each {|x| $x + 8}
$x += 1 | $in + 10
# Note that rhs of ++= is not a pipeline, but only 1
# currently nushell parses this as two statements
# $x ++= 1 and $in + 10. Therefore you will get error
# about adding int to nothing, and $x increased by one

-----

(nu_script
(assignment
(val_variable
(identifier))
(pipeline
(pipe_element
(val_list
(val_number)
(val_number)
(val_number)))
(pipe_element
(command
(cmd_identifier)
(val_closure
(parameter_pipes
(parameter
(identifier)))
(ERROR
(expr_binary
(val_variable
(identifier))
(val_number)))))))))
(val_number))
(ERROR)
(pipeline
(pipe_element
(expr_binary
(val_variable)
(val_number))))
(comment)
(comment)
(comment)
(comment))
Loading

0 comments on commit 79d0e05

Please sign in to comment.