Compare commits

...

5 Commits

Author SHA1 Message Date
9c51f90f10 Merge branch 'master' of https://git.lain.church/emil/hl 2023-08-27 15:29:29 +02:00
74e6f78675 gdb regex_t pretty printer because vector_t was a footgun 2023-08-27 15:24:45 +02:00
e886deca54 TODO adjustments 2023-08-26 22:39:20 +02:00
82599f6363 simple test file 2023-08-26 22:39:14 +02:00
4d179689d5 regex lenghts work 2023-08-26 22:39:07 +02:00
6 changed files with 66 additions and 9 deletions

1
TODO
View File

@ -1,6 +1,5 @@
> Complete C syntax hearer
> Add Ada syntax header
> Create a regex preprocessor
> Figure out what the fuck to do about offset when regex_search()-ing
> Binary search when looking up delta_table
> valgrind

View File

@ -0,0 +1,54 @@
class RegexPrinter:
def __init__(self, val):
self.val = val
def to_string(self):
# Init
s = "{"
# Regular shit
s += "accepting_state = " + str(self.val['accepting_state']) + ", str = " + str(self.val['str']) + ",\n"
# Delta
delta_t_ptr_ptr = gdb.lookup_type("delta_t").pointer().pointer()
dt = self.val['delta_table']
s += "delta_table = {\n"
for i in range(0, dt['element_count']):
s += "\t"
s += (
str(
(
dt['data'].cast(delta_t_ptr_ptr)
+
i
).dereference().dereference()
)
)
s += ",\n"
s = s[:-2]
s += "\n },\n"
# Offshoot
offshoot_t_ptr_ptr = gdb.lookup_type("offshoot_t").pointer().pointer()
dt = self.val['delta_table']
s += "offshoot_table = {\n"
for i in range(0, dt['element_count']):
s += "\t"
s += (
str(
(
dt['data'].cast(offshoot_t_ptr_ptr)
+
i
).dereference().dereference()
)
)
s += ",\n"
s = s[:-2]
s += "\n }\n"
# Closour
s += "}"
return s
def regex_lookup(val):
if str(val.type) == 'regex_t' or str(val.type) == 'const regex_t':
return RegexPrinter(val)
return None
gdb.pretty_printers.append(regex_lookup)

View File

@ -187,9 +187,10 @@ int token_fits(const token_t * const token,
const char * const to,
const int string_offset,
int * match_offset) {
UNUSED(match_offset);
//return regex_match(pattern, to, string_offset, match_offset);
return regex_search(token->syntax, to + string_offset);
return regex_match(token->syntax, to + string_offset);
}
void render_string(const char * const string,

View File

@ -464,8 +464,9 @@ static int regex_assert(const regex_t * const regex,
const delta_t * const delta = *(delta_t**)vector_get(&regex->delta_table, i);
if ((delta->in == state)
&& (delta->input == *s)) {
if(regex_assert(regex, s + delta->width, delta->to)){
return true;
int r = regex_assert(regex, s + delta->width, delta->to, width + 1);
if(r){
return r;
}
}
}
@ -474,7 +475,7 @@ static int regex_assert(const regex_t * const regex,
continue;
}
return (state == regex->accepting_state);
return (state == regex->accepting_state) ? width : false;
}
return false;
@ -489,11 +490,11 @@ int regex_match( regex_t * regex,
return true;
}
int r = 0;
return regex_assert(regex, string, 0, &r);
return regex_assert(regex, string, 0, 0);
}
bool regex_search( regex_t * regex,
const char * const string) {
return (bool)regex_match(regex, string, 0);
return (bool)regex_match(regex, string);
}

View File

@ -14,8 +14,9 @@ typedef struct {
} regex_t;
extern regex_t * regex_compile(const char * const pattern);
extern bool regex_search(regex_t * regex, const char * const string);
extern int regex_free(regex_t * const regex);
extern bool regex_search(regex_t * regex, const char * const string);
extern int regex_match(regex_t * regex, const char * const string);
extern bool is_magic(const char c);

1
tests/test.input Normal file
View File

@ -0,0 +1 @@
while