Lexesis/examples/SyntaxHighlighter/include/highlighter.h

56 lines
1.2 KiB
C++

#pragma once
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include "XMLLexer.h"
#include <string>
#include <vector>
#include <map>
#include <iostream>
class Highlighter {
public:
Highlighter(std::istream &file);
virtual ~Highlighter();
virtual void highlight(std::ostream &os)=0;
protected:
void process();
enum TokenType {
COMMENT,
TAG,
CONTENT,
ELEMENT,
ATTRIBUTE,
ATTRIBURE_CONTENT,
WHITESPACE,
BRACKET,
nonmatching
};
enum Color { Red, Green, Blue, Orange, Yellow, Cyan, Grey, Black, White, Magenta, Pink, Brown, Indigo, Violet, Undefined}; // All the colors, not all of them are used, but it's easy to change now
struct Token {
std::string content = "";
Color color;
TokenType type;
};
std::map<TokenType, Color> colormap;
std::vector<Token> m_tokens;
XMLLexer *m_lexer;
};
class ConsoleHighlighter: public Highlighter {
public:
ConsoleHighlighter(std::istream &file);
void highlight(std::ostream &os);
};
#endif // HIGHLIGHTER_H