Add parse_ prefix to parser type names
This commit is contained in:
parent
e906c64bda
commit
5011e516e4
50
lib/parser.c
50
lib/parser.c
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#define CLASS_START_CAPACITY 4
|
#define CLASS_START_CAPACITY 4
|
||||||
#define SEQUENCE_START_CAPACITY 8
|
#define SEQUENCE_START_CAPACITY 8
|
||||||
#define PARSE_TREE_START_CAPACITY 4
|
#define TREE_START_CAPACITY 4
|
||||||
|
|
||||||
static bool is_special(char c)
|
static bool is_special(char c)
|
||||||
{
|
{
|
||||||
@ -45,7 +45,7 @@ static int parse_literal(const char *input, int rem, char *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_class(const char *input, int rem, class_t *out)
|
static int parse_class(const char *input, int rem, parse_class_t *out)
|
||||||
{
|
{
|
||||||
int result, used = 0;
|
int result, used = 0;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ static int parse_class(const char *input, int rem, class_t *out)
|
|||||||
return out->count > 0 ? used : -1;
|
return out->count > 0 ? used : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_term(const char *input, int rem, term_t *out)
|
static int parse_term(const char *input, int rem, parse_term_t *out)
|
||||||
{
|
{
|
||||||
int result, used = 0;
|
int result, used = 0;
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ static int parse_term(const char *input, int rem, term_t *out)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ('.' == input[0]) {
|
if ('.' == input[0]) {
|
||||||
out->type = TERM_TYPE_WILDCARD;
|
out->type = PARSE_TERM_WILDCARD;
|
||||||
++used;
|
++used;
|
||||||
} else if ('(' == input[0]) {
|
} else if ('(' == input[0]) {
|
||||||
++used;
|
++used;
|
||||||
@ -105,7 +105,7 @@ static int parse_term(const char *input, int rem, term_t *out)
|
|||||||
result = parse_expr(input + used, rem - used, &out->subexpr);
|
result = parse_expr(input + used, rem - used, &out->subexpr);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
return -1;
|
return -1;
|
||||||
out->type = TERM_TYPE_SUBEXPR;
|
out->type = PARSE_TERM_SUBEXPR;
|
||||||
used += result;
|
used += result;
|
||||||
|
|
||||||
if (')' != input[used])
|
if (')' != input[used])
|
||||||
@ -115,55 +115,55 @@ static int parse_term(const char *input, int rem, term_t *out)
|
|||||||
result = parse_class(input + used, rem - used, &out->class);
|
result = parse_class(input + used, rem - used, &out->class);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
return -1;
|
return -1;
|
||||||
out->type = TERM_TYPE_CLASS;
|
out->type = PARSE_TERM_CLASS;
|
||||||
used += result;
|
used += result;
|
||||||
} else {
|
} else {
|
||||||
result = parse_literal(input + used, rem - used, &out->literal);
|
result = parse_literal(input + used, rem - used, &out->literal);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
return -1;
|
return -1;
|
||||||
out->type = TERM_TYPE_LITERAL;
|
out->type = PARSE_TERM_LITERAL;
|
||||||
used += result;
|
used += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (used < rem) {
|
if (used < rem) {
|
||||||
switch (input[used]) {
|
switch (input[used]) {
|
||||||
case '*':
|
case '*':
|
||||||
out->quantifier = QUANTIFIER_ZERO_OR_MORE;
|
out->quantifier = PARSE_QUANTIFIER_STAR;
|
||||||
++used;
|
++used;
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
out->quantifier = QUANTIFIER_ONE_OR_MORE;
|
out->quantifier = PARSE_QUANTIFIER_PLUS;
|
||||||
++used;
|
++used;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
out->quantifier = QUANTIFIER_ZERO_OR_ONE;
|
out->quantifier = PARSE_QUANTIFIER_QMRK;
|
||||||
++used;
|
++used;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
out->quantifier = QUANTIFIER_NONE;
|
out->quantifier = PARSE_QUANTIFIER_NONE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
out->quantifier = QUANTIFIER_NONE;
|
out->quantifier = PARSE_QUANTIFIER_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_sequence(const char *input, int rem, sequence_t *out)
|
static int parse_sequence(const char *input, int rem, parse_sequence_t *out)
|
||||||
{
|
{
|
||||||
int result, used = 0;
|
int result, used = 0;
|
||||||
|
|
||||||
out->len = 0;
|
out->len = 0;
|
||||||
out->capacity = SEQUENCE_START_CAPACITY;
|
out->capacity = SEQUENCE_START_CAPACITY;
|
||||||
out->contents = malloc(out->capacity * sizeof(term_t));
|
out->contents = malloc(out->capacity * sizeof(parse_term_t));
|
||||||
if (NULL == out->contents)
|
if (NULL == out->contents)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (used < rem) {
|
while (used < rem) {
|
||||||
if (out->len >= out->capacity) {
|
if (out->len >= out->capacity) {
|
||||||
out->capacity *= 2;
|
out->capacity *= 2;
|
||||||
out->contents
|
out->contents = realloc(
|
||||||
= realloc(out->contents, out->capacity * sizeof(term_t));
|
out->contents, out->capacity * sizeof(parse_term_t));
|
||||||
if (NULL == out->contents)
|
if (NULL == out->contents)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -184,8 +184,8 @@ int parse_expr(const char *input, int rem, parse_tree_t *out)
|
|||||||
int result, used = 0;
|
int result, used = 0;
|
||||||
|
|
||||||
out->count = 0;
|
out->count = 0;
|
||||||
out->capacity = PARSE_TREE_START_CAPACITY;
|
out->capacity = TREE_START_CAPACITY;
|
||||||
out->alternatives = malloc(out->capacity * sizeof(sequence_t));
|
out->alternatives = malloc(out->capacity * sizeof(parse_sequence_t));
|
||||||
if (NULL == out->alternatives)
|
if (NULL == out->alternatives)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ int parse_expr(const char *input, int rem, parse_tree_t *out)
|
|||||||
if (out->count >= out->capacity) {
|
if (out->count >= out->capacity) {
|
||||||
out->capacity *= 2;
|
out->capacity *= 2;
|
||||||
out->alternatives = realloc(
|
out->alternatives = realloc(
|
||||||
out->alternatives, out->capacity * sizeof(sequence_t));
|
out->alternatives, out->capacity * sizeof(parse_sequence_t));
|
||||||
if (NULL == out->alternatives)
|
if (NULL == out->alternatives)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -219,25 +219,25 @@ int parse_expr(const char *input, int rem, parse_tree_t *out)
|
|||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void class_free(class_t *c)
|
static void class_free(parse_class_t *c)
|
||||||
{
|
{
|
||||||
if (NULL != c->contents)
|
if (NULL != c->contents)
|
||||||
free(c->contents);
|
free(c->contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sequence_free(sequence_t *s)
|
static void sequence_free(parse_sequence_t *s)
|
||||||
{
|
{
|
||||||
if (NULL != s->contents) {
|
if (NULL != s->contents) {
|
||||||
for (int i = 0; i < s->len; ++i) {
|
for (int i = 0; i < s->len; ++i) {
|
||||||
switch (s->contents[i].type) {
|
switch (s->contents[i].type) {
|
||||||
case TERM_TYPE_CLASS:
|
case PARSE_TERM_CLASS:
|
||||||
class_free(&s->contents[i].class);
|
class_free(&s->contents[i].class);
|
||||||
break;
|
break;
|
||||||
case TERM_TYPE_SUBEXPR:
|
case PARSE_TERM_SUBEXPR:
|
||||||
parse_tree_free_children(&s->contents[i].subexpr);
|
parse_tree_free_children(&s->contents[i].subexpr);
|
||||||
break;
|
break;
|
||||||
case TERM_TYPE_WILDCARD:
|
case PARSE_TERM_WILDCARD:
|
||||||
case TERM_TYPE_LITERAL:
|
case PARSE_TERM_LITERAL:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
42
lib/parser.h
42
lib/parser.h
@ -12,42 +12,42 @@ typedef struct {
|
|||||||
bool negated;
|
bool negated;
|
||||||
int count, capacity;
|
int count, capacity;
|
||||||
char *contents;
|
char *contents;
|
||||||
} class_t;
|
} parse_class_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
QUANTIFIER_NONE,
|
PARSE_QUANTIFIER_NONE,
|
||||||
QUANTIFIER_ZERO_OR_MORE,
|
PARSE_QUANTIFIER_STAR,
|
||||||
QUANTIFIER_ONE_OR_MORE,
|
PARSE_QUANTIFIER_PLUS,
|
||||||
QUANTIFIER_ZERO_OR_ONE,
|
PARSE_QUANTIFIER_QMRK,
|
||||||
} quantifier_t;
|
} parse_quantifier_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TERM_TYPE_WILDCARD,
|
PARSE_TERM_WILDCARD,
|
||||||
TERM_TYPE_CLASS,
|
PARSE_TERM_CLASS,
|
||||||
TERM_TYPE_LITERAL,
|
PARSE_TERM_LITERAL,
|
||||||
TERM_TYPE_SUBEXPR,
|
PARSE_TERM_SUBEXPR,
|
||||||
} term_type_t;
|
} parse_term_type_t;
|
||||||
|
|
||||||
struct _term;
|
struct _parse_term;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int len, capacity;
|
int len, capacity;
|
||||||
struct _term *contents;
|
struct _parse_term *contents;
|
||||||
} sequence_t;
|
} parse_sequence_t;
|
||||||
|
|
||||||
typedef struct _parse_tree {
|
typedef struct {
|
||||||
int count, capacity;
|
int count, capacity;
|
||||||
sequence_t *alternatives;
|
parse_sequence_t *alternatives;
|
||||||
} parse_tree_t;
|
} parse_tree_t;
|
||||||
|
|
||||||
typedef struct _term {
|
typedef struct _parse_term {
|
||||||
quantifier_t quantifier;
|
parse_quantifier_t quantifier;
|
||||||
term_type_t type;
|
parse_term_type_t type;
|
||||||
union {
|
union {
|
||||||
class_t class;
|
parse_class_t class;
|
||||||
char literal;
|
char literal;
|
||||||
parse_tree_t subexpr;
|
parse_tree_t subexpr;
|
||||||
};
|
};
|
||||||
} term_t;
|
} parse_term_t;
|
||||||
|
|
||||||
int parse_expr(const char *input, int rem, parse_tree_t *out);
|
int parse_expr(const char *input, int rem, parse_tree_t *out);
|
||||||
void parse_tree_free_children(parse_tree_t *t);
|
void parse_tree_free_children(parse_tree_t *t);
|
||||||
|
@ -44,8 +44,9 @@ static void a_is_parsed_as_unquantified_literal(void)
|
|||||||
ASSERT_NOT_NULL(t.alternatives);
|
ASSERT_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
|
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('a', t.alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
parse_tree_free_children(&t);
|
||||||
@ -60,8 +61,9 @@ static void b_is_parsed_as_unquantified_literal(void)
|
|||||||
ASSERT_NOT_NULL(t.alternatives);
|
ASSERT_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
|
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);
|
ASSERT_EQ('b', t.alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(3, t.alternatives[0].len);
|
ASSERT_EQ(3, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
|
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('a', t.alternatives[0].contents[0].literal);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[1].type);
|
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('b', t.alternatives[0].contents[1].literal);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[2].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[2].type);
|
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);
|
ASSERT_EQ('c', t.alternatives[0].contents[2].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
|
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);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
|
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);
|
ASSERT_EQ('.', t.alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, t.alternatives[0].contents[0].type);
|
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);
|
ASSERT_EQ('\\', t.alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_SUBEXPR, t.alternatives[0].contents[0].type);
|
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;
|
const parse_tree_t *inner = &t.alternatives[0].contents[0].subexpr;
|
||||||
ASSERT_EQ(2, inner->count);
|
ASSERT_EQ(2, inner->count);
|
||||||
|
|
||||||
ASSERT_EQ(1, inner->alternatives[0].len);
|
ASSERT_EQ(1, inner->alternatives[0].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_NONE, inner->alternatives[0].contents[0].quantifier);
|
PARSE_QUANTIFIER_NONE,
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[0].contents[0].type);
|
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('a', inner->alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
ASSERT_EQ(1, inner->alternatives[1].len);
|
ASSERT_EQ(1, inner->alternatives[1].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_NONE, inner->alternatives[1].contents[0].quantifier);
|
PARSE_QUANTIFIER_NONE,
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[1].contents[0].type);
|
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);
|
ASSERT_EQ('b', inner->alternatives[1].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(2, t.alternatives[0].len);
|
ASSERT_EQ(2, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_SUBEXPR, t.alternatives[0].contents[0].type);
|
PARSE_QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[1].quantifier);
|
ASSERT_EQ(PARSE_TERM_SUBEXPR, t.alternatives[0].contents[0].type);
|
||||||
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('b', t.alternatives[0].contents[1].literal);
|
||||||
|
|
||||||
const parse_tree_t *inner = &t.alternatives[0].contents[0].subexpr;
|
const parse_tree_t *inner = &t.alternatives[0].contents[0].subexpr;
|
||||||
ASSERT_EQ(1, inner->alternatives[0].len);
|
ASSERT_EQ(1, inner->alternatives[0].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_NONE, inner->alternatives[0].contents[0].quantifier);
|
PARSE_QUANTIFIER_NONE,
|
||||||
ASSERT_EQ(TERM_TYPE_LITERAL, inner->alternatives[0].contents[0].type);
|
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('a', inner->alternatives[0].contents[0].literal);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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;
|
parse_tree_t t;
|
||||||
const int result = PARSE_EXPR_STRING(".*", &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(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_ZERO_OR_MORE, t.alternatives[0].contents[0].quantifier);
|
PARSE_QUANTIFIER_STAR, t.alternatives[0].contents[0].quantifier);
|
||||||
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
|
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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;
|
parse_tree_t t;
|
||||||
const int result = PARSE_EXPR_STRING(".+", &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(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_ONE_OR_MORE, t.alternatives[0].contents[0].quantifier);
|
PARSE_QUANTIFIER_PLUS, t.alternatives[0].contents[0].quantifier);
|
||||||
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
|
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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;
|
parse_tree_t t;
|
||||||
const int result = PARSE_EXPR_STRING(".?", &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(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(
|
ASSERT_EQ(
|
||||||
QUANTIFIER_ZERO_OR_ONE, t.alternatives[0].contents[0].quantifier);
|
PARSE_QUANTIFIER_QMRK, t.alternatives[0].contents[0].quantifier);
|
||||||
ASSERT_EQ(TERM_TYPE_WILDCARD, t.alternatives[0].contents[0].type);
|
ASSERT_EQ(PARSE_TERM_WILDCARD, t.alternatives[0].contents[0].type);
|
||||||
|
|
||||||
parse_tree_free_children(&t);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_CLASS, t.alternatives[0].contents[0].type);
|
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_FALSE(t.alternatives[0].contents[0].class.negated);
|
||||||
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
|
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
|
||||||
ASSERT_NOT_NULL(t.alternatives[0].contents[0].class.contents);
|
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_NOT_NULL(t.alternatives);
|
||||||
|
|
||||||
ASSERT_EQ(1, t.alternatives[0].len);
|
ASSERT_EQ(1, t.alternatives[0].len);
|
||||||
ASSERT_EQ(QUANTIFIER_NONE, t.alternatives[0].contents[0].quantifier);
|
ASSERT_EQ(
|
||||||
ASSERT_EQ(TERM_TYPE_CLASS, t.alternatives[0].contents[0].type);
|
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_TRUE(t.alternatives[0].contents[0].class.negated);
|
||||||
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
|
ASSERT_EQ(1, t.alternatives[0].contents[0].class.count);
|
||||||
ASSERT_NOT_NULL(t.alternatives[0].contents[0].class.contents);
|
ASSERT_NOT_NULL(t.alternatives[0].contents[0].class.contents);
|
||||||
@ -291,9 +307,9 @@ int main(void)
|
|||||||
backslash_backslash_is_parsed_as_unquantified_literal();
|
backslash_backslash_is_parsed_as_unquantified_literal();
|
||||||
a_pipe_b_in_parens_is_parsed_as_subexpr_term();
|
a_pipe_b_in_parens_is_parsed_as_subexpr_term();
|
||||||
a_in_parens_b_is_parsed_as_sequence_with_subexpr_term();
|
a_in_parens_b_is_parsed_as_sequence_with_subexpr_term();
|
||||||
dot_star_is_parsed_as_zero_or_more_wildcard();
|
dot_star_is_parsed_as_star_quantified_wildcard();
|
||||||
dot_plus_is_parsed_as_one_or_more_wildcard();
|
dot_plus_is_parsed_as_plus_quantified_wildcard();
|
||||||
dot_question_mark_is_parsed_as_zero_or_one_wildcard();
|
dot_question_mark_is_parsed_as_qmrk_quantified_wildcard();
|
||||||
a_in_brackets_is_parsed_as_class_containing_only_a();
|
a_in_brackets_is_parsed_as_class_containing_only_a();
|
||||||
caret_a_in_brackets_parses_as_negated_class();
|
caret_a_in_brackets_parses_as_negated_class();
|
||||||
return TESTING_END();
|
return TESTING_END();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user