comment cleanup

This commit is contained in:
Ben Burdette 2020-04-06 20:14:48 -06:00
parent ec449c8450
commit 55c96b64e4
2 changed files with 23 additions and 153 deletions

View file

@ -11,15 +11,10 @@ int main()
// In each program where errors occur, this has to be set.
ErrorInfo::programName = std::optional("error-demo");
// There are currently four error types:
// There are currently four constructor functions:
//
// ProgramError, ProgramWarning, NixLangError, NixLangWarning.
//
// Each error type is created with a specific sequence of builder functions.
// Unlike with a constructor, each parameter is clearly named.
// If the sequence of function calls isn't followed, then there's a type
// error. This should make for a consistent look in the code when errors are
// created.
// ProgramError takes name, description, and an optional hint.
printErrorInfo(
@ -33,68 +28,35 @@ int main()
printErrorInfo(
ErrorInfo::ProgramWarning("name",
"warning description",
std::optional(hintfmt("there was a %1%", "warning"))));
// printErrorInfo( ProgramWarning()
// .name("warning name")
// .description("warning description")
// // the templated value, 'warning', is automatically colored yellow.
// .hint(hintfmt("there was a %1%", "warning"))
// );
/*
// some invalid errors:
// type error: no hint function.
ProgramError()
.name("name")
.description("error description");
// type error: description before name.
ProgramError()
.description("error description")
.name("name")
.nohint();
// type error: hint function with regular boost format, not special
hintfmt. ProgramError() .description("error description") .name("name")
.hint(format("there was a %1%") % "warning");
*/
std::optional(
hintfmt("there was a %1%", "warning"))));
// NixLangWarning adds nix file, line number, column range, and the lines of
// code where a warning occurred.
SymbolTable testTable;
auto problem_symbol = testTable.create("problem");
printErrorInfo(ErrorInfo::NixLangWarning(
"warning name",
"warning description",
Pos(problem_symbol, 40, 13),
std::nullopt,
"this is the problem line of code",
std::nullopt,
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
// // NixLangError is just the same as NixLangWarning, except for the Error
// // flag.
// printErrorInfo(NixLangError()
// .name("error name")
// .description("error description")
// .pos(Pos(problem_symbol, 40, 13))
// .linesOfCode(std::optional("previous line of code"),
// "this is the problem line of code",
// std::optional("next line of code"))
// .hint(hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
printErrorInfo(ErrorInfo::NixLangError(
"error name",
"error description",
Pos(problem_symbol, 40, 13),
std::optional("previous line of code"),
"this is the problem line of code",
std::optional("next line of code"),
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
printErrorInfo(
ErrorInfo::NixLangWarning(
"warning name",
"warning description",
Pos(problem_symbol, 40, 13),
std::nullopt,
"this is the problem line of code",
std::nullopt,
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
// NixLangError is just the same as NixLangWarning, except for the Error
// flag.
printErrorInfo(
ErrorInfo::NixLangError(
"error name",
"error description",
Pos(problem_symbol, 40, 13),
std::optional("previous line of code"),
"this is the problem line of code",
std::optional("next line of code"),
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
return 0;
}

View file

@ -191,98 +191,6 @@ private:
}
};
/*
template <class T>
class AddPos : private T
{
public:
template <class P>
T& pos(const P &aPos)
{
GetEI().ensureNixCode().nixFile = aPos.file;
GetEI().ensureNixCode().ensureErrLine().lineNumber = aPos.line;
GetEI().ensureNixCode().ensureErrLine().columnRange = { .start = aPos.column, .len = 1 };
return *this;
}
protected:
ErrorInfo& GetEI()
{
return T::GetEI();
}
};
template <class T>
class AddLOC : private T
{
public:
T& linesOfCode(std::optional<string> prevloc, string loc, std::optional<string> nextloc)
{
GetEI().ensureNixCode().ensureErrLine().prevLineOfCode = prevloc;
GetEI().ensureNixCode().ensureErrLine().errLineOfCode = loc;
GetEI().ensureNixCode().ensureErrLine().nextLineOfCode = nextloc;
return *this;
}
protected:
ErrorInfo& GetEI()
{
return T::GetEI();
}
};
*/
/*
// the template layer for adding a hint.
template <class T>
class AddHint : private T
{
public:
T& hint(const hintformat &hf)
{
GetEI().hint = std::optional(hf.str());
return *this;
}
T& nohint()
{
GetEI().hint = std::nullopt;
return *this;
}
protected:
ErrorInfo& GetEI()
{
return T::GetEI();
}
};
*/
// --------------------------------------------------------
// error types
/*typedef AddName<
AddDescription<
AddHint<
EIError>>> ProgramError;
typedef AddName<
AddDescription<
AddHint<
EIWarning>>> ProgramWarning;
typedef AddName<
AddDescription<
AddPos<
AddLOC<
AddHint<
EIError>>>>> NixLangError;
typedef AddName<
AddDescription<
AddPos<
AddLOC<
AddHint<
EIWarning>>>>> NixLangWarning;
*/
// --------------------------------------------------------
// error printing