MCPcopy Create free account
hub / github.com/aiscriptdev/aiscript / parse_range_pattern

Method parse_range_pattern

aiscript-vm/src/parser/mod.rs:2129–2168  ·  view source on GitHub ↗
(&mut self, start: Option<Box<Expr<'gc>>>)

Source from the content-addressed store, hash-verified

2127 }
2128
2129 fn parse_range_pattern(&mut self, start: Option<Box<Expr<'gc>>>) -> Option<MatchPattern<'gc>> {
2130 let inclusive = self.match_token(TokenType::DotDotEq);
2131 if !inclusive && !self.match_token(TokenType::DotDot) {
2132 self.error_at_current("Expected '..' or '..=' in range pattern.");
2133 return None;
2134 }
2135
2136 let end = if self.check(TokenType::FatArrow) || self.check(TokenType::Comma) {
2137 None
2138 } else {
2139 Some(Box::new(self.expression()?))
2140 };
2141
2142 // Validate range values if both are literals
2143 if let (Some(box_start), Some(box_end)) = (&start, &end) {
2144 if let (
2145 Expr::Literal {
2146 value: start_val, ..
2147 },
2148 Expr::Literal { value: end_val, .. },
2149 ) = (&**box_start, &**box_end)
2150 {
2151 match (start_val, end_val) {
2152 (Literal::Number(s), Literal::Number(e)) if s > e => {
2153 self.error("Invalid range pattern: start value must be less than or equal to end value.");
2154 }
2155 (Literal::Number(_), Literal::Number(_)) => {}
2156 _ => {
2157 self.error("Range patterns only support numeric values.");
2158 }
2159 }
2160 }
2161 }
2162
2163 Some(MatchPattern::Range {
2164 start,
2165 end,
2166 inclusive,
2167 })
2168 }
2169
2170 fn parse_literal(&mut self, token: Token<'gc>) -> Option<Literal<'gc>> {
2171 match token.kind {

Callers 1

match_patternMethod · 0.80

Calls 5

match_tokenMethod · 0.80
error_at_currentMethod · 0.80
checkMethod · 0.80
expressionMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected