tree-sitter-omega
aien-dev/tree-sitter-omega
Brought by drakestapleton
tree-sitter-omega / test / corpus / basics.txt
| 1 | ================================================================================ |
| 2 | Note lines and a text program |
| 3 | ================================================================================ |
| 4 | |
| 5 | note text bytes with every escape are written to stdout and read back with get and len |
| 6 | text t "a\tb\\c\"d\ne" |
| 7 | global g uchar 16 |
| 8 | fn main to int |
| 9 | n = write int 1 t ulong 0 len t |
| 10 | put g 0 get t 2 |
| 11 | ret add int get t 0 int add len t ulong get g 0 |
| 12 | end |
| 13 | |
| 14 | -------------------------------------------------------------------------------- |
| 15 | |
| 16 | (source_file |
| 17 | (comment) |
| 18 | (text_declaration |
| 19 | (identifier) |
| 20 | (string |
| 21 | (string_content) |
| 22 | (escape_sequence) |
| 23 | (string_content) |
| 24 | (escape_sequence) |
| 25 | (string_content) |
| 26 | (escape_sequence) |
| 27 | (string_content) |
| 28 | (escape_sequence) |
| 29 | (string_content))) |
| 30 | (global_declaration |
| 31 | (identifier) |
| 32 | (identifier) |
| 33 | (integer)) |
| 34 | (function_definition |
| 35 | (identifier) |
| 36 | (return_type |
| 37 | (identifier)) |
| 38 | (block |
| 39 | (assignment |
| 40 | (identifier) |
| 41 | (expression |
| 42 | (identifier) |
| 43 | (identifier) |
| 44 | (integer) |
| 45 | (identifier) |
| 46 | (identifier) |
| 47 | (integer) |
| 48 | (identifier) |
| 49 | (identifier))) |
| 50 | (put_statement |
| 51 | (expression |
| 52 | (identifier) |
| 53 | (integer) |
| 54 | (identifier) |
| 55 | (identifier) |
| 56 | (integer))) |
| 57 | (return_statement |
| 58 | (expression |
| 59 | (identifier) |
| 60 | (identifier) |
| 61 | (identifier) |
| 62 | (identifier) |
| 63 | (integer) |
| 64 | (identifier) |
| 65 | (identifier) |
| 66 | (identifier) |
| 67 | (identifier) |
| 68 | (identifier) |
| 69 | (identifier) |
| 70 | (identifier) |
| 71 | (integer)))))) |
| 72 | |
| 73 | ================================================================================ |
| 74 | Assignment without = and a void call |
| 75 | ================================================================================ |
| 76 | |
| 77 | fn gcd a uint b uint to uint |
| 78 | while ne b 0 bound 100 |
| 79 | t rem a b |
| 80 | a = b |
| 81 | b = t |
| 82 | end |
| 83 | ret a |
| 84 | end |
| 85 | fn hello to void |
| 86 | ret |
| 87 | end |
| 88 | fn main to int |
| 89 | hello |
| 90 | ret int gcd 12 18 |
| 91 | end |
| 92 | |
| 93 | -------------------------------------------------------------------------------- |
| 94 | |
| 95 | (source_file |
| 96 | (function_definition |
| 97 | (identifier) |
| 98 | (parameter_list |
| 99 | (identifier) |
| 100 | (identifier) |
| 101 | (identifier) |
| 102 | (identifier)) |
| 103 | (return_type |
| 104 | (identifier)) |
| 105 | (block |
| 106 | (while_statement |
| 107 | (expression |
| 108 | (identifier) |
| 109 | (identifier) |
| 110 | (integer)) |
| 111 | (integer) |
| 112 | (block |
| 113 | (expression_statement |
| 114 | (expression |
| 115 | (identifier) |
| 116 | (identifier) |
| 117 | (identifier) |
| 118 | (identifier))) |
| 119 | (assignment |
| 120 | (identifier) |
| 121 | (expression |
| 122 | (identifier))) |
| 123 | (assignment |
| 124 | (identifier) |
| 125 | (expression |
| 126 | (identifier))))) |
| 127 | (return_statement |
| 128 | (expression |
| 129 | (identifier))))) |
| 130 | (function_definition |
| 131 | (identifier) |
| 132 | (return_type |
| 133 | (identifier)) |
| 134 | (block |
| 135 | (return_statement))) |
| 136 | (function_definition |
| 137 | (identifier) |
| 138 | (return_type |
| 139 | (identifier)) |
| 140 | (block |
| 141 | (expression_statement |
| 142 | (expression |
| 143 | (identifier))) |
| 144 | (return_statement |
| 145 | (expression |
| 146 | (identifier) |
| 147 | (identifier) |
| 148 | (integer) |
| 149 | (integer)))))) |
| 150 | |
| 151 | ================================================================================ |
| 152 | If, else, for, break, continue, trap, exit |
| 153 | ================================================================================ |
| 154 | |
| 155 | fn main to int |
| 156 | s = ulong 0 |
| 157 | for i ulong 10 |
| 158 | if eq rem i 2 0 |
| 159 | continue |
| 160 | else |
| 161 | s = add s i |
| 162 | end |
| 163 | if gt s 20 |
| 164 | break |
| 165 | end |
| 166 | end |
| 167 | if eq s 0 |
| 168 | trap 4 |
| 169 | end |
| 170 | exit int s |
| 171 | end |
| 172 | |
| 173 | -------------------------------------------------------------------------------- |
| 174 | |
| 175 | (source_file |
| 176 | (function_definition |
| 177 | (identifier) |
| 178 | (return_type |
| 179 | (identifier)) |
| 180 | (block |
| 181 | (assignment |
| 182 | (identifier) |
| 183 | (expression |
| 184 | (identifier) |
| 185 | (integer))) |
| 186 | (for_statement |
| 187 | (identifier) |
| 188 | (expression |
| 189 | (identifier) |
| 190 | (integer)) |
| 191 | (block |
| 192 | (if_statement |
| 193 | (expression |
| 194 | (identifier) |
| 195 | (identifier) |
| 196 | (identifier) |
| 197 | (integer) |
| 198 | (integer)) |
| 199 | (block |
| 200 | (continue_statement)) |
| 201 | (else_clause |
| 202 | (block |
| 203 | (assignment |
| 204 | (identifier) |
| 205 | (expression |
| 206 | (identifier) |
| 207 | (identifier) |
| 208 | (identifier)))))) |
| 209 | (if_statement |
| 210 | (expression |
| 211 | (identifier) |
| 212 | (identifier) |
| 213 | (integer)) |
| 214 | (block |
| 215 | (break_statement))))) |
| 216 | (if_statement |
| 217 | (expression |
| 218 | (identifier) |
| 219 | (identifier) |
| 220 | (integer)) |
| 221 | (block |
| 222 | (trap_statement |
| 223 | (expression |
| 224 | (integer))))) |
| 225 | (exit_statement |
| 226 | (expression |
| 227 | (identifier) |
| 228 | (identifier)))))) |
| 229 | |
| 230 | ================================================================================ |
| 231 | A note line with no text and a word that starts with note |
| 232 | ================================================================================ |
| 233 | |
| 234 | note |
| 235 | fn main to int |
| 236 | notes = int 1 |
| 237 | ret notes |
| 238 | end |
| 239 | |
| 240 | -------------------------------------------------------------------------------- |
| 241 | |
| 242 | (source_file |
| 243 | (comment) |
| 244 | (function_definition |
| 245 | (identifier) |
| 246 | (return_type |
| 247 | (identifier)) |
| 248 | (block |
| 249 | (assignment |
| 250 | (identifier) |
| 251 | (expression |
| 252 | (identifier) |
| 253 | (integer))) |
| 254 | (return_statement |
| 255 | (expression |
| 256 | (identifier)))))) |