Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDTill committed Jul 29, 2023
1 parent e59eced commit c73cdc6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
23 changes: 17 additions & 6 deletions src/forscape_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ void Error::writeErrors(const std::vector<Error>& errors, Typeset::Model* m, Typ
err.writeTo(m->lastText(), caller);
m->appendLine();
}

m->appendSerialToOutput(*errors.front().error_out);
}

Typeset::Model* Error::writeErrors(const std::vector<Error>& errors, Typeset::View* caller){
Expand Down Expand Up @@ -72,7 +74,7 @@ bool ErrorStream::noErrors() const noexcept {

void ErrorStream::fail(const Typeset::Selection& selection, ErrorCode code) alloc_except {
Typeset::Model* model = selection.getModel();
writeLocation(selection, model);
writeLocation(ERROR, selection, model);

const size_t start = error_out.size();
error_out += getMessage(code);
Expand All @@ -90,17 +92,20 @@ void ErrorStream::fail(const Typeset::Selection& selection, ErrorCode code) allo

void ErrorStream::fail(const Typeset::Selection& selection, const std::string& str, ErrorCode code) alloc_except {
Typeset::Model* model = selection.getModel();
writeLocation(selection, model);
writeLocation(ERROR, selection, model);

const size_t start = error_out.size();
error_out += str;
error_out += '\n';
errors.push_back(Error(selection, code, start, str.length(), &error_out));
model->errors.push_back(errors.back());
}

void ErrorStream::warn(WarningLevel warning_level, const Typeset::Selection& selection, ErrorCode code) alloc_except {
if(warning_level == NO_WARNING) return;

Typeset::Model* model = selection.getModel();
writeLocation(selection, model);
writeLocation(warning_level, selection, model);

const size_t start = error_out.size();
error_out += getMessage(code);
Expand All @@ -122,11 +127,14 @@ void ErrorStream::warn(WarningLevel warning_level, const Typeset::Selection& sel
}

void ErrorStream::warn(WarningLevel warning_level, const Typeset::Selection& selection, const std::string& str, ErrorCode code) alloc_except {
if(warning_level == NO_WARNING) return;

Typeset::Model* model = selection.getModel();
writeLocation(selection, model);
writeLocation(warning_level, selection, model);

const size_t start = error_out.size();
error_out += str;
error_out += '\n';

const Error error(selection, code, start, str.size(), &error_out);
switch (warning_level) {
Expand All @@ -136,11 +144,14 @@ void ErrorStream::warn(WarningLevel warning_level, const Typeset::Selection& sel
}
}

void ErrorStream::writeLocation(const Typeset::Selection& selection, const Typeset::Model* const model) alloc_except {
void ErrorStream::writeLocation(WarningLevel level, const Typeset::Selection& selection, const Typeset::Model* const model) alloc_except {
assert(model == selection.getModel());
error_out += warning_labels[level];
error_out += '\n';
error_out += model->path.u8string();
error_out += ':';
error_out += ": Line ";
error_out += selection.getStartLineAsString();
error_out += '\n';
//DO THIS: no link here, markerlink design is bad
}

Expand Down
3 changes: 1 addition & 2 deletions src/forscape_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class ErrorStream {
std::string error_out;
std::vector<Error> errors;
std::vector<Error> warnings;
Typeset::View* caller = nullptr; //DO THIS: this shouldn't be necessary

public:
void reset() noexcept;
Expand All @@ -50,7 +49,7 @@ class ErrorStream {
void warn(WarningLevel warning_level, const Typeset::Selection& selection, const std::string& str, ErrorCode code = ErrorCode::VALUE_NOT_DETERMINED) alloc_except;

private:
void writeLocation(const Typeset::Selection& selection, const Typeset::Model* const model) alloc_except;
void writeLocation(WarningLevel level, const Typeset::Selection& selection, const Typeset::Model* const model) alloc_except;
};

}
Expand Down
6 changes: 3 additions & 3 deletions src/forscape_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Parser::reset() noexcept {
index = 0;
parsing_dims = false;
loops = 0;
error_node = NONE;
error_node = model->errors.empty() ? NONE: parse_tree.addTerminal(model->errors.back().code, model->errors.back().selection);
}

void Parser::registerGrouping(const Typeset::Selection& sel) alloc_except {
Expand Down Expand Up @@ -1501,7 +1501,6 @@ ParseNode Parser::identifierFollowOn(ParseNode id) noexcept{
index = index_backup;

//DO THIS: you have to address this heinuous hack
error_stream.reset();
model->errors.clear();
error_node = NONE;
}
Expand Down Expand Up @@ -2146,7 +2145,8 @@ const Typeset::Marker& Parser::rMarkPrev() const noexcept{
}

bool Parser::noErrors() const noexcept{
return model->errors.empty(); //DO THIS: a bit odd here
assert((error_node == NONE) == (model->errors.empty()));
return error_node == NONE; //DO THIS: a bit odd here
}

void Parser::recover() noexcept{
Expand Down
2 changes: 0 additions & 2 deletions src/forscape_static_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ ParseNode StaticPass::resolveStmt(ParseNode pn) noexcept{

size_t child_rows = parse_tree.getRows(child);
if(rt.rows == UNKNOWN_SIZE) rt.rows = child_rows;

//DO THIS: give more descriptive error messages wherever DIMENSION_MISMATCH occurs
else if(rt.rows != child_rows && child_rows != UNKNOWN_SIZE) return error(pn, child, DIMENSION_MISMATCH);

return pn;
Expand Down

0 comments on commit c73cdc6

Please sign in to comment.