refactor: split optimizer/verifier/parser modules (mainline); add runner trace/directives; add LLVM terminator/select scaffolds; extract AST Span; update CURRENT_TASK with remaining plan
This commit is contained in:
26
src/parser/expr/ternary.rs
Normal file
26
src/parser/expr/ternary.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use crate::parser::{NyashParser, ParseError};
|
||||
use crate::parser::common::ParserUtils;
|
||||
use crate::tokenizer::TokenType;
|
||||
use crate::ast::{ASTNode, Span};
|
||||
|
||||
#[inline]
|
||||
fn is_sugar_enabled() -> bool { crate::parser::sugar_gate::is_enabled() }
|
||||
|
||||
impl NyashParser {
|
||||
pub(crate) fn expr_parse_ternary(&mut self) -> Result<ASTNode, ParseError> {
|
||||
let cond = self.expr_parse_coalesce()?;
|
||||
if self.match_token(&TokenType::QUESTION) {
|
||||
self.advance();
|
||||
let then_expr = self.parse_expression()?;
|
||||
self.consume(TokenType::COLON)?;
|
||||
let else_expr = self.parse_expression()?;
|
||||
return Ok(ASTNode::If {
|
||||
condition: Box::new(cond),
|
||||
then_body: vec![then_expr],
|
||||
else_body: Some(vec![else_expr]),
|
||||
span: Span::unknown(),
|
||||
});
|
||||
}
|
||||
Ok(cond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user