Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/analyze/analyzed_ruby.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
20 changes: 10 additions & 10 deletions src/analyze/invalid_structures.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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--; }
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/include/analyze/analyzed_ruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/include/prism_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <prism.h>

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,
Expand Down
14 changes: 6 additions & 8 deletions src/prism_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
#include <stdlib.h>
#include <string.h>

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");
}
}

Expand All @@ -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
Expand All @@ -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
Expand Down
Loading