remove using std::*, switch to include guard
This commit is contained in:
parent
a72b6b2ec8
commit
8713aeac5e
|
@ -5,11 +5,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
using std::cout;
|
optional<string> ErrorInfo::programName = std::nullopt;
|
||||||
using std::endl;
|
|
||||||
using std::nullopt;
|
|
||||||
|
|
||||||
optional<string> ErrorInfo::programName = nullopt;
|
|
||||||
|
|
||||||
// return basic_format?
|
// return basic_format?
|
||||||
string showErrLine(ErrLine &errLine)
|
string showErrLine(ErrLine &errLine)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#ifndef error_hh
|
||||||
|
#define error_hh
|
||||||
|
|
||||||
#include "ansicolor.hh"
|
#include "ansicolor.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -8,12 +9,6 @@
|
||||||
|
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
using std::string;
|
|
||||||
using std::optional;
|
|
||||||
using boost::format;
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -36,7 +31,6 @@ class ErrLine {
|
||||||
optional<string> prevLineOfCode;
|
optional<string> prevLineOfCode;
|
||||||
string errLineOfCode;
|
string errLineOfCode;
|
||||||
optional<string> nextLineOfCode;
|
optional<string> nextLineOfCode;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NixCode {
|
class NixCode {
|
||||||
|
@ -112,8 +106,6 @@ class ErrorInfo {
|
||||||
protected:
|
protected:
|
||||||
// constructor is protected, so only the builder classes can create an ErrorInfo.
|
// constructor is protected, so only the builder classes can create an ErrorInfo.
|
||||||
ErrorInfo(ErrLevel level) { this->level = level; }
|
ErrorInfo(ErrLevel level) { this->level = level; }
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Init as error
|
// Init as error
|
||||||
|
@ -285,7 +277,9 @@ typedef AddName<
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
// error printing
|
// error printing
|
||||||
|
|
||||||
|
// just to cout for now.
|
||||||
void printErrorInfo(ErrorInfo &einfo);
|
void printErrorInfo(ErrorInfo &einfo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -3,95 +3,91 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using std::optional;
|
|
||||||
using std::nullopt;
|
|
||||||
using std::cout;
|
|
||||||
using std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
// In each program where errors occur, this has to be set.
|
// In each program where errors occur, this has to be set.
|
||||||
ErrorInfo::programName = optional("error-test");
|
ErrorInfo::programName = optional("error-test");
|
||||||
|
|
||||||
// There are currently four error types:
|
// There are currently four error types:
|
||||||
//
|
//
|
||||||
// ProgramError, ProgramWarning, NixLangError, NixLangWarning.
|
// ProgramError, ProgramWarning, NixLangError, NixLangWarning.
|
||||||
//
|
//
|
||||||
// Each error type is created with a specific sequence of builder functions.
|
// Each error type is created with a specific sequence of builder functions.
|
||||||
// Unlike with a constructor, each parameter is clearly named.
|
// Unlike with a constructor, each parameter is clearly named.
|
||||||
// If the sequence of function calls isn't followed, then there's a type error.
|
// 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.
|
// This should make for a consistent look in the code when errors are created.
|
||||||
|
|
||||||
// ProgramError takes name, description, and an optional hint.
|
// ProgramError takes name, description, and an optional hint.
|
||||||
printErrorInfo(
|
printErrorInfo(
|
||||||
ProgramError()
|
ProgramError()
|
||||||
.name("name")
|
.name("name")
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.nohint()
|
.nohint()
|
||||||
);
|
);
|
||||||
|
|
||||||
// ProgramWarning takes name, description, and an optional hint.
|
// ProgramWarning takes name, description, and an optional hint.
|
||||||
// The hint is in the form of a hintfmt class, which wraps boost::format(), and
|
// The hint is in the form of a hintfmt class, which wraps boost::format(), and
|
||||||
// makes all the substituted text yellow.
|
// makes all the substituted text yellow.
|
||||||
printErrorInfo(
|
printErrorInfo(
|
||||||
ProgramWarning()
|
ProgramWarning()
|
||||||
.name("warning name")
|
.name("warning name")
|
||||||
.description("warning description")
|
.description("warning description")
|
||||||
.hint(hintfmt("there was a %1%") % "warning") // 'warning' will be yellow.
|
.hint(hintfmt("there was a %1%") % "warning") // 'warning' will be yellow.
|
||||||
);
|
);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// some invalid errors:
|
// some invalid errors:
|
||||||
|
|
||||||
// type error: no hint function.
|
// type error: no hint function.
|
||||||
ProgramError()
|
ProgramError()
|
||||||
.name("name")
|
.name("name")
|
||||||
.description("error description");
|
.description("error description");
|
||||||
|
|
||||||
// type error: description before name.
|
// type error: description before name.
|
||||||
ProgramError()
|
ProgramError()
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.name("name")
|
.name("name")
|
||||||
.nohint();
|
.nohint();
|
||||||
|
|
||||||
// type error: hint function with regular boost format, not special hintfmt.
|
// type error: hint function with regular boost format, not special hintfmt.
|
||||||
ProgramError()
|
ProgramError()
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.name("name")
|
.name("name")
|
||||||
.hint(format("there was a %1%") % "warning");
|
.hint(format("there was a %1%") % "warning");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// NixLangWarning adds nix file, line number, column range, and the lines of code
|
// NixLangWarning adds nix file, line number, column range, and the lines of code
|
||||||
// where a warning occurred.
|
// where a warning occurred.
|
||||||
printErrorInfo(
|
printErrorInfo(
|
||||||
NixLangWarning()
|
NixLangWarning()
|
||||||
.name("warning name")
|
.name("warning name")
|
||||||
.description("warning description")
|
.description("warning description")
|
||||||
.nixFile("myfile.nix")
|
.nixFile("myfile.nix")
|
||||||
.lineNumber(40)
|
.lineNumber(40)
|
||||||
.columnRange(13,7)
|
.columnRange(13,7)
|
||||||
.linesOfCode(nullopt
|
.linesOfCode(std::nullopt
|
||||||
,"this is the problem line of code"
|
,"this is the problem line of code"
|
||||||
,nullopt)
|
,std::nullopt)
|
||||||
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
||||||
);
|
);
|
||||||
|
|
||||||
// NixLangError is just the same as NixLangWarning, except for the Error flag.
|
// NixLangError is just the same as NixLangWarning, except for the Error flag.
|
||||||
printErrorInfo(
|
printErrorInfo(
|
||||||
NixLangError()
|
NixLangError()
|
||||||
.name("error name")
|
.name("error name")
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.nixFile("myfile.nix")
|
.nixFile("myfile.nix")
|
||||||
.lineNumber(40)
|
.lineNumber(40)
|
||||||
.columnRange(13,7)
|
.columnRange(13,7)
|
||||||
.linesOfCode(optional("previous line of code")
|
.linesOfCode(optional("previous line of code")
|
||||||
,"this is the problem line of code"
|
,"this is the problem line of code"
|
||||||
,optional("next line of code"))
|
,optional("next line of code"))
|
||||||
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
||||||
);
|
);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue