tree-sitter-bash/corpus/control_flow.txt

135 lines
2.4 KiB
Plaintext
Raw Normal View History

2017-07-14 23:11:35 +00:00
====================================
While statements
====================================
while something happens; do
echo a
echo b
done
---
(program
(while_statement
2017-07-16 05:13:55 +00:00
(command (command_name) (word))
2017-07-14 23:11:35 +00:00
(do_group
2017-07-16 05:13:55 +00:00
(command (command_name) (word))
(command (command_name) (word)))))
2017-07-14 23:18:46 +00:00
2017-07-15 00:51:06 +00:00
====================================
For statements
====================================
for a in $(seq 1 10); do
echo $a
done
---
(program
(for_statement
2017-07-16 05:13:55 +00:00
(word)
(command (command_substitution (command (command_name) (word) (word))))
2017-07-15 00:51:06 +00:00
(do_group
2017-07-16 05:13:55 +00:00
(command (command_name) (simple_expansion (variable_name))))))
2017-07-15 00:51:06 +00:00
2017-07-14 23:18:46 +00:00
====================================
If statements
====================================
if cat some_file | grep -v ok; then
echo one
elif cat other_file | grep -v ok; then
echo two
else
exit
fi
---
(program
(if_statement
(pipeline
2017-07-16 05:13:55 +00:00
(command (command_name) (word))
(command (command_name) (word) (word)))
(command (command_name) (word))
2017-07-14 23:18:46 +00:00
(elif_clause
(pipeline
2017-07-16 05:13:55 +00:00
(command (command_name) (word))
(command (command_name) (word) (word)))
(command (command_name) (word)))
2017-07-14 23:18:46 +00:00
(else_clause
(command (command_name)))))
2017-07-14 23:29:28 +00:00
====================================
If statements with conditional expressions
====================================
if [ "$(uname)" == 'Darwin' ]; then
echo one
fi
---
(program
(if_statement
(bracket_command
2017-07-16 05:13:55 +00:00
(string (command_substitution (command (command_name))))
(word)
(raw_string))
(command (command_name) (word))))
2017-07-14 23:29:28 +00:00
====================================
Case statements
====================================
case "opt" in
a)
echo a
;;
b)
echo b
;;
esac
---
(program
2017-07-16 05:13:55 +00:00
(case_statement (string)
(case_item (word)
(command (command_name) (word)))
(case_item (word)
(command (command_name) (word)))))
2017-07-15 00:32:55 +00:00
===============================
Subshells
===============================
(
./start-server --port=80
) &
---
(program
2017-07-16 05:13:55 +00:00
(subshell (command (command_name) (word))))
2017-07-15 00:35:51 +00:00
===============================
Function definitions
===============================
do_something() {
echo ok
}
function do_something_else() {
echo ok
}
---
(program
2017-07-16 05:13:55 +00:00
(function_definition (command_name) (compound_statement (command (command_name) (word))))
(function_definition (command_name) (compound_statement (command (command_name) (word)))))