Commit af774749 by Aaron Leung

Some more helpers.

parent 7c4ca347
...@@ -86,8 +86,9 @@ DEFINE_CTYPE_SEQUENCE_MATCHER(xdigit); ...@@ -86,8 +86,9 @@ DEFINE_CTYPE_SEQUENCE_MATCHER(xdigit);
DEFINE_CTYPE_SEQUENCE_MATCHER(alnum); DEFINE_CTYPE_SEQUENCE_MATCHER(alnum);
DEFINE_CTYPE_SEQUENCE_MATCHER(punct); DEFINE_CTYPE_SEQUENCE_MATCHER(punct);
DEFINE_TO_EOL_MATCHER(line_comment, "//"); DEFINE_TO_EOL_MATCHER(shell_comment, "#");
DEFINE_DELIMITED_MATCHER(block_comment, "/*", "*/", 0); DEFINE_TO_EOL_MATCHER(c_line_comment, "//");
DEFINE_DELIMITED_MATCHER(c_block_comment, "/*", "*/", 0);
DEFINE_DELIMITED_MATCHER(double_quoted_string, "\"", "\"", 1); DEFINE_DELIMITED_MATCHER(double_quoted_string, "\"", "\"", 1);
DEFINE_DELIMITED_MATCHER(single_quoted_string, "\'", "\'", 1); DEFINE_DELIMITED_MATCHER(single_quoted_string, "\'", "\'", 1);
DEFINE_DELIMITED_MATCHER(interpolant, "#{", "}", 0); DEFINE_DELIMITED_MATCHER(interpolant, "#{", "}", 0);
...@@ -138,3 +139,4 @@ DEFINE_CHARS_MATCHER(equal, "=="); ...@@ -138,3 +139,4 @@ DEFINE_CHARS_MATCHER(equal, "==");
static DEFINE_ALTERNATIVES_MATCHER(identifier_initial, prefix_is_alphas, prefix_is_underscore); static DEFINE_ALTERNATIVES_MATCHER(identifier_initial, prefix_is_alphas, prefix_is_underscore);
static DEFINE_ALTERNATIVES_MATCHER(identifier_trailer, prefix_is_alnums, prefix_is_underscore); static DEFINE_ALTERNATIVES_MATCHER(identifier_trailer, prefix_is_alnums, prefix_is_underscore);
DEFINE_FIRST_REST_MATCHER(identifier, prefix_is_identifier_initial, prefix_is_identifier_trailer); DEFINE_FIRST_REST_MATCHER(identifier, prefix_is_identifier_initial, prefix_is_identifier_trailer);
...@@ -78,6 +78,7 @@ DECLARE_MATCHER(digit); ...@@ -78,6 +78,7 @@ DECLARE_MATCHER(digit);
DECLARE_MATCHER(xdigit); DECLARE_MATCHER(xdigit);
DECLARE_MATCHER(alnum); DECLARE_MATCHER(alnum);
DECLARE_MATCHER(punct); DECLARE_MATCHER(punct);
DECLARE_MATCHER(spaces); DECLARE_MATCHER(spaces);
DECLARE_MATCHER(alphas); DECLARE_MATCHER(alphas);
DECLARE_MATCHER(digits); DECLARE_MATCHER(digits);
...@@ -85,8 +86,9 @@ DECLARE_MATCHER(xdigits); ...@@ -85,8 +86,9 @@ DECLARE_MATCHER(xdigits);
DECLARE_MATCHER(alnums); DECLARE_MATCHER(alnums);
DECLARE_MATCHER(puncts); DECLARE_MATCHER(puncts);
DECLARE_MATCHER(line_comment); DECLARE_MATCHER(shell_comment);
DECLARE_MATCHER(block_comment); DECLARE_MATCHER(c_line_comment);
DECLARE_MATCHER(c_block_comment);
DECLARE_MATCHER(double_quoted_string); DECLARE_MATCHER(double_quoted_string);
DECLARE_MATCHER(single_quoted_string); DECLARE_MATCHER(single_quoted_string);
DECLARE_MATCHER(interpolant); DECLARE_MATCHER(interpolant);
......
...@@ -22,8 +22,10 @@ void print_slice(char *s, char *t) { ...@@ -22,8 +22,10 @@ void print_slice(char *s, char *t) {
(printf("testing << %s >>\n", #matcher), print_slice(src, matcher(src, __VA_ARGS__))) (printf("testing << %s >>\n", #matcher), print_slice(src, matcher(src, __VA_ARGS__)))
int main() { int main() {
char *spaces = " \t \t \v \r\n \n\nhello world";
char *dqstring = "\"blah blah \\\" blah\""; char *dqstring = "\"blah blah \\\" blah\"";
char *sqstring = "'this \\'is\\' a \"string\" now' blah blah blah"; char *sqstring = "'this \\'is\\' a \"string\" now' blah blah blah";
char *scomment = "# a shell-style comment";
char *bcomment = "/* this is a c comment \\*/ blah blah"; char *bcomment = "/* this is a c comment \\*/ blah blah";
char *noncomment = "/* blah blah"; char *noncomment = "/* blah blah";
char *interpolant = "#{ this is an interpolant \\} blah blah"; char *interpolant = "#{ this is an interpolant \\} blah blah";
...@@ -35,6 +37,9 @@ int main() { ...@@ -35,6 +37,9 @@ int main() {
char *lcomment = "// blah blah blah // end\n blah blah"; char *lcomment = "// blah blah blah // end\n blah blah";
char *id2 = "badec4669264hello"; char *id2 = "badec4669264hello";
test1(prefix_is_spaces, spaces);
test1(prefix_is_spaces, words);
testn(prefix_is_char, words, 'h'); testn(prefix_is_char, words, 'h');
testn(prefix_is_char, words, 'a'); testn(prefix_is_char, words, 'a');
...@@ -47,8 +52,11 @@ int main() { ...@@ -47,8 +52,11 @@ int main() {
testn(prefix_is_some_of, id1, "_deint"); testn(prefix_is_some_of, id1, "_deint");
testn(prefix_is_some_of, id1, "abcd"); testn(prefix_is_some_of, id1, "abcd");
test1(prefix_is_block_comment, bcomment); test1(prefix_is_shell_comment, scomment);
test1(prefix_is_block_comment, noncomment); test1(prefix_is_shell_comment, lcomment);
test1(prefix_is_c_block_comment, bcomment);
test1(prefix_is_c_block_comment, noncomment);
test1(prefix_is_double_quoted_string, dqstring); test1(prefix_is_double_quoted_string, dqstring);
test1(prefix_is_double_quoted_string, sqstring); test1(prefix_is_double_quoted_string, sqstring);
...@@ -59,8 +67,8 @@ int main() { ...@@ -59,8 +67,8 @@ int main() {
test1(prefix_is_interpolant, interpolant); test1(prefix_is_interpolant, interpolant);
test1(prefix_is_interpolant, lcomment); test1(prefix_is_interpolant, lcomment);
test1(prefix_is_line_comment, lcomment); test1(prefix_is_c_line_comment, lcomment);
test1(prefix_is_line_comment, noncomment); test1(prefix_is_c_line_comment, noncomment);
testn(prefix_sequence, id2, prefix_is_alphas, prefix_is_digits); testn(prefix_sequence, id2, prefix_is_alphas, prefix_is_digits);
testn(prefix_sequence, id2, prefix_is_alphas, prefix_is_puncts); testn(prefix_sequence, id2, prefix_is_alphas, prefix_is_puncts);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment