Commit 2a4f9023 by Aaron Leung

Adding a negative lookahead.

parent 4346e067
...@@ -39,6 +39,10 @@ char *prefix_epsilon(char *src) { ...@@ -39,6 +39,10 @@ char *prefix_epsilon(char *src) {
return src; return src;
} }
char *prefix_not(char *src, prefix_matcher m) {
return m(src) ? NULL : src;
}
char *_prefix_alternatives(char *src, ...) { char *_prefix_alternatives(char *src, ...) {
va_list ap; va_list ap;
va_start(ap, src); va_start(ap, src);
......
...@@ -75,6 +75,7 @@ char *prefix_is_some_of(char *src, char *class); ...@@ -75,6 +75,7 @@ char *prefix_is_some_of(char *src, char *class);
char *prefix_is_delimited_by(char *src, char *beg, char *end, int esc); char *prefix_is_delimited_by(char *src, char *beg, char *end, int esc);
char *prefix_epsilon(char *src); char *prefix_epsilon(char *src);
char *prefix_not(char *src, prefix_matcher m);
char *_prefix_alternatives(char *src, ...); char *_prefix_alternatives(char *src, ...);
#define prefix_alternatives(src, ...) _prefix_alternatives(src, __VA_ARGS__, NULL) #define prefix_alternatives(src, ...) _prefix_alternatives(src, __VA_ARGS__, NULL)
char *_prefix_sequence(char *src, ...); char *_prefix_sequence(char *src, ...);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "prefix_primitives.h" #include "prefix_primitives.h"
#include "lexical_patterns.h"
void print_slice(char *s, char *t) { void print_slice(char *s, char *t) {
if (t) { if (t) {
...@@ -74,6 +75,11 @@ int main() { ...@@ -74,6 +75,11 @@ int main() {
test1(prefix_is_c_line_comment, lcomment); test1(prefix_is_c_line_comment, lcomment);
test1(prefix_is_c_line_comment, non_comment); test1(prefix_is_c_line_comment, non_comment);
test1(prefix_epsilon, words);
testn(prefix_not, words, prefix_is_puncts);
testn(prefix_not, words, prefix_is_alphas);
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);
...@@ -94,5 +100,8 @@ int main() { ...@@ -94,5 +100,8 @@ int main() {
test1(prefix_is_integer, integer3); test1(prefix_is_integer, integer3);
test1(prefix_is_integer, word2); test1(prefix_is_integer, word2);
test1(prefix_is_word, word2);
test1(prefix_is_word, non_word);
return 0; return 0;
} }
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