1 #ifndef __TOKENIZER_H__ 2 #define __TOKENIZER_H__ 3 4 struct tokenizer; 5 6 #define TOKENIZER_ENUM_START_POS 255 7 8 enum tokenizer_type { 9 TOKENIZER_KEYWORD = TOKENIZER_ENUM_START_POS, 10 TOKENIZER_TYPE, 11 TOKENIZER_LITERAL, 12 TOKENIZER_NUMBER, 13 TOKENIZER_COMMENT, 14 TOKENIZER_DIRECTIVE, 15 TOKENIZER_TEXT, 16 TOKENIZER_NEWLINE, 17 TOKENIZER_ERROR, 18 19 TOKENIZER_SEARCH, 20 TOKENIZER_STATUS_BAR, 21 22 TOKENIZER_EXECUTING_LINE_ARROW, 23 TOKENIZER_SELECTED_LINE_ARROW, 24 TOKENIZER_EXECUTING_LINE_HIGHLIGHT, 25 TOKENIZER_SELECTED_LINE_HIGHLIGHT, 26 TOKENIZER_EXECUTING_LINE_BLOCK, 27 TOKENIZER_SELECTED_LINE_BLOCK, 28 29 TOKENIZER_ENABLED_BREAKPOINT, 30 TOKENIZER_DISABLED_BREAKPOINT, 31 TOKENIZER_SELECTED_LINE_NUMBER, 32 TOKENIZER_SCROLL_MODE_STATUS, 33 TOKENIZER_LOGO, 34 TOKENIZER_COLOR, 35 }; 36 37 enum tokenizer_language_support { 38 TOKENIZER_LANGUAGE_C = TOKENIZER_ENUM_START_POS, 39 TOKENIZER_LANGUAGE_ASM, 40 TOKENIZER_LANGUAGE_D, 41 TOKENIZER_LANGUAGE_GO, 42 TOKENIZER_LANGUAGE_RUST, 43 TOKENIZER_LANGUAGE_ADA, 44 TOKENIZER_LANGUAGE_CGDBHELP, 45 TOKENIZER_LANGUAGE_UNKNOWN 46 }; 47 48 /* tokenizer_init 49 * -------------- 50 * 51 * This initializers a new tokenizer. 52 * 53 * t: The tokenizer object to work on 54 * 55 * Return: It will never fail. 56 */ 57 struct tokenizer *tokenizer_init(void); 58 59 /* tokenizer_destroy 60 * ----------------- 61 * 62 * This destroy's a tokenizer 63 * 64 * t: The tokenizer object to work on 65 */ 66 void tokenizer_destroy(struct tokenizer *t); 67 68 /** 69 * This functions will prepare the tokenizer to parse a particular buffer. 70 * 71 * t: The tokenizer object to work on 72 * 73 * Return: -1 on error. 0 on success 74 */ 75 int tokenizer_set_buffer(struct tokenizer *t, const char *buffer, 76 enum tokenizer_language_support l); 77 78 /* tokenizer_get_token 79 * ------------------- 80 * 81 * This function will get the next token packet from the file. 82 * 83 * t: The tokenizer object to work on 84 * 85 * Return: -1 on error, 0 on end of file, 1 on success 86 */ 87 struct token_data { 88 enum tokenizer_type e; 89 const char *data; 90 }; 91 int tokenizer_get_token(struct tokenizer *t, struct token_data *token_data); 92 93 /* tokenizer_print_enum 94 * -------------------- 95 * 96 * Returns the string representation of the enum 97 * 98 * e: The enum 99 * 100 * Returns: NULL on error, or the enum on success. 101 */ 102 const char *tokenizer_get_printable_enum(enum tokenizer_type e); 103 104 /* tokenizer_get_default_file_type 105 * 106 * This will return the type of file the tokenizer thinks the 107 * extension FILE_EXTENSION belongs too. 108 * 109 * t: The tokenizer object to work on 110 * e: The file extension the tokenizer will use to determine filetype. 111 */ 112 enum tokenizer_language_support tokenizer_get_default_file_type(const char 113 *file_extension); 114 115 #endif /* __TOKENIZER_H__ */ 116