1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
/*
* HT Editor
* syntax.h
*
* Copyright (C) 1999-2002 Stefan Weyergraf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SYNTAX_H__
#define __SYNTAX_H__
#include "data.h"
#include "htobj.h"
#define HT_HTML_SYNTAX_LEXER
struct text_pos {
uint line;
uint pofs;
};
typedef uint lexer_state;
typedef uint lexer_state_set;
typedef uint lexer_token;
enum lexer_rule_string_type {
LRST_EMPTY,
LRST_STRING,
LRST_STRING_EXPECT,
LRST_REGEX,
LRST_CHARSET,
LRST_WHITESPACE,
LRST_QSTRING, /* '[^']*' */
LRST_DQSTRING, /* "[^"]*" */
// LRST_DQSTRING2, /* "([^"]|\")*" */
LRST_ANYCHAR,
LRST_IDENTIFIER
};
struct syntax_lexer_rule {
lexer_state_set needstate;
bool need_line_start;
lexer_rule_string_type string_type;
const char *string;
lexer_state state;
lexer_token token;
};
/*
* CLASS ht_syntax_lexer
*/
class ht_syntax_lexer: public Object {
public:
/* new */
virtual void config_changed();
virtual vcp getcolor_syntax(uint pal_index)=0;
virtual lexer_state getinitstate()=0;
virtual lexer_token geterrortoken()=0;
virtual const char *getname()=0;
virtual lexer_token gettoken(void *buf, uint buflen, text_pos p, bool start_of_line, lexer_state *ret_state, uint *ret_len)=0;
virtual vcp gettoken_color(lexer_token t)=0;
};
/*
* CLASS ht_lang_syntax_lexer
*/
class ht_lang_syntax_lexer: public ht_syntax_lexer {
protected:
syntax_lexer_rule *lexer_rules;
void **lexer_rules_precompiled;
int lexer_rules_count;
/* new */
void free_lexer_rules();
void set_lexer_rules(syntax_lexer_rule *lr);
public:
void init(syntax_lexer_rule *lexer_rules);
virtual void done();
/* overwritten */
virtual lexer_token gettoken(void *buf, uint buflen, text_pos p, bool start_of_line, lexer_state *ret_state, uint *ret_len);
};
/*
* CLASS ht_c_syntax_lexer
*/
class ht_c_syntax_lexer: public ht_lang_syntax_lexer {
protected:
const char **c_reserved_sorted;
uint c_reserved_count;
palette c_pal;
virtual void config_changed();
void reloadpalette();
public:
void init();
virtual void done();
/* overwritten */
virtual vcp getcolor_syntax(uint pal_index);
virtual lexer_state getinitstate();
virtual lexer_token geterrortoken();
virtual const char *getname();
virtual lexer_token gettoken(void *buf, uint buflen, text_pos p, bool start_of_line, lexer_state *ret_state, uint *ret_len);
virtual vcp gettoken_color(lexer_token t);
};
#ifdef HT_HTML_SYNTAX_LEXER
/*
* CLASS ht_html_syntax_lexer
*/
class ht_html_syntax_lexer: public ht_lang_syntax_lexer {
protected:
char **html_reserved_sorted;
uint html_reserved_count;
palette html_pal;
virtual void config_changed();
void reloadpalette();
public:
void init();
virtual void done();
/* overwritten */
virtual vcp getcolor_syntax(uint pal_index);
virtual lexer_state getinitstate();
virtual lexer_token geterrortoken();
virtual const char *getname();
virtual lexer_token gettoken(void *buf, uint buflen, text_pos p, bool start_of_line, lexer_state *ret_state, uint *ret_len);
virtual vcp gettoken_color(lexer_token t);
};
#endif
const char **create_sorted_stringtable(const char **table);
/*
* syntax palette
*/
#define palkey_syntax_default "c/default"
#define palidx_syntax_whitespace 0
#define palidx_syntax_comment 1
#define palidx_syntax_identifier 2
#define palidx_syntax_reserved 3
#define palidx_syntax_intnum 4
#define palidx_syntax_floatnum 5
#define palidx_syntax_string 6
#define palidx_syntax_char 7
#define palidx_syntax_symbol 8
#define palidx_syntax_preprocess 9
#define palidx_syntax_meta 10
#endif /* __SYNTAX_H__ */
|