2025-09-17 07:43:07 +09:00
|
|
|
use crate::ast::{ASTNode, Span};
|
2025-09-17 05:56:33 +09:00
|
|
|
use crate::parser::common::ParserUtils;
|
2025-09-17 07:43:07 +09:00
|
|
|
use crate::parser::{NyashParser, ParseError};
|
2025-09-17 05:56:33 +09:00
|
|
|
use crate::tokenizer::TokenType;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
2025-09-17 07:43:07 +09:00
|
|
|
fn is_sugar_enabled() -> bool {
|
|
|
|
|
crate::parser::sugar_gate::is_enabled()
|
|
|
|
|
}
|
2025-09-17 05:56:33 +09:00
|
|
|
|
|
|
|
|
impl NyashParser {
|
|
|
|
|
pub(crate) fn expr_parse_coalesce(&mut self) -> Result<ASTNode, ParseError> {
|
|
|
|
|
let mut expr = self.expr_parse_or()?;
|
|
|
|
|
while self.match_token(&TokenType::QmarkQmark) {
|
|
|
|
|
if !is_sugar_enabled() {
|
|
|
|
|
let line = self.current_token().line;
|
|
|
|
|
return Err(ParseError::UnexpectedToken {
|
|
|
|
|
found: self.current_token().token_type.clone(),
|
|
|
|
|
expected: "enable NYASH_SYNTAX_SUGAR_LEVEL=basic|full for '??'".to_string(),
|
|
|
|
|
line,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
self.advance();
|
|
|
|
|
let rhs = self.expr_parse_or()?;
|
|
|
|
|
let scr = expr;
|
2025-09-23 09:00:07 +09:00
|
|
|
expr = ASTNode::MatchExpr {
|
2025-09-17 05:56:33 +09:00
|
|
|
scrutinee: Box::new(scr.clone()),
|
|
|
|
|
arms: vec![(crate::ast::LiteralValue::Null, rhs)],
|
|
|
|
|
else_expr: Box::new(scr),
|
|
|
|
|
span: Span::unknown(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
Ok(expr)
|
|
|
|
|
}
|
|
|
|
|
}
|