1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Control flow instructions
//!
//! Provides four control flow instructions for script execution:
//! - `loop`: Start a loop (finite or infinite)
//! - `end`: End a loop or other block structure
//! - `break`: Exit current loop immediately
//! - `continue`: Skip to next iteration
//!
//! # Instructions
//!
//! ## `loop` - Start a loop
//!
//! Begins a loop block that can run a fixed number of times or infinitely.
//!
//! **Syntax:** `loop [iterations]`
//!
//! **Parameters:**
//! - `[iterations]` (optional): Number of times to repeat (default: infinite)
//! - If omitted, creates an infinite loop (must use `break` to exit)
//! - Must be greater than 0 if specified
//!
//! **Examples:**
//! ```text
//! loop 5 # Run 5 times
//! loop # Infinite loop (use break to exit)
//! ```
//!
//! ---
//!
//! ## `end` - End a block
//!
//! Marks the end of a loop or other block structure.
//! For loops, checks counter and jumps back if iterations remain.
//!
//! **Syntax:** `end`
//!
//! **Parameters:** None
//!
//! **Examples:**
//! ```text
//! loop 3
//! key A
//! end # End of loop
//! ```
//!
//! ---
//!
//! ## `break` - Exit loop early
//!
//! Immediately exits the current loop and continues after the `end`.
//!
//! **Syntax:** `break`
//!
//! **Parameters:** None
//!
//! **Examples:**
//! ```text
//! loop 10
//! key A
//! break # Exit loop immediately
//! end
//! ```
//!
//! ---
//!
//! ## `continue` - Skip to next iteration
//!
//! Skips the remaining loop body and proceeds to the next iteration.
//!
//! **Syntax:** `continue`
//!
//! **Parameters:** None
//!
//! **Examples:**
//! ```text
//! loop 10
//! key A
//! continue # Skip remaining body
//! key B # This won't execute
//! end
//! ```
//!
//! ---
//!
//! # Common Use Cases
//!
//! ## Fixed Iteration Loop
//! ```text
//! loop 5
//! key H
//! key E
//! key L
//! key L
//! key O
//! end
//! ```
//!
//! ## Infinite Loop with Break
//! ```text
//! loop
//! find_color 0xFF0000
//! if_found
//! break
//! end
//! sleep 100
//! end
//! ```
//!
//! ## Conditional Skip with Continue
//! ```text
//! loop 10
//! key A
//! if_condition
//! continue # Skip key B on this iteration
//! end
//! key B
//! end
//! ```
//!
//! ## Nested Loops
//! ```text
//! loop 3 # Outer loop
//! loop 2 # Inner loop
//! key X
//! end
//! key Y
//! end
//! ```
//!
//! ---
//!
//! # Important Notes
//!
//! 1. **Loop boundaries**: Every `loop` must have a matching `end`. The compiler validates this at compile time.
//!
//! 2. **Break/Continue scope**: These instructions only affect the innermost loop. For nested loops, they don't affect outer loops.
//!
//! 3. **Infinite loops**: When using `loop` without iterations, ensure there's a `break` condition to avoid hanging scripts.
//!
//! 4. **Zero iterations not allowed**: `loop 0` will cause a parse error. Minimum is 1.
//!
// Submodules - each instruction handler in its own file
// Re-export handlers for convenience
pub use ;
pub use BreakHandler;
pub use ContinueHandler;