diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-11-02 14:28:25 -0400 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-11-03 10:13:49 -0400 |
commit | 95d3f2eaec1456eb5a964c4622ccc723af020ef2 (patch) | |
tree | 4ddc6ca69c3f35a9c63172647f529603e1d2b8ba /prism | |
parent | 85af40c1d7e707b9f66138d863c69084fb5ae8ed (diff) |
[ruby/prism] Properly support the suppress_warnings option
https://github.com/ruby/prism/commit/84229529d7
Diffstat (limited to 'prism')
-rw-r--r-- | prism/parser.h | 7 | ||||
-rw-r--r-- | prism/prism.c | 11 |
2 files changed, 15 insertions, 3 deletions
diff --git a/prism/parser.h b/prism/parser.h index f4d0153e17..a30e61c9bf 100644 --- a/prism/parser.h +++ b/prism/parser.h @@ -672,6 +672,13 @@ struct pm_parser { * a true value. */ bool frozen_string_literal; + + /** + * Whether or not we should emit warnings. This will be set to false if the + * consumer of the library specified it, usually because they are parsing + * when $VERBOSE is nil. + */ + bool suppress_warnings; }; #endif diff --git a/prism/prism.c b/prism/prism.c index cfb32ded66..0e135db5cb 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -508,7 +508,9 @@ pm_parser_err_token(pm_parser_t *parser, const pm_token_t *token, pm_diagnostic_ */ static inline void pm_parser_warn(pm_parser_t *parser, const uint8_t *start, const uint8_t *end, pm_diagnostic_id_t diag_id) { - pm_diagnostic_list_append(&parser->warning_list, start, end, diag_id); + if (!parser->suppress_warnings) { + pm_diagnostic_list_append(&parser->warning_list, start, end, diag_id); + } } /** @@ -16364,7 +16366,8 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm .pattern_matching_newlines = false, .in_keyword_arg = false, .semantic_token_seen = false, - .frozen_string_literal = false + .frozen_string_literal = false, + .suppress_warnings = false }; // Initialize the constant pool. We're going to completely guess as to the @@ -16413,7 +16416,9 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm } // suppress_warnings option - // if (options->suppress_warnings) {} + if (options->suppress_warnings) { + parser->suppress_warnings = true; + } // scopes option for (size_t scope_index = 0; scope_index < options->scopes_count; scope_index++) { |