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
5 changes: 3 additions & 2 deletions src/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "include/util.h"
#include "include/util/hb_array.h"
#include "include/util/hb_string.h"
#include "include/util/string.h"
#include "include/visitor.h"

#include <prism.h>
Expand Down Expand Up @@ -60,8 +61,8 @@ static bool analyze_erb_content(const AST_NODE_T* node, void* data) {

const char* opening = erb_content_node->tag_opening->value;

if (strcmp(opening, "<%%") != 0 && strcmp(opening, "<%%=") != 0 && strcmp(opening, "<%#") != 0
&& strcmp(opening, "<%graphql") != 0) {
if (!string_equals(opening, "<%%") && !string_equals(opening, "<%%=") && !string_equals(opening, "<%#")
&& !string_equals(opening, "<%graphql")) {
analyzed_ruby_T* analyzed = herb_analyze_ruby(hb_string(erb_content_node->content->value));

erb_content_node->parsed = true;
Expand Down
3 changes: 2 additions & 1 deletion src/analyze_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>

#include "include/analyzed_ruby.h"
#include "include/util/string.h"

bool has_if_node(analyzed_ruby_T* analyzed) {
return analyzed->if_node_count > 0;
Expand Down Expand Up @@ -83,7 +84,7 @@ bool has_then_keyword(analyzed_ruby_T* analyzed) {
bool has_error_message(analyzed_ruby_T* anlayzed, const char* message) {
for (const pm_diagnostic_t* error = (const pm_diagnostic_t*) anlayzed->parser.error_list.head; error != NULL;
error = (const pm_diagnostic_t*) error->node.next) {
if (strcmp(error->message, message) == 0) { return true; }
if (string_equals(error->message, message)) { return true; }
}

return false;
Expand Down
7 changes: 4 additions & 3 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "include/lexer.h"
#include "include/util/hb_array.h"
#include "include/util/hb_buffer.h"
#include "include/util/string.h"

#include <stdlib.h>
#include <string.h>
Expand All @@ -22,11 +23,11 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
}

case TOKEN_ERB_START: {
if (strcmp(token->value, "<%#") == 0) {
if (string_equals(token->value, "<%#")) {
skip_erb_content = true;
is_comment_tag = true;
} else if (strcmp(token->value, "<%%") == 0 || strcmp(token->value, "<%%=") == 0
|| strcmp(token->value, "<%graphql") == 0) {
} else if (string_equals(token->value, "<%%") || string_equals(token->value, "<%%=")
|| string_equals(token->value, "<%graphql")) {
skip_erb_content = true;
is_comment_tag = false;
} else {
Expand Down
11 changes: 11 additions & 0 deletions src/include/util/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef HERB_UTILS_STRING_H
#define HERB_UTILS_STRING_H

#include <stdbool.h>
#include <string.h>

static inline bool string_equals(const char* a, const char* b) {
return strcmp(a, b) == 0;
}

#endif
13 changes: 7 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "include/io.h"
#include "include/ruby_parser.h"
#include "include/util/hb_buffer.h"
#include "include/util/string.h"

#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -61,7 +62,7 @@ int main(const int argc, char* argv[]) {
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);

if (strcmp(argv[1], "lex") == 0) {
if (string_equals(argv[1], "lex")) {
herb_lex_to_buffer(source, &output);
clock_gettime(CLOCK_MONOTONIC, &end);

Expand All @@ -74,15 +75,15 @@ int main(const int argc, char* argv[]) {
return 0;
}

if (strcmp(argv[1], "parse") == 0) {
if (string_equals(argv[1], "parse")) {
AST_DOCUMENT_NODE_T* root = herb_parse(source, NULL);

herb_analyze_parse_tree(root, source);

clock_gettime(CLOCK_MONOTONIC, &end);

int silent = 0;
if (argc > 3 && strcmp(argv[3], "--silent") == 0) { silent = 1; }
if (argc > 3 && string_equals(argv[3], "--silent")) { silent = 1; }

if (!silent) {
ast_pretty_print_node((AST_NODE_T*) root, 0, 0, &output);
Expand All @@ -98,7 +99,7 @@ int main(const int argc, char* argv[]) {
return 0;
}

if (strcmp(argv[1], "ruby") == 0) {
if (string_equals(argv[1], "ruby")) {
herb_extract_ruby_to_buffer(source, &output);
clock_gettime(CLOCK_MONOTONIC, &end);

Expand All @@ -111,7 +112,7 @@ int main(const int argc, char* argv[]) {
return 0;
}

if (strcmp(argv[1], "html") == 0) {
if (string_equals(argv[1], "html")) {
herb_extract_html_to_buffer(source, &output);
clock_gettime(CLOCK_MONOTONIC, &end);

Expand All @@ -124,7 +125,7 @@ int main(const int argc, char* argv[]) {
return 0;
}

if (strcmp(argv[1], "prism") == 0) {
if (string_equals(argv[1], "prism")) {
printf("HTML+ERB File: \n%s\n", source);

char* ruby_source = herb_extract(source, HERB_EXTRACT_LANGUAGE_RUBY);
Expand Down
11 changes: 6 additions & 5 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "include/util/hb_array.h"
#include "include/util/hb_buffer.h"
#include "include/util/hb_string.h"
#include "include/util/string.h"
#include "include/visitor.h"

#include <stdio.h>
Expand Down Expand Up @@ -346,7 +347,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value
while (!token_is(parser, TOKEN_EOF)
&& !(
token_is(parser, TOKEN_QUOTE) && opening_quote != NULL
&& strcmp(parser->current_token->value, opening_quote->value) == 0
&& string_equals(parser->current_token->value, opening_quote->value)
)) {
if (token_is(parser, TOKEN_ERB_START)) {
parser_append_literal_node_from_buffer(parser, &buffer, children, start);
Expand All @@ -364,7 +365,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value
token_T* next_token = lexer_next_token(parser->lexer);

if (next_token && next_token->type == TOKEN_QUOTE && opening_quote != NULL
&& strcmp(next_token->value, opening_quote->value) == 0) {
&& string_equals(next_token->value, opening_quote->value)) {
hb_buffer_append(&buffer, parser->current_token->value);
hb_buffer_append(&buffer, next_token->value);

Expand All @@ -387,7 +388,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value
}

if (token_is(parser, TOKEN_QUOTE) && opening_quote != NULL
&& strcmp(parser->current_token->value, opening_quote->value) == 0) {
&& string_equals(parser->current_token->value, opening_quote->value)) {
lexer_state_snapshot_T saved_state = lexer_save_state(parser->lexer);

token_T* potential_closing = parser->current_token;
Expand Down Expand Up @@ -415,7 +416,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value
while (!token_is(parser, TOKEN_EOF)
&& !(
token_is(parser, TOKEN_QUOTE) && opening_quote != NULL
&& strcmp(parser->current_token->value, opening_quote->value) == 0
&& string_equals(parser->current_token->value, opening_quote->value)
)) {
if (token_is(parser, TOKEN_ERB_START)) {
parser_append_literal_node_from_buffer(parser, &buffer, children, start);
Expand Down Expand Up @@ -445,7 +446,7 @@ static AST_HTML_ATTRIBUTE_VALUE_NODE_T* parser_parse_quoted_html_attribute_value

token_T* closing_quote = parser_consume_expected(parser, TOKEN_QUOTE, errors);

if (opening_quote != NULL && closing_quote != NULL && strcmp(opening_quote->value, closing_quote->value) != 0) {
if (opening_quote != NULL && closing_quote != NULL && !string_equals(opening_quote->value, closing_quote->value)) {
append_quotes_mismatch_error(
opening_quote,
closing_quote,
Expand Down
Loading