Skip to content

Commit

Permalink
Improve error handling messages
Browse files Browse the repository at this point in the history
This patch adds the line where the problem happens to help
investigation.

Signed-off-by: Jose Ricardo Ziviani <[email protected]>
  • Loading branch information
jrziviani committed Feb 16, 2019
1 parent ddae221 commit 2dfe638
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 111 deletions.
15 changes: 11 additions & 4 deletions include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ namespace amps
bool run_endif(parser_iterator &it);
bool run_insert(parser_iterator &it, metainfo &metainfo);

object compute(token_types oper);
object compute_unary(token_types oper);
object compute(token_types oper, size_t line);
object compute_unary(token_types oper, size_t line);
object compute_numbers(number_t a,
number_t b,
token_types oper);
token_types oper, size_t line);
object compute_strings(std::string a,
std::string b,
token_types oper);
Expand All @@ -87,10 +87,12 @@ namespace amps
friend class compiler;

const tokens &tokens_;
const metarange &range_;
size_t cursor_;

parser_iterator(const tokens &tks) :
parser_iterator(const tokens &tks, const metarange &range) :
tokens_(tks),
range_(range),
cursor_(0)
{
}
Expand Down Expand Up @@ -140,6 +142,11 @@ namespace amps
}
}

metarange range() const
{
return range_;
}

bool match(token_types type)
{
if (!is_eot() && tokens_[cursor_].type() == type) {
Expand Down
10 changes: 8 additions & 2 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ namespace amps
void log(const T &msg, const Ts... msgs)
{
if constexpr (sizeof...(Ts) > 0) {
stream_ << msg << " ";
stream_ << msg;
log(msgs...);
}
else {
stream_ << msg << std::flush;
stream_ << msg << std::endl;
}
}

template <typename... Ts>
void critical(const Ts... msgs)
{
log("Error: ", msgs...);
}
};
}

Expand Down
1 change: 1 addition & 0 deletions include/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace amps
{
size_t start;
size_t end;
size_t line;
};

struct metadata
Expand Down
3 changes: 1 addition & 2 deletions include/vector_ostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace amps
continue;
}

// add string without \n
data_.push_back(std::string(start, len - 1));
data_.push_back(std::string(start, len));
start += len + 1;
len = 0;
}
Expand Down
Loading

0 comments on commit 2dfe638

Please sign in to comment.