Changed %const format in preprocesser now
Instead of %const(<name>) ... %end it will now be %const <name> ... %end i.e. the first symbol after %const will be considered the name of the constant similar to %use.
This commit is contained in:
@@ -25,7 +25,7 @@ static_assert(NUMBER_OF_OPCODES == 98, "ERROR: Lexer is out of date");
|
|||||||
using std::string, std::string_view, std::pair, std::make_pair;
|
using std::string, std::string_view, std::pair, std::make_pair;
|
||||||
|
|
||||||
const auto VALID_SYMBOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV"
|
const auto VALID_SYMBOL = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV"
|
||||||
"WXYZ0123456789-_.:()%#$",
|
"WXYZ0123456789-_.:%#$",
|
||||||
VALID_DIGIT = "0123456789", VALID_HEX = "0123456789abcdefABCDEF";
|
VALID_DIGIT = "0123456789", VALID_HEX = "0123456789abcdefABCDEF";
|
||||||
|
|
||||||
bool is_char_in_s(char c, const char *s)
|
bool is_char_in_s(char c, const char *s)
|
||||||
@@ -52,7 +52,7 @@ pair<token_t, lerr_t> tokenise_symbol(string_view &source, size_t &column,
|
|||||||
|
|
||||||
if (initial_match(sym, "%CONST"))
|
if (initial_match(sym, "%CONST"))
|
||||||
{
|
{
|
||||||
t = token_t(token_type_t::PP_CONST, sym.substr(6));
|
t.type = token_type_t::PP_CONST;
|
||||||
}
|
}
|
||||||
else if (sym == "%USE")
|
else if (sym == "%USE")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -81,20 +81,9 @@ pp_err_t preprocess_const_blocks(const vector<token_t *> &tokens,
|
|||||||
if (t->type == token_type_t::PP_CONST)
|
if (t->type == token_type_t::PP_CONST)
|
||||||
{
|
{
|
||||||
string_view capture;
|
string_view capture;
|
||||||
if (t->content == "" && (i == tokens.size() - 1 ||
|
if (i + 1 >= tokens.size() || tokens[i + 1]->type != token_type_t::SYMBOL)
|
||||||
tokens[i + 1]->type != token_type_t::SYMBOL))
|
|
||||||
return ERR(pp_err_t{pp_err_type_t::EXPECTED_NAME});
|
|
||||||
else if (t->content != "")
|
|
||||||
capture = t->content;
|
|
||||||
else
|
|
||||||
capture = tokens[++i]->content;
|
capture = tokens[++i]->content;
|
||||||
|
|
||||||
// Check for brackets
|
|
||||||
auto start = capture.find('(');
|
|
||||||
auto end = capture.find(')');
|
|
||||||
if (start == string::npos || end == string::npos)
|
|
||||||
return ERR(pp_err_t{pp_err_type_t::EXPECTED_NAME});
|
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
size_t block_start = i, block_end = 0;
|
size_t block_start = i, block_end = 0;
|
||||||
for (; i < tokens.size() && tokens[i]->type != token_type_t::PP_END; ++i)
|
for (; i < tokens.size() && tokens[i]->type != token_type_t::PP_END; ++i)
|
||||||
@@ -105,8 +94,7 @@ pp_err_t preprocess_const_blocks(const vector<token_t *> &tokens,
|
|||||||
|
|
||||||
block_end = i;
|
block_end = i;
|
||||||
|
|
||||||
blocks[capture.substr(start + 1, end - 1)] =
|
blocks[capture] = const_t{block_start, block_end};
|
||||||
const_t{block_start, block_end};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user