File: syntax.h

package info (click to toggle)
ht 0.5.0-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,388 kB
  • ctags: 9,064
  • sloc: cpp: 51,336; ansic: 11,954; sh: 2,742; yacc: 1,142; lex: 396; makefile: 178
file content (107 lines) | stat: -rw-r--r-- 2,647 bytes parent folder | download
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
/* 
 *	HT Editor
 *	syntax.h
 *
 *	Copyright (C) 2001 Stefan Weyergraf (stefan@weyergraf.de)
 *
 *	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 "common.h"
#include "htio.h"

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_REGEX,
	LRST_CHARSET,
	LRST_WHITESPACE,
	LRST_ANYCHAR
};

struct syntax_lexer_rule {
	lexer_state_set needstate;
	bool need_line_start;
	lexer_rule_string_type string_type;
	char *string;
	lexer_state state;
	lexer_token token;
};

/*
 *	CLASS ht_syntax_lexer
 */

class ht_syntax_lexer: public object {
public:
/* new */
	virtual	lexer_state getinitstate()=0;
	virtual	lexer_token geterrortoken()=0;
	virtual	lexer_token gettoken(char *buf, lexer_state *state, text_pos *p, UINT *len, bool start_of_line, bool only_state_changers)=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(char *buf, lexer_state *state, text_pos *p, UINT *len, bool start_of_line, bool only_state_changers);
};

/*
 *	CLASS ht_c_syntax_lexer
 */

class ht_c_syntax_lexer: public ht_lang_syntax_lexer {
protected:
	char **c_reserved_sorted;
	UINT c_reserved_count;
public:
			void init();
	virtual	void done();
/* overwritten */
	virtual	lexer_state getinitstate();
	virtual	lexer_token geterrortoken();
	virtual	lexer_token gettoken(char *buf, lexer_state *state, text_pos *p, UINT *len, bool start_of_line, bool only_state_changers);
	virtual	vcp gettoken_color(lexer_token t);
};

char **create_sorted_stringtable(char **table);

#endif /* __SYNTAX_H__ */