feat: add string parser

This commit is contained in:
TopchetoEU 2022-10-28 10:14:58 +03:00
parent 90497f601d
commit e755850c6f
2 changed files with 14 additions and 3 deletions

View File

@ -13,9 +13,9 @@ group_t &ast_ctx_t::group(const std::string &name) {
ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector<token_t> &tokens): messages(messages), tokens(tokens) {
group("$_exp_val")
.add_last("$_var", parse_exp_var)
.add_last("$_int", parse_exp_int_lit);
.add_last("$_int", parse_exp_int_lit)
.add_last("$_string", parse_exp_str_lit);
// .add_last("$_float", parse_exp_float_lit)
// .add_last("$_string", parse_exp_str_lit);
group("$_stat")
.add_last("$_exp", parse_stat_exp);
group("$_def")

View File

@ -159,7 +159,7 @@ bool ast::parse_exp_var(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
bool ast::parse_exp_int_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
tree_helper_t h(ctx, res_i);
if (h.curr().is_literal()) {
if (h.curr().is_int_literal()) {
auto &arr = out["content"].array({});
for (auto b : h.curr().literal()) arr.push_back((float)b);
out["location"] = conv::loc_to_map(h.loc());
@ -168,7 +168,18 @@ bool ast::parse_exp_int_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
return false;
}
bool ast::parse_exp_str_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
tree_helper_t h(ctx, res_i);
if (h.curr().is_str_literal()) {
auto &arr = out["content"].array({});
for (auto b : h.curr().literal()) arr.push_back((float)b);
out["location"] = conv::loc_to_map(h.loc());
return h.submit(true);
}
return false;
}
bool ast::parse_exp(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
tree_helper_t h(ctx, res_i);