Added simplifications to defining syntax rules...

This commit is contained in:
Ognjen Milan Robovic 2023-09-14 20:07:46 -04:00
parent c5073d489f
commit 2d9b199962
2 changed files with 62 additions and 8 deletions

View File

@ -11,14 +11,15 @@
#include <xolatile/xyntax.h>
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

View File

@ -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