| 1220 | } |
| 1221 | |
| 1222 | ParserFunctor *ParserContext::generate_glua_parser() |
| 1223 | { |
| 1224 | auto *ctx = this; |
| 1225 | auto l = [&](std::string t) { |
| 1226 | return ctx->literal(t); |
| 1227 | }; |
| 1228 | auto n = [&](std::string name) { |
| 1229 | return ctx->named_parser(name); |
| 1230 | }; |
| 1231 | auto s = l; |
| 1232 | auto str_parser = ctx->string_parser(); |
| 1233 | std::vector<glua::parser::ParserFunctor*> expr1_stru = { ctx->lua_symbol_parser(), l("("), str_parser, l(")") }; |
| 1234 | glua::parser::ParserFunctor *expr_parser1 = ctx->concat_parsers(expr1_stru); |
| 1235 | std::vector<ParserFunctor*> unops = { l("-"), l("not"), l("#"), l("~") }; |
| 1236 | ctx->cache("unop", ctx->union_parsers(unops)); |
| 1237 | std::vector<ParserFunctor*> binops = { l("+"), l("-"), l("*"), l("/"), l("//"), l("^"), |
| 1238 | l("%"), l("&"), l("~"), l("|"), l(">>"), l("<<"), l(".."), l("<="), |
| 1239 | l("<"), l(">="), l(">"), l("=="), l("~="), l("and"), l("or") }; |
| 1240 | ctx->cache("binop", ctx->union_parsers(binops)); |
| 1241 | ctx->cache("fieldsep", ctx->p_or(s(","), s(";"))); |
| 1242 | ctx->cache("field", ctx->p_or( |
| 1243 | ctx->p_and(s("["), n("exp"), s("]"), s("="), n("exp"))->as("array_index_field"), |
| 1244 | ctx->p_and(ctx->lua_symbol_parser(), ctx->p_or(s("="), s(":")), n("exp"))->as("map_index_field"), |
| 1245 | ctx->p_and(ctx->string_parser(), s(":"), n("exp"))->as("string_map_index_field"), |
| 1246 | n("exp") |
| 1247 | )); |
| 1248 | ctx->cache("var_declare_prefix", ctx->p_or( |
| 1249 | s("local"), |
| 1250 | s("var"), |
| 1251 | s("let") |
| 1252 | )); |
| 1253 | ctx->cache("fieldlist", |
| 1254 | ctx->repeatPlus(ctx->p_and(n("field"), ctx->optional_parser(n("fieldsep")))->as("fieldsep_value_pair"))); |
| 1255 | ctx->cache("tableconstructor", |
| 1256 | ctx->p_or( |
| 1257 | ctx->p_and(s("{"), s("}")), |
| 1258 | ctx->p_and(s("{"), n("fieldlist"), s("}")), |
| 1259 | ctx->p_and(s("["), s("]")), |
| 1260 | ctx->p_and(s("["), n("fieldlist"), s("]")) |
| 1261 | )); |
| 1262 | ctx->cache("parlist", |
| 1263 | ctx->p_or(s("..."), ctx->p_and(n("namelist"), ctx->optional_parser(ctx->p_and(s(","), s("...")))))); |
| 1264 | ctx->cache("funcbody_args_def", |
| 1265 | ctx->p_and(s("("), ctx->optional_parser(n("parlist")), s(")"))); |
| 1266 | ctx->cache("funcbody", |
| 1267 | ctx->p_and(n("funcbody_args_def"), n("block"), s("end"))); |
| 1268 | ctx->cache("functiondef", |
| 1269 | ctx->p_and(s("function"), n("funcbody"))); |
| 1270 | ctx->cache("un_exp", ctx-> p_and(n("unop"), n("simpleexp"))->set_items_in_same_line()); |
| 1271 | ctx->cache("simpleexp", |
| 1272 | ctx->p_or( |
| 1273 | s("nil"), s("false"), s("true"), |
| 1274 | s("..."), n("functiondef"), |
| 1275 | ctx->number_parser(), ctx->string_parser(), |
| 1276 | n("un_exp"), |
| 1277 | // n("prefixexp"), // 后面要紧跟着bin_exp的下半部分 |
| 1278 | n("functioncall"), |
| 1279 | n("suffixedexp"), n("prefixexp"), n("tableconstructor"), |
no test coverage detected