diff options
author | JaceCearK1 <JaceCearK1@users.noreply.github.com> | 2017-07-01 21:04:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-01 21:04:18 +0200 |
commit | 0dd804a99e5455a0eac8ff6ed87d9de16c7380b7 (patch) | |
tree | 7b3567978b63ee6548a7b945e075ea8ba37bef51 /tools/ramscrgen/sym_file.cpp | |
parent | f1344efd2aff92292f58f7323bd9297a38fe9b02 (diff) | |
parent | 8d82578d3a101b06f9d2ced31738021007c4e533 (diff) |
Merge pull request #1 from pret/master
Update fork to match main fork.
Diffstat (limited to 'tools/ramscrgen/sym_file.cpp')
-rw-r--r-- | tools/ramscrgen/sym_file.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/ramscrgen/sym_file.cpp b/tools/ramscrgen/sym_file.cpp index 9d9e4a064..5379bd93f 100644 --- a/tools/ramscrgen/sym_file.cpp +++ b/tools/ramscrgen/sym_file.cpp @@ -53,6 +53,7 @@ SymFile::SymFile(std::string filename) : m_filename(filename) m_pos = 0; m_lineNum = 1; m_lineStart = 0; + m_inLangConditional = false; RemoveComments(); } @@ -387,12 +388,78 @@ void SymFile::ExpectEmptyRestOfLine() } } + +void SymFile::SkipLine() +{ + while (m_buffer[m_pos] != 0 && m_buffer[m_pos] != '\n') + m_pos++; + + if (m_buffer[m_pos] == '\n') + m_pos++; +} + // Checks if we're at the end of the file. bool SymFile::IsAtEnd() { return (m_pos >= m_size); } +void SymFile::HandleLangConditional(std::string lang) +{ + if (m_buffer[m_pos] != '#') + return; + + m_pos++; + + if (CheckForDirective("begin")) + { + if (m_inLangConditional) + RaiseError("already inside language conditional"); + + SkipWhitespace(); + + std::string label = GetLabel(false); + + if (label.length() == 0) + RaiseError("no language name after #begin"); + + ExpectEmptyRestOfLine(); + + if (lang == label) + { + m_inLangConditional = true; + } + else + { + while (!IsAtEnd() && m_buffer[m_pos] != '#') + SkipLine(); + + if (m_buffer[m_pos] != '#') + RaiseError("unterminated language conditional"); + + m_pos++; + + if (!CheckForDirective("end")) + RaiseError("expected #end"); + + ExpectEmptyRestOfLine(); + } + } + else if (CheckForDirective("end")) + { + if (!m_inLangConditional) + RaiseError("not inside language conditional"); + + m_inLangConditional = false; + + ExpectEmptyRestOfLine(); + } + else + { + RaiseError("unknown # directive"); + } +} + // Reports a diagnostic message. void SymFile::ReportDiagnostic(const char* type, const char* format, std::va_list args) { |