add for-range loops to El (for i in 0..n)

Adds `for i in start..end` (exclusive) and `for i in start..=end`
(inclusive) range loop syntax. Existing `for item in list` iteration
is preserved; the parser branches on DotDot/DotDotEq presence after
the start expression. Lexer adds DotDot and DotDotEq tokens with
longer-match-first priority. Codegen emits a C `for` loop with the
loop variable scoped to the statement; inclusive uses `<=`, exclusive `<`.
This commit is contained in:
Will Anderson
2026-05-03 15:44:58 -05:00
parent 49a8a1c24b
commit f271f9d9d8
3 changed files with 68 additions and 4 deletions
+18 -2
View File
@@ -698,8 +698,24 @@ fn lex(source: String) -> [Map<String, Any>] {
let i = i + 1
} else {
if ch == "." {
let tokens = native_list_append(tokens, make_tok("Dot", "."))
let i = i + 1
// Check for ..= (inclusive range) before .. (exclusive range) before single .
let peek2_i = i + 2
let peek2_ch = ""
if peek2_i < total {
let peek2_ch: String = native_list_get(chars, peek2_i)
}
if peek_ch == "." {
if peek2_ch == "=" {
let tokens = native_list_append(tokens, make_tok("DotDotEq", "..="))
let i = i + 3
} else {
let tokens = native_list_append(tokens, make_tok("DotDot", ".."))
let i = i + 2
}
} else {
let tokens = native_list_append(tokens, make_tok("Dot", "."))
let i = i + 1
}
} else {
if ch == ";" {
let tokens = native_list_append(tokens, make_tok("Semicolon", ";"))