Skip to content

Commit

Permalink
Major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rep-movsd committed Nov 21, 2017
1 parent 6173385 commit b228960
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 188 deletions.
4 changes: 2 additions & 2 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ constexpr ErrLine ParseError(const char* /*unused*/)
}

// Set error message and location if not already set
#define PARSE_ERR(x) if(errRow == -1) {errRow = cur_row(); errCol = cur_col(); err = x;}
#define PARSE_ERR(x) if(m_iErrRow == -1) {m_iErrRow = cur_row(); m_iErrCol = cur_col(); m_arrErrs = x;}

// Push warning message and location to list
#define PARSE_WARN(x) warns.push_back(Message(x, cur_row(), cur_col()))
#define PARSE_WARN(x) m_arrWarns.push_back(Message(x, cur_row(), cur_col()))


#endif
Expand Down
10 changes: 7 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ using namespace std;
int main()
{
constexpr auto parser =
#include "test/loop.spt"
#include "test/if.spt"

REPORT_ERRORS(parser);

spt::tree spt_tree(parser);
spt::template_dict dct = spt_tree.get_default_dict();
spt_tree.root.render(cout, dct);

spt_tree.root().render(cout, dct);

cout << endl;

//parser.dump();
cout << endl;

}


8 changes: 4 additions & 4 deletions parse_error_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ template<> struct MsgToType<Error_Infinite_loop_in_for_tag>{using type = Infinit
#define DUMP_WARNING(x) \
if((x) < n) \
{ \
constexpr auto w = parser.warns[(x)]; \
constexpr auto w = parser.m_arrWarns[(x)]; \
spt::IF<w.m == spt::Error_Expecting_an_identifier, spt::Warning<w.row, w.col, spt::MsgToType<w.m>::type>> (); \
spt::IF<w.m == spt::Error_Unexpected_character_inside_tag_content, spt::Warning<w.row, w.col, spt::MsgToType<w.m>::type>> (); \
spt::IF<w.m == spt::Error_Expecting_a_tag_name_after_open_bracket, spt::Warning<w.row, w.col, spt::MsgToType<w.m>::type>> (); \
Expand All @@ -94,7 +94,7 @@ if((x) < n) \
}

#define REPORT_ERRORS(parser) \
constexpr int n = parser.warns.size(); \
constexpr int n = parser.m_arrWarns.size(); \
DUMP_WARNING(0); \
DUMP_WARNING(1); \
DUMP_WARNING(2); \
Expand All @@ -115,8 +115,8 @@ DUMP_WARNING(16); \
DUMP_WARNING(17); \
DUMP_WARNING(18); \
DUMP_WARNING(19); \
constexpr bool hasErr = parser.errRow > -1 || parser.errCol > -1; \
spt::IF<hasErr, spt::Error<parser.errRow, parser.errCol, spt::MsgToType<parser.err>::type>> {};
constexpr bool hasErr = parser.m_iErrRow > -1 || parser.m_iErrCol > -1; \
spt::IF<hasErr, spt::Error<parser.m_iErrRow, parser.m_iErrCol, spt::MsgToType<parser.m_arrErrs>::type>> {};

#else

Expand Down
8 changes: 4 additions & 4 deletions scripts/generate_parse_error_code.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ ${MsgToType}
#define DUMP_WARNING(x) \\
if((x) < n) \\
{ \\
constexpr auto w = parser.warns[(x)]; \\
constexpr auto w = parser.m_arrWarns[(x)]; \\
${warners}
}
#define REPORT_ERRORS(parser) \\
constexpr int n = parser.warns.size(); \\
constexpr int n = parser.m_arrWarns.size(); \\
${dumps}
constexpr bool hasErr = parser.errRow > -1 || parser.errCol > -1; \\
spt::IF<hasErr, spt::Error<parser.errRow, parser.errCol, spt::MsgToType<parser.err>::type>> {};
constexpr bool hasErr = parser.m_iErrRow > -1 || parser.m_iErrCol > -1; \\
spt::IF<hasErr, spt::Error<parser.m_iErrRow, parser.m_iErrCol, spt::MsgToType<parser.m_arrErrs>::type>> {};
#else
Expand Down
2 changes: 1 addition & 1 deletion scripts/make_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main()
spt::tree spt_tree(parser);
spt::template_dict dct;
spt_tree.root.render(cout, dct);
spt_tree.root().render(cout, dct);
}
`;

Expand Down
Loading

0 comments on commit b228960

Please sign in to comment.