🚀 feat: Multiple improvements for Nyash parser and LLVM backend
Parser improvements: - Added expression statement fallback in parse_statement() for flexible syntax - Fixed ternary operator to use PeekExpr instead of If AST (better lowering) - Added peek_token() check to avoid ?/?: operator conflicts LLVM Python improvements: - Added optional ESC_JSON_FIX environment flag for string concatenation - Improved PHI generation with better default handling - Enhanced substring tracking for esc_json pattern Documentation updates: - Updated language guide with peek expression examples - Added box theory diagrams to Phase 15 planning - Clarified peek vs when syntax differences These changes enable cleaner parser implementation for self-hosting, especially for handling digit conversion with peek expressions instead of 19-line if-else chains. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -86,8 +86,9 @@ impl NyashParser {
|
||||
self.parse_assignment_or_function_call()
|
||||
}
|
||||
_ => {
|
||||
let line = self.current_token().line;
|
||||
Err(ParseError::InvalidStatement { line })
|
||||
// Fallback: treat as expression statement
|
||||
// Allows forms like: print("x") or a bare literal as the last value in a block
|
||||
Ok(self.parse_expression()?)
|
||||
}
|
||||
};
|
||||
|
||||
@ -246,13 +247,12 @@ impl NyashParser {
|
||||
/// return文をパース
|
||||
pub(super) fn parse_return(&mut self) -> Result<ASTNode, ParseError> {
|
||||
self.advance(); // consume 'return'
|
||||
|
||||
// returnの後に式があるかチェック
|
||||
let value = if self.is_at_end() || self.match_token(&TokenType::NEWLINE) {
|
||||
// return単体の場合はvoidを返す
|
||||
// 許容: 改行をスキップしてから式有無を判定
|
||||
self.skip_newlines();
|
||||
// returnの後に式があるかチェック(RBRACE/EOFなら値なし)
|
||||
let value = if self.is_at_end() || self.match_token(&TokenType::RBRACE) {
|
||||
None
|
||||
} else {
|
||||
// 式をパースして返す
|
||||
Some(Box::new(self.parse_expression()?))
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user