@@ -368,19 +368,6 @@ parser_magic_comments(pm_parser_t *parser, VALUE source) {
368368 return magic_comments ;
369369}
370370
371- static VALUE get_diagnostic_level_symbol (uint8_t level ) {
372- switch (level ) {
373- case 0 :
374- return ID2SYM (rb_intern ("error_default" ));
375- case 1 :
376- return ID2SYM (rb_intern ("warning_verbose_not_nil" ));
377- case 2 :
378- return ID2SYM (rb_intern ("warning_verbose_true" ));
379- default :
380- rb_raise (rb_eRuntimeError , "Unknown level: %" PRIu8 , level );
381- }
382- }
383-
384371/**
385372 * Extract out the data location from the parser into a Location instance if one
386373 * exists.
@@ -415,10 +402,19 @@ parser_errors(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
415402 LONG2FIX (error -> location .end - error -> location .start )
416403 };
417404
405+ VALUE level = Qnil ;
406+ switch (error -> level ) {
407+ case PM_ERROR_LEVEL_FATAL :
408+ level = ID2SYM (rb_intern ("fatal" ));
409+ break ;
410+ default :
411+ rb_raise (rb_eRuntimeError , "Unknown level: %" PRIu8 , error -> level );
412+ }
413+
418414 VALUE error_argv [] = {
419415 rb_enc_str_new_cstr (error -> message , encoding ),
420416 rb_class_new_instance (3 , location_argv , rb_cPrismLocation ),
421- get_diagnostic_level_symbol ( error -> level )
417+ level
422418 };
423419
424420 rb_ary_push (errors , rb_class_new_instance (3 , error_argv , rb_cPrismParseError ));
@@ -442,10 +438,22 @@ parser_warnings(pm_parser_t *parser, rb_encoding *encoding, VALUE source) {
442438 LONG2FIX (warning -> location .end - warning -> location .start )
443439 };
444440
441+ VALUE level = Qnil ;
442+ switch (warning -> level ) {
443+ case PM_WARNING_LEVEL_DEFAULT :
444+ level = ID2SYM (rb_intern ("default" ));
445+ break ;
446+ case PM_WARNING_LEVEL_VERBOSE :
447+ level = ID2SYM (rb_intern ("verbose" ));
448+ break ;
449+ default :
450+ rb_raise (rb_eRuntimeError , "Unknown level: %" PRIu8 , warning -> level );
451+ }
452+
445453 VALUE warning_argv [] = {
446454 rb_enc_str_new_cstr (warning -> message , encoding ),
447455 rb_class_new_instance (3 , location_argv , rb_cPrismLocation ),
448- get_diagnostic_level_symbol ( warning -> level )
456+ level
449457 };
450458
451459 rb_ary_push (warnings , rb_class_new_instance (3 , warning_argv , rb_cPrismParseWarning ));
0 commit comments