From 2d9b1999626a1d6adbf8c956c2188d8f0fd671bc Mon Sep 17 00:00:00 2001 From: xolatile Date: Thu, 14 Sep 2023 20:07:46 -0400 Subject: [PATCH] Added simplifications to defining syntax rules... --- xyntax.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- xyntax.h | 17 +++++++++++++++++ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/xyntax.c b/xyntax.c index 85aa1c5..81b08e3 100644 --- a/xyntax.c +++ b/xyntax.c @@ -11,14 +11,15 @@ #include -int syntax_count = 0; -int * syntax_enrange = NULL; -int * syntax_derange = NULL; -char * * syntax_begin = NULL; -char * * syntax_end = NULL; -char * syntax_escape = NULL; -int * syntax_colour = NULL; -int * syntax_effect = NULL; +int syntax_count = 0; +int * syntax_enrange = NULL; +int * syntax_derange = NULL; +char * * syntax_begin = NULL; +char * * syntax_end = NULL; +char * syntax_escape = NULL; +int * syntax_colour = NULL; +int * syntax_effect = NULL; +char * syntax_separator = NULL; int syntax_define (int enrange, int derange, char * begin, char * end, char escape, int colour, int effect) { fatal_failure (begin == NULL, "syntax_define: Begin string is null pointer."); @@ -115,6 +116,10 @@ int syntax_select (char * string, int * length) { } void syntax_delete (void) { + if (syntax_count == 0) { + return; + } + --syntax_count; do { @@ -129,6 +134,38 @@ void syntax_delete (void) { syntax_escape = deallocate (syntax_escape); syntax_colour = deallocate (syntax_colour); syntax_effect = deallocate (syntax_effect); + + syntax_count = 0; +} + +void syntax_define_separators (char * separator) { + syntax_separator = separator; +} + +void syntax_define_default (int string_colour, int string_effect, int number_colour, int number_effect) { + (void) syntax_define (1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_BOLD); + (void) syntax_define (0, 0, "\"", "\"", '\\', string_colour, string_effect); + (void) syntax_define (1, 1, "0123456789", syntax_separator, '\0', number_colour, number_effect); +} + +void syntax_define_words (char * * word_array, int word_count, int word_colour, int word_effect) { + int word = 0; + + for (word = 0; word != word_count; ++word) { + (void) syntax_define (0, 1, word_array [word], syntax_separator, '\0', word_colour, word_effect); + } + + (void) syntax_define (1, 1, "abcdefghijklmnopqrstuvwxyz", syntax_separator, '\0', COLOUR_WHITE, EFFECT_NORMAL); + (void) syntax_define (1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", syntax_separator, '\0', COLOUR_WHITE, EFFECT_BOLD); + (void) syntax_define (1, 1, "_", syntax_separator, '\0', COLOUR_PINK, EFFECT_BOLD); +} + +void syntax_define_range (char * range_begin, char * range_end, char range_escape, int range_colour, int range_effect) { + (void) syntax_define (0, 0, range_begin, range_end, range_escape, range_colour, range_effect); +} + +void syntax_define_operators (char * operator_array, int operator_colour, int operator_effect) { + (void) syntax_define (1, 0, operator_array, "", '\0', operator_colour, operator_effect); } #endif diff --git a/xyntax.h b/xyntax.h index c34af3d..09681a6 100644 --- a/xyntax.h +++ b/xyntax.h @@ -20,10 +20,27 @@ extern char * * syntax_end; extern char * syntax_escape; extern int * syntax_colour; extern int * syntax_effect; +extern char * syntax_separator; + +extern int syntax_styles; extern int syntax_define (int, int, char *, char *, char, int, int); extern int syntax_select (char *, int *); extern void syntax_delete (void); +/* Simplification... */ + +extern void syntax_define_style (int *, int *); + +extern void syntax_define_separators (char *); + +extern void syntax_define_default (int, int, int, int); + +extern void syntax_define_words (char * *, int, int, int); + +extern void syntax_define_range (char *, char *, char, int, int); + +extern void syntax_define_operators (char *, int, int); + #endif