Changed regexes a bit and added support for comments

This commit is contained in:
Thomas Ave 2016-05-28 19:44:20 +02:00
parent 86df359a97
commit e19380b4ab
4 changed files with 11 additions and 4 deletions

View File

@ -22,6 +22,7 @@ class Highlighter {
void process();
enum TokenType {
COMMENT,
TAG,
CONTENT,
ELEMENT,

View File

@ -1,6 +1,6 @@
ELEMENT = </?[ ]*[a-zA-Z0-9]*
ELEMENT = </?[ ]*[a-zA-Z0-9-]*
WHITESPACE = [ ]*
ATTRIBUTE = [a-zA-Z0-9]*[ ]*=
ATTRIBUTE_CONTENT_DOUBLE_QUOTES = [ ]*"[^<>"]*"
ATTRIBUTE_CONTENT_SINGLE_QUOTES = [ ]*'[^<>']*'
ATTRIBUTE = [a-zA-Z0-9-]*[ ]*=
ATTRIBUTE_CONTENT_DOUBLE_QUOTES = "[^<>"]*"
ATTRIBUTE_CONTENT_SINGLE_QUOTES = '[^<>']*'
BRACKET = [</>]

View File

@ -11,6 +11,7 @@ Highlighter::Highlighter(std::istream &file) {
colormap[ATTRIBURE_CONTENT] = Undefined;
colormap[BRACKET] = Undefined;
colormap[nonmatching] = Undefined;
colormap[COMMENT] = Undefined;
}
Highlighter::~Highlighter() {
@ -30,6 +31,9 @@ void Highlighter::process() {
case XMLLexer::TokenType::TAG:
newtoken.type = TAG;
break;
case XMLLexer::TokenType::COMMENT:
newtoken.type = COMMENT;
break;
default:
newtoken.type = nonmatching;
break;
@ -103,6 +107,7 @@ ConsoleHighlighter::ConsoleHighlighter(std::istream &file): Highlighter(file) {
colormap[ATTRIBURE_CONTENT] = Green;
colormap[BRACKET] = Blue;
colormap[nonmatching] = Black;
colormap[COMMENT] = Black;
process();
}

View File

@ -1,2 +1,3 @@
COMMENT = <!--[^<>]*-->
TAG = </?[^<>]*>
CONTENT = [^<>]*