diff options
Diffstat (limited to 'pattern.h')
| -rw-r--r-- | pattern.h | 138 |
1 files changed, 81 insertions, 57 deletions
@@ -3,42 +3,42 @@ // #pragma once +#include <err.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <sys/types.h> -#include <err.h> // BP virtual machine pattern types enum bp_pattype_e { - BP_ERROR = 0, - BP_ANYCHAR = 1, - BP_ID_START = 2, - BP_ID_CONTINUE = 3, - BP_STRING = 4, - BP_RANGE = 5, - BP_NOT = 6, - BP_UPTO = 7, - BP_UPTO_STRICT = 8, - BP_REPEAT = 9, - BP_BEFORE = 10, - BP_AFTER = 11, - BP_CAPTURE = 12, - BP_OTHERWISE = 13, - BP_CHAIN = 14, - BP_MATCH = 15, - BP_NOT_MATCH = 16, - BP_REPLACE = 17, - BP_REF = 18, - BP_NODENT = 19, - BP_CURDENT = 20, + BP_ERROR = 0, + BP_ANYCHAR = 1, + BP_ID_START = 2, + BP_ID_CONTINUE = 3, + BP_STRING = 4, + BP_RANGE = 5, + BP_NOT = 6, + BP_UPTO = 7, + BP_UPTO_STRICT = 8, + BP_REPEAT = 9, + BP_BEFORE = 10, + BP_AFTER = 11, + BP_CAPTURE = 12, + BP_OTHERWISE = 13, + BP_CHAIN = 14, + BP_MATCH = 15, + BP_NOT_MATCH = 16, + BP_REPLACE = 17, + BP_REF = 18, + BP_NODENT = 19, + BP_CURDENT = 20, BP_START_OF_FILE = 21, BP_START_OF_LINE = 22, - BP_END_OF_FILE = 23, - BP_END_OF_LINE = 24, + BP_END_OF_FILE = 23, + BP_END_OF_LINE = 24, BP_WORD_BOUNDARY = 25, - BP_DEFINITIONS = 26, - BP_TAGGED = 27, + BP_DEFINITIONS = 26, + BP_TAGGED = 27, BP_LEFTRECURSION = 28, }; @@ -58,21 +58,39 @@ struct bp_pat_s { struct { const char *start, *end, *msg; } BP_ERROR; - struct {} BP_ANYCHAR; - struct {} BP_ID_START; - struct {} BP_ID_CONTINUE; - struct {const char *string; size_t len; } BP_STRING; - struct {unsigned char low, high; } BP_RANGE; - struct {bp_pat_t *pat;} BP_NOT; - struct {bp_pat_t *target, *skip;} BP_UPTO; - struct {bp_pat_t *target, *skip;} BP_UPTO_STRICT; + struct { + } BP_ANYCHAR; + struct { + } BP_ID_START; + struct { + } BP_ID_CONTINUE; + struct { + const char *string; + size_t len; + } BP_STRING; + struct { + unsigned char low, high; + } BP_RANGE; + struct { + bp_pat_t *pat; + } BP_NOT; + struct { + bp_pat_t *target, *skip; + } BP_UPTO; + struct { + bp_pat_t *target, *skip; + } BP_UPTO_STRICT; struct { uint32_t min; int32_t max; bp_pat_t *sep, *repeat_pat; } BP_REPEAT; - struct {bp_pat_t *pat;} BP_BEFORE; - struct {bp_pat_t *pat;} BP_AFTER; + struct { + bp_pat_t *pat; + } BP_BEFORE; + struct { + bp_pat_t *pat; + } BP_AFTER; struct { bp_pat_t *pat; const char *name; @@ -85,8 +103,12 @@ struct bp_pat_s { struct { bp_pat_t *first, *second; } BP_CHAIN; - struct {bp_pat_t *pat, *must_match;} BP_MATCH; - struct {bp_pat_t *pat, *must_not_match;} BP_NOT_MATCH; + struct { + bp_pat_t *pat, *must_match; + } BP_MATCH; + struct { + bp_pat_t *pat, *must_not_match; + } BP_NOT_MATCH; struct { bp_pat_t *pat; const char *text; @@ -96,13 +118,20 @@ struct bp_pat_s { const char *name; uint32_t len; } BP_REF; - struct {} BP_NODENT; - struct {} BP_CURDENT; - struct {} BP_START_OF_FILE; - struct {} BP_START_OF_LINE; - struct {} BP_END_OF_FILE; - struct {} BP_END_OF_LINE; - struct {} BP_WORD_BOUNDARY; + struct { + } BP_NODENT; + struct { + } BP_CURDENT; + struct { + } BP_START_OF_FILE; + struct { + } BP_START_OF_LINE; + struct { + } BP_END_OF_FILE; + struct { + } BP_END_OF_LINE; + struct { + } BP_WORD_BOUNDARY; struct { const char *name; uint32_t namelen; @@ -142,21 +171,16 @@ typedef struct { } value; } maybe_pat_t; -__attribute__((returns_nonnull)) -bp_pat_t *allocate_pat(bp_pat_t pat); -__attribute__((nonnull, returns_nonnull)) -bp_pat_t *bp_raw_literal(const char *str, size_t len); -__attribute__((nonnull(1))) -maybe_pat_t bp_stringpattern(const char *str, const char *end); -__attribute__((nonnull(1,2))) -maybe_pat_t bp_replacement(bp_pat_t *replacepat, const char *replacement, const char *end); +__attribute__((returns_nonnull)) bp_pat_t *allocate_pat(bp_pat_t pat); +__attribute__((nonnull, returns_nonnull)) bp_pat_t *bp_raw_literal(const char *str, size_t len); +__attribute__((nonnull(1))) maybe_pat_t bp_stringpattern(const char *str, const char *end); +__attribute__((nonnull(1, 2))) maybe_pat_t bp_replacement(bp_pat_t *replacepat, const char *replacement, + const char *end); bp_pat_t *chain_together(bp_pat_t *first, bp_pat_t *second); bp_pat_t *either_pat(bp_pat_t *first, bp_pat_t *second); -__attribute__((nonnull(1))) -maybe_pat_t bp_pattern(const char *str, const char *end); +__attribute__((nonnull(1))) maybe_pat_t bp_pattern(const char *str, const char *end); void free_all_pats(void); -__attribute__((nonnull)) -void delete_pat(bp_pat_t **at_pat, bool recursive); +__attribute__((nonnull)) void delete_pat(bp_pat_t **at_pat, bool recursive); int fprint_pattern(FILE *stream, bp_pat_t *pat); // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 |
