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(); void process();
enum TokenType { enum TokenType {
COMMENT,
TAG, TAG,
CONTENT, CONTENT,
ELEMENT, ELEMENT,

View File

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

View File

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

View File

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