Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions src/tealang.pest
Original file line number Diff line number Diff line change
Expand Up @@ -84,38 +84,36 @@ num = @{
| (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT*)
}

// Identifier: starts with letter or underscore, followed by letters, digits, or underscores
// Cannot be a keyword (enforced by negative lookaheads)
// Examples: "x", "count", "my_getint", "quickread", "arr", "head", "tail", "inq"
identifier = @{
!kw_let ~ !kw_fn ~ !kw_struct ~ !kw_if ~ !kw_else ~ !kw_while ~
!kw_break ~ !kw_continue ~ !kw_return ~ !kw_i32 ~ !kw_use ~
(ASCII_ALPHA | "_") ~ (ASCII_ALPHA | ASCII_DIGIT | "_")*
}

// Keywords (using @ for atomic rules to prevent whitespace inside)
// Example: "let x:i32 = 0;"
kw_let = @{ "let" }
kw_let = @{ "let" ~ WHITESPACE }
// Example: "fn main() -> i32 { }"
kw_fn = @{ "fn" }
kw_fn = @{ "fn" ~ WHITESPACE }
// Example: "struct Node { value:i32, next:i32 }"
kw_struct = @{ "struct" }
kw_struct = @{ "struct" ~ WHITESPACE }
// Example: "if x > 0 { }"
kw_if = @{ "if" }
kw_if = @{ "if" ~ WHITESPACE }
// Example: "if x > 0 { } else { }"
kw_else = @{ "else" }
kw_else = @{ "else" ~ &(WHITESPACE | lbrace) }
// Example: "while i < 10 { i = i + 1; }"
kw_while = @{ "while" }
kw_while = @{ "while" ~ WHITESPACE }
// Example: "while 1 > 0 { if done { break; } }"
kw_break = @{ "break" }
kw_break = @{ "break" ~ &(WHITESPACE | semicolon) }
// Example: "while i < n { if inq[temp] == 0 { continue; } i = i + 1; }"
kw_continue = @{ "continue" }
kw_continue = @{ "continue" ~ &(WHITESPACE | semicolon) }
// Example: "return 0;" or "return sum;"
kw_return = @{ "return" }
kw_return = @{ "return" ~ &(WHITESPACE | semicolon) }
// Example: "let count:i32 = 0;"
kw_i32 = @{ "i32" }
kw_i32 = @{ "i32" ~ &(WHITESPACE | semicolon | comma | rparen | lbrace | rbrace | rbracket | op_assign) }
// Example: "use std;"
kw_use = @{ "use" }
kw_use = @{ "use" ~ WHITESPACE }

// Identifier: starts with letter or underscore, followed by letters, digits, or underscores
// Cannot be a keyword (enforced by negative lookaheads)
// Examples: "x", "count", "my_getint", "quickread", "arr", "head", "tail", "inq"
identifier = @{
(ASCII_ALPHA | "_") ~ (ASCII_ALPHA | ASCII_DIGIT | "_")*
}

// Types
// Type specification: integer type or user-defined type
Expand Down
Loading