mruby-compiler: add one-line pattern matching

add support for one-line pattern matching syntax:
- 'expr in pattern' returns true/false
- 'expr => pattern' raises NoMatchingPatternError on mismatch

add NODE_MATCH_PAT node type for both forms, distinguished by
raise_on_fail flag. grammar rules placed at expr level to avoid
conflict with rescue clause's exception variable syntax.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-12-17 16:37:12 +09:00
parent e8096bf745
commit e76ce24860
5 changed files with 5744 additions and 5520 deletions
+1
View File
@@ -920,6 +920,7 @@ mrb_init_exception(mrb_state *mrb)
mrb_define_class_id(mrb, MRB_SYM(SyntaxError), script_error); /* 15.2.38 */
struct RClass *index_error = mrb_define_class_id(mrb, MRB_SYM(IndexError), E_STANDARD_ERROR); /* 15.2.33 */
mrb_define_class_id(mrb, MRB_SYM(KeyError), index_error);
mrb_define_class_id(mrb, MRB_SYM(NoMatchingPatternError), E_STANDARD_ERROR); /* pattern matching */
struct RClass *stack_error = mrb_define_class_id(mrb, MRB_SYM(SystemStackError), exception);
mrb->stack_err = mrb_obj_ptr(mrb_exc_new_lit(mrb, stack_error, "stack level too deep"));