Rewriting with only the tokenizer left
This commit is contained in:
parent
c53e7cbc2f
commit
c22f5f5b7d
|
@ -1,11 +0,0 @@
|
|||
|
||||
#ifndef CARROT_PRINT_DEFINITION_H
|
||||
#define CARROT_PRINT_DEFINITION_H
|
||||
|
||||
#include <defgen.h>
|
||||
|
||||
void carrot_print_definition (carrot_definition_s *definition);
|
||||
void carrot_print_element (carrot_element_s *element);
|
||||
void carrot_print_rule (carrot_rule_s *rule);
|
||||
|
||||
#endif
|
|
@ -1,6 +1,4 @@
|
|||
#include <tokenizer.h>
|
||||
#include <defgen.h>
|
||||
#include <print_def.h>
|
||||
|
||||
char * carrot_load_file(char *path, uint32_t *out_len_file)
|
||||
{
|
||||
|
@ -45,9 +43,6 @@ int main(int argc, char **argv)
|
|||
carrot_token_stream_s stream = carrot_tokenize(file_content, len_file_content);
|
||||
carrot_print_tokens(&stream);
|
||||
|
||||
carrot_definition_s definition = carrot_parse_definition(&stream);
|
||||
carrot_print_definition(&definition);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
#include <print_def.h>
|
||||
|
||||
void carrot_print_definition(carrot_definition_s *definition)
|
||||
{
|
||||
uint32_t index = 0;
|
||||
while(index < definition->num_rules)
|
||||
{
|
||||
carrot_print_rule(&definition->rules[index]);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
const char * carrot_constringify_pattern_name(carrot_pattern_e pattern)
|
||||
{
|
||||
switch(pattern)
|
||||
{
|
||||
case CARROT_PATTERN_INVALID: return "Invalid";
|
||||
case CARROT_PATTERN_WORD: return "Word";
|
||||
case CARROT_PATTERN_KEYWORD: return "Keyword";
|
||||
case CARROT_PATTERN_NUMBER: return "Number";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
const char * carrot_constringify_element_type(carrot_element_e element)
|
||||
{
|
||||
switch(element)
|
||||
{
|
||||
case CARROT_ELEMENT_RULE_INSERTION: return "Rule Insertion";
|
||||
case CARROT_ELEMENT_PATTERN: return "Pattern";
|
||||
case CARROT_ELEMENT_RAW_LITERAL: return "Raw Literal";
|
||||
}
|
||||
}
|
||||
|
||||
void carrot_print_element(carrot_element_s *element)
|
||||
{
|
||||
char buffer[72];
|
||||
int len_buffer = 71;
|
||||
switch(element->type)
|
||||
{
|
||||
case CARROT_ELEMENT_RULE_INSERTION:
|
||||
len_buffer = snprintf(buffer, 71, "%d:\"%s\"", element->specific.raw_literal.num_bytes, element->specific.raw_literal.bytes);
|
||||
break;
|
||||
|
||||
case CARROT_ELEMENT_PATTERN:
|
||||
len_buffer = snprintf(buffer, 71, "%d:\"%s\"", element->specific.raw_literal.num_bytes, carrot_constringify_pattern_name(element->specific.pattern.value));
|
||||
break;
|
||||
|
||||
case CARROT_ELEMENT_RAW_LITERAL:
|
||||
len_buffer = snprintf(buffer, 71, "%d:\"%s\"", element->specific.raw_literal.num_bytes, element->specific.raw_literal.bytes);
|
||||
break;
|
||||
}
|
||||
buffer[len_buffer] = 0x00;
|
||||
|
||||
printf("Element<T: '%s'>: %s", carrot_constringify_element_type(element->type), buffer);
|
||||
}
|
||||
|
||||
void carrot_print_rule(carrot_rule_s *rule)
|
||||
{
|
||||
uint32_t index = 0;
|
||||
while(index < rule->num_elements)
|
||||
{
|
||||
carrot_print_element(&rule->elements[index]);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue