resolve: apply stashed using/module + deps bridge; remove conflict markers in runner/mod.rs

This commit is contained in:
Selfhosting Dev
2025-09-08 04:35:50 +09:00
parent da5fa600d2
commit f22082f67c
18 changed files with 685 additions and 67 deletions

View File

@ -19,6 +19,9 @@ impl NyashParser {
TokenType::BOX => {
self.parse_box_declaration()
},
TokenType::IMPORT => {
self.parse_import()
},
TokenType::INTERFACE => {
self.parse_interface_box_declaration()
},
@ -117,6 +120,32 @@ impl NyashParser {
}
result
}
/// import文をパース: import "path" (as Alias)?
pub(super) fn parse_import(&mut self) -> Result<ASTNode, ParseError> {
self.advance(); // consume 'import'
let path = if let TokenType::STRING(s) = &self.current_token().token_type {
let v = s.clone();
self.advance();
v
} else {
return Err(ParseError::UnexpectedToken { found: self.current_token().token_type.clone(), expected: "string literal".to_string(), line: self.current_token().line });
};
// Optional: 'as' Alias (treat 'as' as identifier literal)
let mut alias: Option<String> = None;
if let TokenType::IDENTIFIER(w) = &self.current_token().token_type {
if w == "as" {
self.advance();
if let TokenType::IDENTIFIER(name) = &self.current_token().token_type {
alias = Some(name.clone());
self.advance();
} else {
return Err(ParseError::UnexpectedToken { found: self.current_token().token_type.clone(), expected: "alias name".to_string(), line: self.current_token().line });
}
}
}
Ok(ASTNode::ImportStatement { path, alias, span: Span::unknown() })
}
/// if文をパース: if (condition) { body } else if ... else { body }
pub(super) fn parse_if(&mut self) -> Result<ASTNode, ParseError> {