2025-09-17 07:43:07 +09:00
|
|
|
use crate::ast::{ASTNode, BinaryOperator, 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;
|
|
|
|
|
|
|
|
|
|
impl NyashParser {
|
|
|
|
|
pub(crate) fn expr_parse_or(&mut self) -> Result<ASTNode, ParseError> {
|
|
|
|
|
let mut expr = self.expr_parse_and()?;
|
|
|
|
|
while self.match_token(&TokenType::OR) {
|
|
|
|
|
let operator = BinaryOperator::Or;
|
|
|
|
|
self.advance();
|
|
|
|
|
let right = self.expr_parse_and()?;
|
|
|
|
|
if std::env::var("NYASH_GRAMMAR_DIFF").ok().as_deref() == Some("1") {
|
|
|
|
|
let ok = crate::grammar::engine::get().syntax_is_allowed_binop("or");
|
2025-09-17 07:43:07 +09:00
|
|
|
if !ok {
|
|
|
|
|
eprintln!("[GRAMMAR-DIFF][Parser] binop 'or' not allowed by syntax rules");
|
|
|
|
|
}
|
2025-09-17 05:56:33 +09:00
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
expr = ASTNode::BinaryOp {
|
|
|
|
|
operator,
|
|
|
|
|
left: Box::new(expr),
|
|
|
|
|
right: Box::new(right),
|
|
|
|
|
span: Span::unknown(),
|
|
|
|
|
};
|
2025-09-17 05:56:33 +09:00
|
|
|
}
|
|
|
|
|
Ok(expr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub(crate) fn expr_parse_and(&mut self) -> Result<ASTNode, ParseError> {
|
2025-09-17 06:55:39 +09:00
|
|
|
let mut expr = self.expr_parse_bit_or()?;
|
2025-09-17 05:56:33 +09:00
|
|
|
while self.match_token(&TokenType::AND) {
|
|
|
|
|
let operator = BinaryOperator::And;
|
|
|
|
|
self.advance();
|
2025-09-17 06:55:39 +09:00
|
|
|
let right = self.expr_parse_equality()?;
|
2025-09-17 05:56:33 +09:00
|
|
|
if std::env::var("NYASH_GRAMMAR_DIFF").ok().as_deref() == Some("1") {
|
|
|
|
|
let ok = crate::grammar::engine::get().syntax_is_allowed_binop("and");
|
2025-09-17 07:43:07 +09:00
|
|
|
if !ok {
|
|
|
|
|
eprintln!("[GRAMMAR-DIFF][Parser] binop 'and' not allowed by syntax rules");
|
|
|
|
|
}
|
2025-09-17 05:56:33 +09:00
|
|
|
}
|
2025-09-17 07:43:07 +09:00
|
|
|
expr = ASTNode::BinaryOp {
|
|
|
|
|
operator,
|
|
|
|
|
left: Box::new(expr),
|
|
|
|
|
right: Box::new(right),
|
|
|
|
|
span: Span::unknown(),
|
|
|
|
|
};
|
2025-09-17 05:56:33 +09:00
|
|
|
}
|
|
|
|
|
Ok(expr)
|
|
|
|
|
}
|
|
|
|
|
}
|