feat: add string parser
This commit is contained in:
parent
90497f601d
commit
e755850c6f
@ -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) {
|
ast_ctx_t::ast_ctx_t(msg_stack_t &messages, std::vector<token_t> &tokens): messages(messages), tokens(tokens) {
|
||||||
group("$_exp_val")
|
group("$_exp_val")
|
||||||
.add_last("$_var", parse_exp_var)
|
.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("$_float", parse_exp_float_lit)
|
||||||
// .add_last("$_string", parse_exp_str_lit);
|
|
||||||
group("$_stat")
|
group("$_stat")
|
||||||
.add_last("$_exp", parse_stat_exp);
|
.add_last("$_exp", parse_stat_exp);
|
||||||
group("$_def")
|
group("$_def")
|
||||||
|
@ -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) {
|
bool ast::parse_exp_int_lit(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
|
||||||
tree_helper_t h(ctx, res_i);
|
tree_helper_t h(ctx, res_i);
|
||||||
|
|
||||||
if (h.curr().is_literal()) {
|
if (h.curr().is_int_literal()) {
|
||||||
auto &arr = out["content"].array({});
|
auto &arr = out["content"].array({});
|
||||||
for (auto b : h.curr().literal()) arr.push_back((float)b);
|
for (auto b : h.curr().literal()) arr.push_back((float)b);
|
||||||
out["location"] = conv::loc_to_map(h.loc());
|
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;
|
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) {
|
bool ast::parse_exp(ast_ctx_t &ctx, size_t &res_i, map_t &out) {
|
||||||
tree_helper_t h(ctx, res_i);
|
tree_helper_t h(ctx, res_i);
|
||||||
|
Loading…
Reference in New Issue
Block a user