Skip to content

Commit

Permalink
Merge commit '61878e70635a30ac834a25c227a3fefd309bd623'
Browse files Browse the repository at this point in the history
  • Loading branch information
kmurray committed Nov 4, 2016
2 parents 8f11abb + 61878e7 commit 99d1f79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
25 changes: 24 additions & 1 deletion libblifparse/src/blif_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace blifparse {

std::string escape_string(const std::string& near_text);

//We wrap the actual blif_error to issolate custom handlers from vaargs
void blif_error_wrap(Callback& callback, const int line_no, const std::string& near_text, const char* fmt, ...) {
va_list args;
Expand Down Expand Up @@ -39,8 +41,29 @@ void blif_error_wrap(Callback& callback, const int line_no, const std::string& n
//Build the string from the buffer
std::string msg(buf.get(), len);

//TODO: escape near_text
std::string escaped_near_text = escape_string(near_text);

//Call the error handler
callback.parse_error(line_no, near_text, msg);
callback.parse_error(line_no, escaped_near_text, msg);
}

std::string escape_string(const std::string& near_text) {
std::string escaped_text;

for(char c : near_text) {

if(c == '\n') {
escaped_text += "\\n";
} else if(c == '\r') {
escaped_text += "\\r";
} else {
escaped_text += c;
}
}

return escaped_text;
}


}
4 changes: 0 additions & 4 deletions libblifparse/src/blif_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include "blifparse.hpp"
namespace blifparse {


extern std::function<void(const int, const std::string&, const std::string&)> blif_error;

void blif_error_wrap(Callback& callback, const int line_no, const std::string& near_text, const char* fmt, ...);

}
#endif
2 changes: 1 addition & 1 deletion libblifparse/src/blif_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DIGITS [0-9]
ALPHA_NUM_SYMBOLS ({ALPHA_SYMBOLS}|{DIGITS})
BACK_SLASH [\\]
WS [ \t]
ENDL (\n|\n\r)
ENDL (\n|\n\r|\r\n)

/* Special Parser States */
%x LATCH
Expand Down

0 comments on commit 99d1f79

Please sign in to comment.