-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgnu_source_highlight.h
84 lines (74 loc) · 3.12 KB
/
gnu_source_highlight.h
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
/*
* Copyright (C) 2016 Richard Burke
*
* Based on lib/examples/infoformatter.h in source-highlight
* by Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2009
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WED_SOURCE_HIGHLIGHT_H
#define WED_SOURCE_HIGHLIGHT_H
#include <srchilite/sourcehighlighter.h>
#include <srchilite/formattermanager.h>
#include <srchilite/formatterparams.h>
extern "C" {
#include "gnu_source_highlight_syntax.h"
}
namespace wed {
class Tokenizer;
/* An instance of this class is created for each source-highlight token.
* These instances are passed to the source-highlight library, which invokes
* the format function when a token of the specified type is matched. This
* allows wed to determine the tokens and their positions within an
* input string from source-highlight */
class TokenizerFormatter : public srchilite::Formatter {
private:
SyntaxToken token; /* The corresponding wed SyntaxToken */
Tokenizer *tokenizer; /* Reference to main interface object */
bool is_continuation_of_previous_token(int start);
public:
TokenizerFormatter(SyntaxToken token, Tokenizer *tokenizer);
void format(const std::string &s,
const srchilite::FormatterParams *params);
};
typedef boost::shared_ptr<TokenizerFormatter> TokenizerFormatterPtr;
/* This class wraps around all objects used to interact with
* source-highlight. An instance of this class is created for each filetype */
class Tokenizer {
private:
/* Processes each line of input and tokenizes it based on the
lanuage definition it was created with */
srchilite::SourceHighlighter *highlighter;
/* Maps a source-highlight token to the relevant formater
function */
srchilite::FormatterManager *fmt_manager;
/* Stores arguments that can be passed to formatter format function */
srchilite::FormatterParams *fmt_params;
/* Stores the tokens matched */
SyntaxMatches *syn_matches;
/* Tracks the offset into the input string that has been processed
so far */
size_t offset;
public:
Tokenizer(srchilite::SourceHighlighter *highlighter,
srchilite::FormatterManager *fmt_manager,
srchilite::FormatterParams *fmt_params);
~Tokenizer();
void tokenize(const std::string &str);
SyntaxMatches *get_syn_matches() const;
size_t get_offset() const;
};
}
#endif