Implemented syntax highlighting for consequent part.
This commit is contained in:
parent
e65ec9b6c1
commit
098f2bf813
@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <anthem/Utils.h>
|
||||
#include <anthem/output/ClingoOutput.h>
|
||||
#include <anthem/output/Formatting.h>
|
||||
|
||||
namespace anthem
|
||||
@ -148,22 +149,25 @@ struct TermPrintSubstitutedVisitor
|
||||
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)
|
||||
{
|
||||
if (function.external)
|
||||
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())
|
||||
return;
|
||||
|
||||
std::cout << "(";
|
||||
outputStream << "(";
|
||||
|
||||
for (auto i = function.arguments.cbegin(); i != function.arguments.cend(); i++)
|
||||
{
|
||||
if (i != function.arguments.cbegin())
|
||||
std::cout << ",";
|
||||
outputStream << ", ";
|
||||
|
||||
const auto &argument = *i;
|
||||
|
||||
@ -171,10 +175,12 @@ struct TermPrintSubstitutedVisitor
|
||||
|
||||
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)
|
||||
@ -189,7 +195,7 @@ struct LiteralPrintSubstitutedVisitor
|
||||
{
|
||||
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)
|
||||
@ -217,7 +223,7 @@ struct HeadLiteralPrintSubstitutedVisitor
|
||||
if (literal.sign == Clingo::AST::Sign::DoubleNegation)
|
||||
throwErrorAtLocation(literal.location, "double-negated literals currently unsupported", context);
|
||||
else if (literal.sign == Clingo::AST::Sign::Negation)
|
||||
std::cout << "not ";
|
||||
context.logger.outputStream() << Clingo::AST::Sign::Negation << " ";
|
||||
|
||||
literal.data.accept(LiteralPrintSubstitutedVisitor(), literal, context);
|
||||
}
|
||||
@ -232,7 +238,7 @@ struct HeadLiteralPrintSubstitutedVisitor
|
||||
throwErrorAtLocation(headLiteral.location, "conditional head literals currently unsupported", context);
|
||||
|
||||
if (i != disjunction.elements.cbegin())
|
||||
std::cout << " or ";
|
||||
context.logger.outputStream() << " " << output::Keyword("or") << " ";
|
||||
|
||||
visit(conditionLiteral.literal, headLiteral, context);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace output
|
||||
|
||||
ColorStream &operator<<(ColorStream &stream, const Clingo::Symbol &symbol);
|
||||
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::BinaryOperator &binaryOperator);
|
||||
ColorStream &operator<<(ColorStream &stream, const Clingo::AST::UnaryOperation &unaryOperation);
|
||||
|
@ -98,10 +98,7 @@ struct Function
|
||||
|
||||
inline ColorStream &operator<<(ColorStream &stream, const Function &function)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::White, FontWeight::Bold})
|
||||
<< function.name
|
||||
<< ResetFormat());
|
||||
return (stream << function.name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -217,12 +214,12 @@ inline ColorStream &operator<<(ColorStream &stream, const String &string)
|
||||
|
||||
struct Boolean
|
||||
{
|
||||
Boolean(bool value)
|
||||
Boolean(const char *value)
|
||||
: value{value}
|
||||
{
|
||||
};
|
||||
|
||||
bool value;
|
||||
const char *value;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -231,7 +228,7 @@ inline ColorStream &operator<<(ColorStream &stream, const Boolean &boolean)
|
||||
{
|
||||
return (stream
|
||||
<< Format({Color::Red, FontWeight::Normal})
|
||||
<< (boolean.value == true ? "true" : "false")
|
||||
<< boolean.value
|
||||
<< ResetFormat());
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
return (stream << Variable(variable.name));
|
||||
|
Loading…
Reference in New Issue
Block a user