Add parse_ prefix to parser type names

This commit is contained in:
2024-10-26 13:34:27 +01:00
parent e906c64bda
commit 5011e516e4
3 changed files with 106 additions and 90 deletions

View File

@@ -44,8 +44,9 @@ static void a_is_parsed_as_unquantified_literal(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ('a', t.alternatives[0].contents[0].literal);
parse_tree_free_children(&t);
@@ -60,8 +61,9 @@ static void b_is_parsed_as_unquantified_literal(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ('b', t.alternatives[0].contents[0].literal);
parse_tree_free_children(&t);
@@ -76,14 +78,17 @@ static void abc_is_parsed_as_sequence_of_unquantified_literals(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(3, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ('a', t.alternatives[0].contents[0].literal);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[1].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[1].type);
ASSERT_EQ('b', t.alternatives[0].contents[1].literal);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[2].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[2].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[2].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[2].type);
ASSERT_EQ('c', t.alternatives[0].contents[2].literal);
parse_tree_free_children(&t);
@@ -98,8 +103,9 @@ static void dot_is_parsed_as_unquantified_wildcard_term(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
parse_tree_free_children(&t);
}
@@ -113,8 +119,9 @@ static void backslash_dot_is_parsed_as_unquantified_literal(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ('.', t.alternatives[0].contents[0].literal);
parse_tree_free_children(&t);
@@ -129,8 +136,9 @@ static void backslash_backslash_is_parsed_as_unquantified_literal(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[0].type);
ASSERT_EQ('\\', t.alternatives[0].contents[0].literal);
parse_tree_free_children(&t);
@@ -145,22 +153,25 @@ static void a_pipe_b_in_parens_is_parsed_as_subexpr_term(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_SUBEXPR, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_SUBEXPR, t.alternatives[0].contents[0].type);
const parse_tree_t *inner = &t.alternatives[0].contents[0].subexpr;
ASSERT_EQ(2, inner->count);
ASSERT_EQ(1, inner->alternatives[0].len);
ASSERT_EQ(
QUANTIFIER_NONE, inner->alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[0].contents[0].type);
PARSE_QUANTIFIER_NONE,
inner->alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, inner->alternatives[0].contents[0].type);
ASSERT_EQ('a', inner->alternatives[0].contents[0].literal);
ASSERT_EQ(1, inner->alternatives[1].len);
ASSERT_EQ(
QUANTIFIER_NONE, inner->alternatives[1].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[1].contents[0].type);
PARSE_QUANTIFIER_NONE,
inner->alternatives[1].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, inner->alternatives[1].contents[0].type);
ASSERT_EQ('b', inner->alternatives[1].contents[0].literal);
parse_tree_free_children(&t);
@@ -175,23 +186,26 @@ static void a_in_parens_b_is_parsed_as_sequence_with_subexpr_term(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(2, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_SUBEXPR, t.alternatives[0].contents[0].type);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[1].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_SUBEXPR, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, t.alternatives[0].contents[1].type);
ASSERT_EQ('b', t.alternatives[0].contents[1].literal);
const parse_tree_t *inner = &t.alternatives[0].contents[0].subexpr;
ASSERT_EQ(1, inner->alternatives[0].len);
ASSERT_EQ(
QUANTIFIER_NONE, inner->alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[0].contents[0].type);
PARSE_QUANTIFIER_NONE,
inner->alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_LITERAL, inner->alternatives[0].contents[0].type);
ASSERT_EQ('a', inner->alternatives[0].contents[0].literal);
parse_tree_free_children(&t);
}
static void dot_star_is_parsed_as_zero_or_more_wildcard(void)
static void dot_star_is_parsed_as_star_quantified_wildcard(void)
{
parse_tree_t t;
const int result = PARSE_EXPR_STRING(".*", &t);
@@ -201,13 +215,13 @@ static void dot_star_is_parsed_as_zero_or_more_wildcard(void)
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(
QUANTIFIER_ZERO_OR_MORE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
PARSE_QUANTIFIER_STAR, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
parse_tree_free_children(&t);
}
static void dot_plus_is_parsed_as_one_or_more_wildcard(void)
static void dot_plus_is_parsed_as_plus_quantified_wildcard(void)
{
parse_tree_t t;
const int result = PARSE_EXPR_STRING(".+", &t);
@@ -217,13 +231,13 @@ static void dot_plus_is_parsed_as_one_or_more_wildcard(void)
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(
QUANTIFIER_ONE_OR_MORE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
PARSE_QUANTIFIER_PLUS, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
parse_tree_free_children(&t);
}
static void dot_question_mark_is_parsed_as_zero_or_one_wildcard(void)
static void dot_question_mark_is_parsed_as_qmrk_quantified_wildcard(void)
{
parse_tree_t t;
const int result = PARSE_EXPR_STRING(".?", &t);
@@ -233,8 +247,8 @@ static void dot_question_mark_is_parsed_as_zero_or_one_wildcard(void)
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(
QUANTIFIER_ZERO_OR_ONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
PARSE_QUANTIFIER_QMRK, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
parse_tree_free_children(&t);
}
@@ -248,8 +262,9 @@ static void a_in_brackets_is_parsed_as_class_containing_only_a(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_CLASS, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_CLASS, t.alternatives[0].contents[0].type);
ASSERT_FALSE(t.alternatives[0].contents[0].class.negated);
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
ASSERT_NOT_NULL(t.alternatives[0].contents[0].class.contents);
@@ -267,8 +282,9 @@ static void caret_a_in_brackets_parses_as_negated_class(void)
ASSERT_NOT_NULL(t.alternatives);
ASSERT_EQ(1, t.alternatives[0].len);
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(TERM_TYPE_CLASS, t.alternatives[0].contents[0].type);
ASSERT_EQ(
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
ASSERT_EQ(PARSE_TERM_CLASS, t.alternatives[0].contents[0].type);
ASSERT_TRUE(t.alternatives[0].contents[0].class.negated);
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
ASSERT_NOT_NULL(t.alternatives[0].contents[0].class.contents);
@@ -291,9 +307,9 @@ int main(void)
backslash_backslash_is_parsed_as_unquantified_literal();
a_pipe_b_in_parens_is_parsed_as_subexpr_term();
a_in_parens_b_is_parsed_as_sequence_with_subexpr_term();
dot_star_is_parsed_as_zero_or_more_wildcard();
dot_plus_is_parsed_as_one_or_more_wildcard();
dot_question_mark_is_parsed_as_zero_or_one_wildcard();
dot_star_is_parsed_as_star_quantified_wildcard();
dot_plus_is_parsed_as_plus_quantified_wildcard();
dot_question_mark_is_parsed_as_qmrk_quantified_wildcard();
a_in_brackets_is_parsed_as_class_containing_only_a();
caret_a_in_brackets_parses_as_negated_class();
return TESTING_END();