Support surrounding begin and end

This commit is contained in:
2024-03-10 08:50:55 +01:00
parent a3e3be5ec7
commit 2c396ece17
6 changed files with 248 additions and 41 deletions

View File

@ -209,6 +209,16 @@ namespace elna::source
return ss.str();
}
unexpected_token::unexpected_token(const token& token)
: error(token.position()), m_token(token)
{
}
std::string unexpected_token::what() const
{
return "Unexpected token";
}
source_result lex(const std::string& buffer)
{
std::vector<token> tokens;
@ -272,6 +282,14 @@ namespace elna::source
{
tokens.emplace_back(token::type::var, iterator.position());
}
else if (word == "begin")
{
tokens.emplace_back(token::type::begin, iterator.position());
}
else if (word == "end")
{
tokens.emplace_back(token::type::end, iterator.position());
}
else
{
tokens.emplace_back(token::type::identifier, word.c_str(), iterator.position());
@ -297,6 +315,8 @@ namespace elna::source
}
++iterator;
}
tokens.push_back(token(token::type::eof, iterator.position()));
return source_result(std::move(tokens));
}
}