Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

syntax.h

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      syntax.h
00004  *
00005  *      Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de)
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifndef __SYNTAX_H__
00022 #define __SYNTAX_H__
00023 
00024 #include "common.h"
00025 #include "htio.h"
00026 #include "htobj.h"
00027 
00028 #define HT_HTML_SYNTAX_LEXER
00029 
00030 struct text_pos {
00031         UINT line;
00032         UINT pofs;
00033 };
00034 
00035 typedef UINT lexer_state;
00036 typedef UINT lexer_state_set;
00037 typedef UINT lexer_token;
00038 
00039 enum lexer_rule_string_type {
00040         LRST_EMPTY,
00041         LRST_STRING,
00042         LRST_STRING_EXPECT,
00043         LRST_REGEX,
00044         LRST_CHARSET,
00045         LRST_WHITESPACE,
00046         LRST_QSTRING,                   /* '[^']*' */
00047         LRST_DQSTRING,                  /* "[^"]*" */
00048 //     LRST_DQSTRING2,          /* "([^"]|\")*" */
00049         LRST_ANYCHAR,
00050         LRST_IDENTIFIER
00051 };
00052 
00053 struct syntax_lexer_rule {
00054         lexer_state_set needstate;
00055         bool need_line_start;
00056         lexer_rule_string_type string_type;
00057         char *string;
00058         lexer_state state;
00059         lexer_token token;
00060 };
00061 
00062 /*
00063  *      CLASS ht_syntax_lexer
00064  */
00065 
00066 class ht_syntax_lexer: public Object {
00067 public:
00068 /* new */
00069         virtual void config_changed();
00070         virtual vcp getcolor_syntax(UINT pal_index)=0;
00071         virtual lexer_state getinitstate()=0;
00072         virtual lexer_token geterrortoken()=0;
00073         virtual char *getname()=0;
00074         virtual lexer_token gettoken(void *buf, UINT buflen, text_pos p, bool start_of_line, lexer_state *ret_state, UINT *ret_len)=0;
00075         virtual vcp gettoken_color(lexer_token t)=0;
00076 };
00077 
00078 /*
00079  *      CLASS ht_lang_syntax_lexer
00080  */
00081 
00082 class ht_lang_syntax_lexer: public ht_syntax_lexer {
00083 protected:
00084         syntax_lexer_rule *lexer_rules;
00085         void **lexer_rules_precompiled;
00086         int lexer_rules_count;
00087 
00088 /* new */
00089                         void free_lexer_rules();
00090                         void set_lexer_rules(syntax_lexer_rule *lr);
00091 public:
00092                         void init(syntax_lexer_rule *lexer_rules);
00093         virtual void done();
00094 /* overwritten */
00095         virtual lexer_token gettoken(void *buf, UINT buflen, text_pos p, bool start_of_line, lexer_state *ret_state, UINT *ret_len);
00096 };
00097 
00098 /*
00099  *      CLASS ht_c_syntax_lexer
00100  */
00101 
00102 class ht_c_syntax_lexer: public ht_lang_syntax_lexer {
00103 protected:
00104         char **c_reserved_sorted;
00105         UINT c_reserved_count;
00106 
00107         palette c_pal;
00108         
00109         virtual void config_changed();
00110                         void reloadpalette();
00111 public:
00112                         void init();
00113         virtual void done();
00114 /* overwritten */
00115         virtual vcp getcolor_syntax(UINT pal_index);
00116         virtual lexer_state getinitstate();
00117         virtual lexer_token geterrortoken();
00118         virtual char *getname();
00119         virtual lexer_token gettoken(void *buf, UINT buflen, text_pos p, bool start_of_line, lexer_state *ret_state, UINT *ret_len);
00120         virtual vcp gettoken_color(lexer_token t);
00121 };
00122 
00123 #ifdef HT_HTML_SYNTAX_LEXER
00124 /*
00125  *      CLASS ht_html_syntax_lexer
00126  */
00127 
00128 class ht_html_syntax_lexer: public ht_lang_syntax_lexer {
00129 protected:
00130         char **html_reserved_sorted;
00131         UINT html_reserved_count;
00132 
00133         palette html_pal;
00134         
00135         virtual void config_changed();
00136                         void reloadpalette();
00137 public:
00138                         void init();
00139         virtual void done();
00140 /* overwritten */
00141         virtual vcp getcolor_syntax(UINT pal_index);
00142         virtual lexer_state getinitstate();
00143         virtual lexer_token geterrortoken();
00144         virtual char *getname();
00145         virtual lexer_token gettoken(void *buf, UINT buflen, text_pos p, bool start_of_line, lexer_state *ret_state, UINT *ret_len);
00146         virtual vcp gettoken_color(lexer_token t);
00147 };
00148 #endif
00149 
00150 char **create_sorted_stringtable(char **table);
00151 
00152 /*
00153  *      syntax palette
00154  */
00155 
00156 #define palkey_syntax_default                                           "c/default"
00157 
00158 #define palidx_syntax_whitespace                       0
00159 #define palidx_syntax_comment                          1
00160 #define palidx_syntax_identifier                       2
00161 #define palidx_syntax_reserved                         3
00162 #define palidx_syntax_intnum                           4
00163 #define palidx_syntax_floatnum                         5
00164 #define palidx_syntax_string                           6
00165 #define palidx_syntax_char                             7
00166 #define palidx_syntax_symbol                           8
00167 #define palidx_syntax_preprocess                                        9
00168 #define palidx_syntax_meta                             10
00169 
00170 #endif /* __SYNTAX_H__ */

Generated on Fri May 7 21:15:44 2004 by doxygen 1.3.5