Compare commits
5 Commits
a245d25738
...
9c51f90f10
Author | SHA1 | Date | |
---|---|---|---|
9c51f90f10 | |||
74e6f78675 | |||
e886deca54 | |||
82599f6363 | |||
4d179689d5 |
1
TODO
1
TODO
@ -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
|
||||
|
54
debug/regex.pretty_print.py
Normal file
54
debug/regex.pretty_print.py
Normal 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)
|
@ -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,
|
||||
|
@ -464,8 +464,9 @@ static int regex_assert(const regex_t * const regex,
|
||||
const delta_t * const delta = *(delta_t**)vector_get(®ex->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);
|
||||
}
|
||||
|
@ -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
1
tests/test.input
Normal file
@ -0,0 +1 @@
|
||||
while
|
Loading…
Reference in New Issue
Block a user