diff --git a/src/analyze/analyzed_ruby.c b/src/analyze/analyzed_ruby.c index 30f534186..52794bffc 100644 --- a/src/analyze/analyzed_ruby.c +++ b/src/analyze/analyzed_ruby.c @@ -48,22 +48,22 @@ void free_analyzed_ruby(analyzed_ruby_T* analyzed) { free(analyzed); } -const char* erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed) { +hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed) { if (analyzed->end_count > 0) { - return "`<% end %>`"; + return hb_string("`<% end %>`"); } else if (analyzed->else_node_count > 0) { - return "`<% else %>`"; + return hb_string("`<% else %>`"); } else if (analyzed->elsif_node_count > 0) { - return "`<% elsif %>`"; + return hb_string("`<% elsif %>`"); } else if (analyzed->when_node_count > 0) { - return "`<% when %>`"; + return hb_string("`<% when %>`"); } else if (analyzed->in_node_count > 0) { - return "`<% in %>`"; + return hb_string("`<% in %>`"); } else if (analyzed->rescue_node_count > 0) { - return "`<% rescue %>`"; + return hb_string("`<% rescue %>`"); } else if (analyzed->ensure_node_count > 0) { - return "`<% ensure %>`"; + return hb_string("`<% ensure %>`"); } - return NULL; + return HB_STRING_NULL; } diff --git a/src/analyze/invalid_structures.c b/src/analyze/invalid_structures.c index 4681553e3..0a765f62a 100644 --- a/src/analyze/invalid_structures.c +++ b/src/analyze/invalid_structures.c @@ -49,15 +49,15 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) { return true; } - const char* keyword = NULL; + hb_string_T keyword = HB_STRING_NULL; if (context->loop_depth == 0) { if (has_error_message(analyzed, "Invalid break")) { - keyword = "`<% break %>`"; + keyword = hb_string("`<% break %>`"); } else if (has_error_message(analyzed, "Invalid next")) { - keyword = "`<% next %>`"; + keyword = hb_string("`<% next %>`"); } else if (has_error_message(analyzed, "Invalid redo")) { - keyword = "`<% redo %>`"; + keyword = hb_string("`<% redo %>`"); } } else { if (has_error_message(analyzed, "Invalid redo") || has_error_message(analyzed, "Invalid break") @@ -71,7 +71,7 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) { } if (context->rescue_depth == 0) { - if (has_error_message(analyzed, "Invalid retry without rescue")) { keyword = "`<% retry %>`"; } + if (has_error_message(analyzed, "Invalid retry without rescue")) { keyword = hb_string("`<% retry %>`"); } } else { if (has_error_message(analyzed, "Invalid retry without rescue")) { if (is_loop_node) { context->loop_depth--; } @@ -81,11 +81,11 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) { } } - if (keyword == NULL) { keyword = erb_keyword_from_analyzed_ruby(analyzed); } + if (hb_string_is_null(keyword)) { keyword = erb_keyword_from_analyzed_ruby(analyzed); } - if (keyword != NULL && !token_value_empty(content_node->tag_closing)) { + if (!hb_string_is_null(keyword) && !token_value_empty(content_node->tag_closing)) { append_erb_control_flow_scope_error( - hb_string(keyword), + keyword, node->location.start, node->location.end, context->allocator, @@ -116,11 +116,11 @@ bool detect_invalid_erb_structures(const AST_NODE_T* node, void* data) { if (content_node->parsed && !content_node->valid && content_node->analyzed_ruby != NULL) { analyzed_ruby_T* analyzed = content_node->analyzed_ruby; - const char* keyword = erb_keyword_from_analyzed_ruby(analyzed); + hb_string_T keyword = erb_keyword_from_analyzed_ruby(analyzed); if (!token_value_empty(content_node->tag_closing)) { append_erb_control_flow_scope_error( - hb_string(keyword), + keyword, subsequent->location.start, subsequent->location.end, context->allocator, diff --git a/src/include/analyze/analyzed_ruby.h b/src/include/analyze/analyzed_ruby.h index 12387c755..25b12ca8a 100644 --- a/src/include/analyze/analyzed_ruby.h +++ b/src/include/analyze/analyzed_ruby.h @@ -35,6 +35,6 @@ typedef struct ANALYZED_RUBY_STRUCT { analyzed_ruby_T* init_analyzed_ruby(hb_string_T source); void free_analyzed_ruby(analyzed_ruby_T* analyzed); -const char* erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed); +hb_string_T erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed); #endif diff --git a/src/include/prism_helpers.h b/src/include/prism_helpers.h index 62767b984..3c7c9453f 100644 --- a/src/include/prism_helpers.h +++ b/src/include/prism_helpers.h @@ -10,7 +10,7 @@ #include -const char* pm_error_level_to_string(pm_error_level_t level); +hb_string_T pm_error_level_to_string(pm_error_level_t level); RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error( const pm_diagnostic_t* error, diff --git a/src/prism_helpers.c b/src/prism_helpers.c index f9a310bb0..46fde9d85 100644 --- a/src/prism_helpers.c +++ b/src/prism_helpers.c @@ -10,13 +10,11 @@ #include #include -const char* pm_error_level_to_string(pm_error_level_t level) { +hb_string_T pm_error_level_to_string(pm_error_level_t level) { switch (level) { - case PM_ERROR_LEVEL_SYNTAX: return "syntax"; - case PM_ERROR_LEVEL_ARGUMENT: return "argument"; - case PM_ERROR_LEVEL_LOAD: return "load"; - - default: return "Unknown pm_error_level_t"; + case PM_ERROR_LEVEL_SYNTAX: return hb_string("syntax"); + case PM_ERROR_LEVEL_ARGUMENT: return hb_string("argument"); + case PM_ERROR_LEVEL_LOAD: return hb_string("load"); } } @@ -36,7 +34,7 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error( return ruby_parse_error_init( hb_string(error->message), hb_string(pm_diagnostic_id_human(error->diag_id)), - hb_string(pm_error_level_to_string(error->level)), + pm_error_level_to_string(error->level), start, end, allocator @@ -52,7 +50,7 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions( return ruby_parse_error_init( hb_string(error->message), hb_string(pm_diagnostic_id_human(error->diag_id)), - hb_string(pm_error_level_to_string(error->level)), + pm_error_level_to_string(error->level), start, end, allocator