Implemented syntax highlighting for consequent part.

This commit is contained in:
Patrick Lühne 2016-11-24 03:16:37 +01:00
parent e65ec9b6c1
commit 098f2bf813
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
4 changed files with 29 additions and 15 deletions

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include <anthem/Utils.h> #include <anthem/Utils.h>
#include <anthem/output/ClingoOutput.h>
#include <anthem/output/Formatting.h> #include <anthem/output/Formatting.h>
namespace anthem namespace anthem
@ -148,22 +149,25 @@ struct TermPrintSubstitutedVisitor
throwErrorAtLocation(term.location, "“interval” terms currently unsupported, function expected", context); throwErrorAtLocation(term.location, "“interval” terms currently unsupported, function expected", context);
} }
// TODO: check correctness
void visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, Context &context) void visit(const Clingo::AST::Function &function, const Clingo::AST::Term &term, Context &context)
{ {
if (function.external) if (function.external)
throwErrorAtLocation(term.location, "external functions currently unsupported", context); throwErrorAtLocation(term.location, "external functions currently unsupported", context);
std::cout << function.name; auto &outputStream = context.logger.outputStream();
outputStream << output::Function(function.name);
if (function.arguments.empty()) if (function.arguments.empty())
return; return;
std::cout << "("; outputStream << "(";
for (auto i = function.arguments.cbegin(); i != function.arguments.cend(); i++) for (auto i = function.arguments.cbegin(); i != function.arguments.cend(); i++)
{ {
if (i != function.arguments.cbegin()) if (i != function.arguments.cbegin())
std::cout << ","; outputStream << ", ";
const auto &argument = *i; const auto &argument = *i;
@ -171,10 +175,12 @@ struct TermPrintSubstitutedVisitor
assert(matchingTerm != context.headTerms.cend()); assert(matchingTerm != context.headTerms.cend());
std::cout << AuxiliaryHeadVariablePrefix << (matchingTerm - context.headTerms.cbegin()); const auto variableName = std::string(AuxiliaryHeadVariablePrefix) + std::to_string(matchingTerm - context.headTerms.cbegin());
outputStream << output::Variable(variableName.c_str());
} }
std::cout << ")"; outputStream << ")";
} }
void visit(const Clingo::AST::Pool &, const Clingo::AST::Term &term, Context &context) void visit(const Clingo::AST::Pool &, const Clingo::AST::Term &term, Context &context)
@ -189,7 +195,7 @@ struct LiteralPrintSubstitutedVisitor
{ {
void visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, Context &context) void visit(const Clingo::AST::Boolean &boolean, const Clingo::AST::Literal &, Context &context)
{ {
std::cout << (boolean.value == true ? "true" : "false"); context.logger.outputStream() << boolean;
} }
void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, Context &context) void visit(const Clingo::AST::Term &term, const Clingo::AST::Literal &, Context &context)
@ -217,7 +223,7 @@ struct HeadLiteralPrintSubstitutedVisitor
if (literal.sign == Clingo::AST::Sign::DoubleNegation) if (literal.sign == Clingo::AST::Sign::DoubleNegation)
throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context); throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context);
else if (literal.sign == Clingo::AST::Sign::Negation) else if (literal.sign == Clingo::AST::Sign::Negation)
std::cout << "not "; context.logger.outputStream() << Clingo::AST::Sign::Negation << " ";
literal.data.accept(LiteralPrintSubstitutedVisitor(), literal, context); literal.data.accept(LiteralPrintSubstitutedVisitor(), literal, context);
} }
@ -232,7 +238,7 @@ struct HeadLiteralPrintSubstitutedVisitor
throwErrorAtLocation(headLiteral.location, "conditional head literals currently unsupported", context); throwErrorAtLocation(headLiteral.location, "conditional head literals currently unsupported", context);
if (i != disjunction.elements.cbegin()) if (i != disjunction.elements.cbegin())
std::cout << " or "; context.logger.outputStream() << " " << output::Keyword("or") << " ";
visit(conditionLiteral.literal, headLiteral, context); visit(conditionLiteral.literal, headLiteral, context);
} }

View File

@ -18,6 +18,7 @@ namespace output
ColorStream &operator<<(ColorStream &stream, const Clingo::Symbol &symbol); ColorStream &operator<<(ColorStream &stream, const Clingo::Symbol &symbol);
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Sign &sign); ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Sign &sign);
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Boolean &boolean);
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Variable &variable); ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Variable &variable);
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::BinaryOperator &binaryOperator); ColorStream &operator<<(ColorStream &stream, const Clingo::AST::BinaryOperator &binaryOperator);
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::UnaryOperation &unaryOperation); ColorStream &operator<<(ColorStream &stream, const Clingo::AST::UnaryOperation &unaryOperation);

View File

@ -98,10 +98,7 @@ struct Function
inline ColorStream &operator<<(ColorStream &stream, const Function &function) inline ColorStream &operator<<(ColorStream &stream, const Function &function)
{ {
return (stream return (stream << function.name);
<< Format({Color::White, FontWeight::Bold})
<< function.name
<< ResetFormat());
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -217,12 +214,12 @@ inline ColorStream &operator<<(ColorStream &stream, const String &string)
struct Boolean struct Boolean
{ {
Boolean(bool value) Boolean(const char *value)
: value{value} : value{value}
{ {
}; };
bool value; const char *value;
}; };
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
@ -231,7 +228,7 @@ inline ColorStream &operator<<(ColorStream &stream, const Boolean &boolean)
{ {
return (stream return (stream
<< Format({Color::Red, FontWeight::Normal}) << Format({Color::Red, FontWeight::Normal})
<< (boolean.value == true ? "true" : "false") << boolean.value
<< ResetFormat()); << ResetFormat());
} }

View File

@ -96,6 +96,16 @@ ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Sign &sign)
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Boolean &boolean)
{
if (boolean.value == true)
return (stream << Boolean("#true"));
return (stream << Boolean("#false"));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Variable &variable) ColorStream &operator<<(ColorStream &stream, const Clingo::AST::Variable &variable)
{ {
return (stream << Variable(variable.name)); return (stream << Variable(variable.name));