plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
plum-tooling/tree-sitter-plum/test/corpus/match.txt
| 2a44b7e | 1 | ================================================================================ |
| f997bee | 2 | match |
| 2a44b7e | 3 | ================================================================================ |
| 2a44b7e | 4 | |
| c06ddba | 5 | fun main() = |
| f997bee | 6 | match a |
| f502d22 | 7 | 1 => |
| f502d22 | 8 | printLn(a) |
| f502d22 | 9 | "hi" => |
| f502d22 | 10 | printLn(a) |
| f502d22 | 11 | True => |
| f502d22 | 12 | printLn(a) |
| f502d22 | 13 | Some(b) => |
| f502d22 | 14 | printLn(b) |
| f502d22 | 15 | x => |
| f502d22 | 16 | printLn(x) |
| f997bee | 17 | _ => |
| f502d22 | 18 | printLn(a) |
| 2a44b7e | 19 | |
| 2a44b7e | 20 | -------------------------------------------------------------------------------- |
| 2a44b7e | 21 | |
| f502d22 | 22 | (source |
| f502d22 | 23 | (fn |
| f502d22 | 24 | (fn_identifier) |
| f502d22 | 25 | (body |
| f502d22 | 26 | (match |
| f502d22 | 27 | (expression |
| f502d22 | 28 | (primary_expression |
| f502d22 | 29 | (var_identifier))) |
| f502d22 | 30 | (case |
| f502d22 | 31 | (case_pattern |
| f502d22 | 32 | (integer)) |
| f502d22 | 33 | (body |
| aeaba6f | 34 | (expression |
| aeaba6f | 35 | (primary_expression |
| aeaba6f | 36 | (fn_call |
| aeaba6f | 37 | (var_identifier) |
| aeaba6f | 38 | (fn_argument_list |
| aeaba6f | 39 | (expression |
| aeaba6f | 40 | (primary_expression |
| aeaba6f | 41 | (var_identifier))))))))) |
| f502d22 | 42 | (case |
| f502d22 | 43 | (case_pattern |
| f502d22 | 44 | (string |
| f502d22 | 45 | (string_start) |
| f502d22 | 46 | (string_content) |
| f502d22 | 47 | (string_end))) |
| f502d22 | 48 | (body |
| aeaba6f | 49 | (expression |
| aeaba6f | 50 | (primary_expression |
| aeaba6f | 51 | (fn_call |
| aeaba6f | 52 | (var_identifier) |
| aeaba6f | 53 | (fn_argument_list |
| aeaba6f | 54 | (expression |
| aeaba6f | 55 | (primary_expression |
| aeaba6f | 56 | (var_identifier))))))))) |
| f502d22 | 57 | (case |
| f502d22 | 58 | (case_pattern |
| f502d22 | 59 | (type_identifier)) |
| f502d22 | 60 | (body |
| aeaba6f | 61 | (expression |
| aeaba6f | 62 | (primary_expression |
| aeaba6f | 63 | (fn_call |
| aeaba6f | 64 | (var_identifier) |
| aeaba6f | 65 | (fn_argument_list |
| aeaba6f | 66 | (expression |
| aeaba6f | 67 | (primary_expression |
| aeaba6f | 68 | (var_identifier))))))))) |
| f502d22 | 69 | (case |
| f502d22 | 70 | (case_pattern |
| f502d22 | 71 | (class_pattern |
| f502d22 | 72 | (type_identifier) |
| f502d22 | 73 | (case_pattern |
| f502d22 | 74 | (dotted_name |
| f502d22 | 75 | (var_identifier))))) |
| f502d22 | 76 | (body |
| aeaba6f | 77 | (expression |
| aeaba6f | 78 | (primary_expression |
| aeaba6f | 79 | (fn_call |
| aeaba6f | 80 | (var_identifier) |
| aeaba6f | 81 | (fn_argument_list |
| aeaba6f | 82 | (expression |
| aeaba6f | 83 | (primary_expression |
| aeaba6f | 84 | (var_identifier))))))))) |
| f502d22 | 85 | (case |
| f502d22 | 86 | (case_pattern |
| f502d22 | 87 | (dotted_name |
| f502d22 | 88 | (var_identifier))) |
| f502d22 | 89 | (body |
| aeaba6f | 90 | (expression |
| aeaba6f | 91 | (primary_expression |
| aeaba6f | 92 | (fn_call |
| aeaba6f | 93 | (var_identifier) |
| aeaba6f | 94 | (fn_argument_list |
| aeaba6f | 95 | (expression |
| aeaba6f | 96 | (primary_expression |
| aeaba6f | 97 | (var_identifier))))))))) |
| f502d22 | 98 | (case |
| f502d22 | 99 | (case_pattern) |
| f502d22 | 100 | (body |
| aeaba6f | 101 | (expression |
| aeaba6f | 102 | (primary_expression |
| aeaba6f | 103 | (fn_call |
| aeaba6f | 104 | (var_identifier) |
| aeaba6f | 105 | (fn_argument_list |
| aeaba6f | 106 | (expression |
| aeaba6f | 107 | (primary_expression |
| aeaba6f | 108 | (var_identifier))))))))))))) |
| 660674c | 109 | |
| 660674c | 110 | ================================================================================ |
| 660674c | 111 | match - inline case bodies |
| 660674c | 112 | ================================================================================ |
| 660674c | 113 | |
| c06ddba | 114 | fun main() = |
| 660674c | 115 | match a |
| 660674c | 116 | 1 => printLn(a) |
| 660674c | 117 | 2 => printLn(b) |
| 660674c | 118 | _ => printLn(c) |
| 660674c | 119 | |
| 660674c | 120 | -------------------------------------------------------------------------------- |
| 660674c | 121 | |
| 660674c | 122 | (source |
| 660674c | 123 | (fn |
| 660674c | 124 | (fn_identifier) |
| 660674c | 125 | (body |
| 660674c | 126 | (match |
| 660674c | 127 | (expression |
| 660674c | 128 | (primary_expression |
| 660674c | 129 | (var_identifier))) |
| 660674c | 130 | (case |
| 660674c | 131 | (case_pattern |
| 660674c | 132 | (integer)) |
| 660674c | 133 | (expression |
| 660674c | 134 | (primary_expression |
| 660674c | 135 | (fn_call |
| 660674c | 136 | (var_identifier) |
| 660674c | 137 | (fn_argument_list |
| 660674c | 138 | (expression |
| 660674c | 139 | (primary_expression |
| 660674c | 140 | (var_identifier)))))))) |
| 660674c | 141 | (case |
| 660674c | 142 | (case_pattern |
| 660674c | 143 | (integer)) |
| 660674c | 144 | (expression |
| 660674c | 145 | (primary_expression |
| 660674c | 146 | (fn_call |
| 660674c | 147 | (var_identifier) |
| 660674c | 148 | (fn_argument_list |
| 660674c | 149 | (expression |
| 660674c | 150 | (primary_expression |
| 660674c | 151 | (var_identifier)))))))) |
| 660674c | 152 | (case |
| 660674c | 153 | (case_pattern) |
| 660674c | 154 | (expression |
| 660674c | 155 | (primary_expression |
| 660674c | 156 | (fn_call |
| 660674c | 157 | (var_identifier) |
| 660674c | 158 | (fn_argument_list |
| 660674c | 159 | (expression |
| 660674c | 160 | (primary_expression |
| 660674c | 161 | (var_identifier)))))))))))) |
| 608d862 | 162 | |
| 608d862 | 163 | ================================================================================ |
| 608d862 | 164 | match - guard-clause arms, no subject |
| 608d862 | 165 | ================================================================================ |
| 608d862 | 166 | |
| c06ddba | 167 | fun compare(x: Int, y: Int) -> Int = |
| 608d862 | 168 | match |
| 608d862 | 169 | | x > y => |
| 608d862 | 170 | 1 |
| 608d862 | 171 | | x == y => |
| 608d862 | 172 | 0 |
| 608d862 | 173 | | _ => |
| 608d862 | 174 | -1 |
| 608d862 | 175 | |
| 608d862 | 176 | -------------------------------------------------------------------------------- |
| 608d862 | 177 | |
| 608d862 | 178 | (source |
| 608d862 | 179 | (fn |
| 608d862 | 180 | (fn_identifier) |
| 608d862 | 181 | (param |
| 608d862 | 182 | (var_identifier) |
| 608d862 | 183 | (type |
| 608d862 | 184 | (type_identifier))) |
| 608d862 | 185 | (param |
| 608d862 | 186 | (var_identifier) |
| 608d862 | 187 | (type |
| 608d862 | 188 | (type_identifier))) |
| 608d862 | 189 | (type |
| 608d862 | 190 | (type_identifier)) |
| 608d862 | 191 | (body |
| 608d862 | 192 | (match |
| 608d862 | 193 | (guard_case |
| 608d862 | 194 | (expression |
| 608d862 | 195 | (comparison_operator |
| 608d862 | 196 | (primary_expression |
| 608d862 | 197 | (var_identifier)) |
| 608d862 | 198 | (primary_expression |
| 608d862 | 199 | (var_identifier)))) |
| 608d862 | 200 | (body |
| 608d862 | 201 | (expression |
| 608d862 | 202 | (primary_expression |
| 608d862 | 203 | (integer))))) |
| 608d862 | 204 | (guard_case |
| 608d862 | 205 | (expression |
| 608d862 | 206 | (comparison_operator |
| 608d862 | 207 | (primary_expression |
| 608d862 | 208 | (var_identifier)) |
| 608d862 | 209 | (primary_expression |
| 608d862 | 210 | (var_identifier)))) |
| 608d862 | 211 | (body |
| 608d862 | 212 | (expression |
| 608d862 | 213 | (primary_expression |
| 608d862 | 214 | (integer))))) |
| 608d862 | 215 | (guard_case |
| 608d862 | 216 | (body |
| 608d862 | 217 | (expression |
| 608d862 | 218 | (primary_expression |
| 608d862 | 219 | (unary_operator |
| 608d862 | 220 | (primary_expression |
| 608d862 | 221 | (integer))))))))))) |