Eval
- ::dump method now colorizeѕ tokens according to a map.
This commit is contained in:
52
src/Eval.cpp
52
src/Eval.cpp
@@ -25,8 +25,10 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
|
#include <Color.h>
|
||||||
#include <Eval.h>
|
#include <Eval.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
@@ -858,6 +860,28 @@ bool Eval::identifyOperator (
|
|||||||
std::string Eval::dump (
|
std::string Eval::dump (
|
||||||
std::vector <std::pair <std::string, Lexer::Type> >& tokens) const
|
std::vector <std::pair <std::string, Lexer::Type> >& tokens) const
|
||||||
{
|
{
|
||||||
|
// Set up a color mapping.
|
||||||
|
std::map <Lexer::Type, Color> color_map;
|
||||||
|
color_map[Lexer::typeNone] = Color ("color15 on gray4");
|
||||||
|
color_map[Lexer::typeOperator] = Color ("green on gray4");
|
||||||
|
/*
|
||||||
|
Lexer::typeOperator
|
||||||
|
Lexer::typeNone
|
||||||
|
Lexer::typeString
|
||||||
|
Lexer::typeIdentifier
|
||||||
|
Lexer::typeIdentifierEscape
|
||||||
|
Lexer::typeEscape
|
||||||
|
Lexer::typeEscapeHex
|
||||||
|
Lexer::typeEscapeUnicode
|
||||||
|
Lexer::typeNumber
|
||||||
|
Lexer::typeDecimal
|
||||||
|
Lexer::typeExponentIndicator
|
||||||
|
Lexer::typeExponent
|
||||||
|
Lexer::typeHex
|
||||||
|
Lexer::typeDate
|
||||||
|
Lexer::typeDuration
|
||||||
|
*/
|
||||||
|
|
||||||
std::string output;
|
std::string output;
|
||||||
std::vector <std::pair <std::string, Lexer::Type> >::const_iterator i;
|
std::vector <std::pair <std::string, Lexer::Type> >::const_iterator i;
|
||||||
for (i = tokens.begin (); i != tokens.end (); ++i)
|
for (i = tokens.begin (); i != tokens.end (); ++i)
|
||||||
@@ -865,29 +889,13 @@ std::string Eval::dump (
|
|||||||
if (i != tokens.begin ())
|
if (i != tokens.begin ())
|
||||||
output += ' ';
|
output += ' ';
|
||||||
|
|
||||||
switch (i->second)
|
Color c;
|
||||||
{
|
if (color_map[i->second].nontrivial ())
|
||||||
case Lexer::typeOperator:
|
c = color_map[i->second];
|
||||||
output += i->first;
|
else
|
||||||
break;
|
c = color_map[Lexer::typeNone];
|
||||||
|
|
||||||
case Lexer::typeNone:
|
output += c.colorize (i->first);
|
||||||
case Lexer::typeString:
|
|
||||||
case Lexer::typeIdentifier:
|
|
||||||
case Lexer::typeIdentifierEscape:
|
|
||||||
case Lexer::typeEscape:
|
|
||||||
case Lexer::typeEscapeHex:
|
|
||||||
case Lexer::typeEscapeUnicode:
|
|
||||||
case Lexer::typeNumber:
|
|
||||||
case Lexer::typeDecimal:
|
|
||||||
case Lexer::typeExponentIndicator:
|
|
||||||
case Lexer::typeExponent:
|
|
||||||
case Lexer::typeHex:
|
|
||||||
case Lexer::typeDate:
|
|
||||||
case Lexer::typeDuration:
|
|
||||||
output += i->first;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
|||||||
Reference in New Issue
Block a user