From cec029dbee435e7f608b9f6a4a3d8e98f2c5a398 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Wed, 16 Sep 2020 09:33:24 -0700 Subject: Rewrite CodeEditor syntax highlighting for issue #135 --- fluid/StyleParse.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 fluid/StyleParse.h (limited to 'fluid/StyleParse.h') diff --git a/fluid/StyleParse.h b/fluid/StyleParse.h new file mode 100644 index 000000000..e243a7e47 --- /dev/null +++ b/fluid/StyleParse.h @@ -0,0 +1,59 @@ +// +// Syntax highlighting style parser class - erco 09/16/2020 +// +// Copyright 1998-2020 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// + +#ifndef StyleParse_h +#define StyleParse_h + +// Class to manage style parsing, friend of CodeEditor +class StyleParse { +public: + const char *tbuff; // text buffer + char *sbuff; // style buffer + int len; // running length + char style; // current style + char lwhite; // leading white space (1=white, 0=past white) + int col; // line's column counter + char keyword[40]; // keyword parsing buffer + char last; // flag for keyword parsing + + StyleParse() { + tbuff = 0; + sbuff = 0; + len = 0; + style = 0; + lwhite = 1; + col = 0; + last = 0; + } + + // Methods to aid in parsing + int parse_over_char(int handle_crlf=1); + int parse_over_white(); + int parse_over_alpha(); + int parse_to_eol(char s); + int parse_block_comment(); // "/* text.. */" + void buffer_keyword(); + int parse_over_key(const char *key, char s); + int parse_over_angles(char s); + int parse_keyword(); // "switch" + int parse_quoted_string(); // "hello" + int parse_directive(); // "#define" + int parse_line_comment(); // "// text.." + int parse_escape(); // "\'" + int parse_all_else(); // all other code +}; + +#endif //StyleParse_h -- cgit v1.2.3 From 4d503899a3dec9df8380b3981f1a7259e9d6cb8c Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Sat, 19 Sep 2020 10:43:27 -0700 Subject: Mods for Albrecht's 09/19/20 code review --- fluid/StyleParse.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'fluid/StyleParse.h') diff --git a/fluid/StyleParse.h b/fluid/StyleParse.h index e243a7e47..97755d637 100644 --- a/fluid/StyleParse.h +++ b/fluid/StyleParse.h @@ -1,7 +1,8 @@ // -// Syntax highlighting style parser class - erco 09/16/2020 +// Syntax highlighting for the Fast Light Tool Kit (FLTK). // // Copyright 1998-2020 by Bill Spitzak and others. +// Copyright 2020 Greg Ercolano. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this @@ -56,4 +57,4 @@ public: int parse_all_else(); // all other code }; -#endif //StyleParse_h +#endif // StyleParse_h -- cgit v1.2.3 From d66e146a89cd92307cb404bb203a9ce46f890375 Mon Sep 17 00:00:00 2001 From: Greg Ercolano Date: Sun, 20 Sep 2020 16:05:16 -0700 Subject: Handle single quotes --- fluid/StyleParse.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fluid/StyleParse.h') diff --git a/fluid/StyleParse.h b/fluid/StyleParse.h index 97755d637..2fcc4f4db 100644 --- a/fluid/StyleParse.h +++ b/fluid/StyleParse.h @@ -50,7 +50,8 @@ public: int parse_over_key(const char *key, char s); int parse_over_angles(char s); int parse_keyword(); // "switch" - int parse_quoted_string(); // "hello" + int parse_quoted_string(char quote_char, char in_style); + // "hello", 'x' int parse_directive(); // "#define" int parse_line_comment(); // "// text.." int parse_escape(); // "\'" -- cgit v1.2.3