2016-05-28 00:51:12 +02:00
# pragma once
# ifndef HIGHLIGHTER_H
# define HIGHLIGHTER_H
# include "XMLLexer.h"
# include <string>
# include <vector>
# include <map>
# include <iostream>
class Highlighter {
public :
2016-05-29 01:35:39 +02:00
/**
* Create a new Highlighter with the content of the xml file
*/
2016-05-28 00:51:12 +02:00
Highlighter ( std : : istream & file ) ;
virtual ~ Highlighter ( ) ;
2016-05-29 01:35:39 +02:00
/**
* Do the actual highlighting and write it to the provided ostream
* This is a pure virtual function and has to be implemented when creating a new kind of highlighter
*/
2016-05-28 00:51:12 +02:00
virtual void highlight ( std : : ostream & os ) = 0 ;
protected :
2016-05-29 01:35:39 +02:00
/**
* Do the actual work with the lexer
*/
2016-05-28 00:51:12 +02:00
void process ( ) ;
2016-05-29 01:35:39 +02:00
/**
* Local Tokentype used to identify what part of the xml structure is inside the token
* This is necessary because we use two different lexers with different TokenTypes
*/
2016-05-28 00:51:12 +02:00
enum TokenType {
2016-05-28 19:44:20 +02:00
COMMENT ,
2016-05-28 00:51:12 +02:00
TAG ,
CONTENT ,
ELEMENT ,
ATTRIBUTE ,
ATTRIBURE_CONTENT ,
WHITESPACE ,
BRACKET ,
nonmatching
} ;
2016-05-29 01:35:39 +02:00
/**
* Represent all the different colors
*/
2016-05-28 00:51:12 +02:00
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
2016-05-29 01:35:39 +02:00
/**
* A structure used to hold the tokens with their content , TokenType and color
*/
2016-05-28 00:51:12 +02:00
struct Token {
std : : string content = " " ;
Color color ;
TokenType type ;
} ;
2016-05-29 01:35:39 +02:00
// Used to determine the color connected to the TokenType
2016-05-28 00:51:12 +02:00
std : : map < TokenType , Color > colormap ;
2016-05-29 01:35:39 +02:00
// Hold the tokens
2016-05-28 00:51:12 +02:00
std : : vector < Token > m_tokens ;
2016-05-29 01:35:39 +02:00
// Hold the first lexer
2016-05-28 00:51:12 +02:00
XMLLexer * m_lexer ;
} ;
class ConsoleHighlighter : public Highlighter {
2016-05-29 01:35:39 +02:00
/**
* A SyntaxHighlighter specifically for console output
* Look at the base class for more information
*/
2016-05-28 00:51:12 +02:00
public :
ConsoleHighlighter ( std : : istream & file ) ;
void highlight ( std : : ostream & os ) ;
} ;
# endif // HIGHLIGHTER_H