From 57e3f53598059dd4553ee0f5933ca60a11ad6d91 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 10 Mar 2026 17:29:33 +0100 Subject: Add the divrem (/%) operator --- grammar | 1 + oryxc/src/lexer.rs | 8 ++++++++ oryxc/src/parser.rs | 2 ++ 3 files changed, 11 insertions(+) diff --git a/grammar b/grammar index 5fa2e73..2042e97 100644 --- a/grammar +++ b/grammar @@ -48,6 +48,7 @@ binary-op | "-" | "*" | "/" + | "/%" /* Divrem */ | "%" /* Remainder */ | "%%" /* Modulus */ | "~" /* XOR */ diff --git a/oryxc/src/lexer.rs b/oryxc/src/lexer.rs index ace0a83..2dace02 100644 --- a/oryxc/src/lexer.rs +++ b/oryxc/src/lexer.rs @@ -60,6 +60,7 @@ pub enum TokenType { KeywordReturn, Number, Percent2, + SlashPercent, String, } @@ -220,6 +221,13 @@ pub fn tokenize(s: &str) -> Result, OryxError> { view: (i, j + 1), }) }, + '/' if ctx.peek().is_some_and(|c| c == '%') => { + ctx.next(); /* Consume ‘/’ */ + Some(Token { + kind: TokenType::SlashPercent, + view: (i, j + 1), + }) + }, '!' | '&' | '(' | ')' | '*' | '+' | ',' | '-' | '/' | ';' | '<' | '=' | '>' | '[' | ']' | '^' | '{' | '|' | '}' | '~' | '…' | '%' => Some(Token { diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs index 89e2769..70b530f 100644 --- a/oryxc/src/parser.rs +++ b/oryxc/src/parser.rs @@ -686,6 +686,7 @@ impl<'a> Parser<'a> { | TokenType::Asterisk | TokenType::Percent | TokenType::Percent2 + | TokenType::SlashPercent | TokenType::Slash => 5, TokenType::Bar | TokenType::Minus @@ -817,6 +818,7 @@ impl<'a> Parser<'a> { | TokenType::Percent2 | TokenType::Plus | TokenType::Slash + | TokenType::SlashPercent | TokenType::Tilde => { let i = self.cursor; self.next(); -- cgit v1.2.3