Skip to content
Snippets Groups Projects
Commit 6a2ee4f6 authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

add pprint argument to h_allocate_token_new()

also allow NULL argument for unamb_sub to mean default
parent a0d225f5
No related branches found
No related tags found
No related merge requests found
...@@ -795,7 +795,8 @@ HTokenType h_allocate_token_type(const char* name); ...@@ -795,7 +795,8 @@ HTokenType h_allocate_token_type(const char* name);
/// Allocate a new token type with an unambiguous print function. /// Allocate a new token type with an unambiguous print function.
HTokenType h_allocate_token_new( HTokenType h_allocate_token_new(
const char* name, const char* name,
void (*unamb_sub)(const HParsedToken *tok, struct result_buf *buf)); void (*unamb_sub)(const HParsedToken *tok, struct result_buf *buf),
void (*pprint)(FILE* stream, const HParsedToken* tok, int indent, int delta));
/// Get the token type associated with name. Returns -1 if name is unkown /// Get the token type associated with name. Returns -1 if name is unkown
HTokenType h_get_token_type_number(const char* name); HTokenType h_get_token_type_number(const char* name);
......
...@@ -54,13 +54,14 @@ static void default_unamb_sub(const HParsedToken* tok, ...@@ -54,13 +54,14 @@ static void default_unamb_sub(const HParsedToken* tok,
HTokenType h_allocate_token_new( HTokenType h_allocate_token_new(
const char* name, const char* name,
void (*unamb_sub)(const HParsedToken *tok, struct result_buf *buf)) { void (*unamb_sub)(const HParsedToken *tok, struct result_buf *buf),
void (*pprint)(FILE* stream, const HParsedToken* tok, int indent, int delta)) {
HTTEntry* new_entry = h_alloc(&system_allocator, sizeof(*new_entry)); HTTEntry* new_entry = h_alloc(&system_allocator, sizeof(*new_entry));
assert(new_entry != NULL); assert(new_entry != NULL);
new_entry->name = name; new_entry->name = name;
new_entry->value = 0; new_entry->value = 0;
new_entry->unamb_sub = unamb_sub; new_entry->unamb_sub = unamb_sub ? unamb_sub : default_unamb_sub;
new_entry->pprint = NULL; new_entry->pprint = pprint;
HTTEntry* probe = *(HTTEntry**)tsearch(new_entry, &tt_registry, compare_entries); HTTEntry* probe = *(HTTEntry**)tsearch(new_entry, &tt_registry, compare_entries);
if (probe->value != 0) { if (probe->value != 0) {
// Token type already exists... // Token type already exists...
...@@ -87,7 +88,7 @@ HTokenType h_allocate_token_new( ...@@ -87,7 +88,7 @@ HTokenType h_allocate_token_new(
} }
} }
HTokenType h_allocate_token_type(const char* name) { HTokenType h_allocate_token_type(const char* name) {
return h_allocate_token_new(name, default_unamb_sub); return h_allocate_token_new(name, NULL, NULL);
} }
HTokenType h_get_token_type_number(const char* name) { HTokenType h_get_token_type_number(const char* name) {
HTTEntry e; HTTEntry e;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment