aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2022-05-16 10:25:19 +0800
committerLi Jin <dragon-fly@qq.com>2022-05-16 10:25:19 +0800
commitde91fff7af15ae9c4a27d34b5b9266f900412a29 (patch)
tree9ececd242d326c8d5fec84043112782c95174b76 /src
parenta9fe6a5c4c17cf7e8305c1d614939ce510fb1103 (diff)
downloadyuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.gz
yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.bz2
yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.zip
fix issue #101 by supporting metamethod syntax in class block.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/yuescript/yue_ast.h2
-rwxr-xr-xsrc/yuescript/yue_compiler.cpp26
2 files changed, 26 insertions, 2 deletions
diff --git a/src/yuescript/yue_ast.h b/src/yuescript/yue_ast.h
index d255236..38e97ad 100755
--- a/src/yuescript/yue_ast.h
+++ b/src/yuescript/yue_ast.h
@@ -639,7 +639,7 @@ AST_END(TableBlock, "table_block"sv)
639 639
640AST_NODE(class_member_list) 640AST_NODE(class_member_list)
641 ast_ptr<true, Seperator_t> sep; 641 ast_ptr<true, Seperator_t> sep;
642 ast_sel_list<true, variable_pair_t, normal_pair_t> values; 642 ast_sel_list<true, variable_pair_t, normal_pair_t, meta_variable_pair_t, meta_normal_pair_t> values;
643 AST_MEMBER(class_member_list, &sep, &values) 643 AST_MEMBER(class_member_list, &sep, &values)
644AST_END(class_member_list, "class_member_list"sv) 644AST_END(class_member_list, "class_member_list"sv)
645 645
diff --git a/src/yuescript/yue_compiler.cpp b/src/yuescript/yue_compiler.cpp
index 6d90d24..51ece7c 100755
--- a/src/yuescript/yue_compiler.cpp
+++ b/src/yuescript/yue_compiler.cpp
@@ -60,7 +60,7 @@ using namespace parserlib;
60 60
61typedef std::list<std::string> str_list; 61typedef std::list<std::string> str_list;
62 62
63const std::string_view version = "0.10.21"sv; 63const std::string_view version = "0.10.22"sv;
64const std::string_view extension = "yue"sv; 64const std::string_view extension = "yue"sv;
65 65
66class YueCompilerImpl { 66class YueCompilerImpl {
@@ -5985,6 +5985,30 @@ private:
5985 size_t count = 0; 5985 size_t count = 0;
5986 for (auto keyValue : class_member_list->values.objects()) { 5986 for (auto keyValue : class_member_list->values.objects()) {
5987 MemType type = MemType::Common; 5987 MemType type = MemType::Common;
5988 ast_ptr<false, ast_node> ref;
5989 switch (keyValue->getId()) {
5990 case id<meta_variable_pair_t>(): {
5991 auto mtPair = static_cast<meta_variable_pair_t*>(keyValue);
5992 auto nameStr = _parser.toString(mtPair->name);
5993 ref.set(toAst<normal_pair_t>("__"s + nameStr + ':' + nameStr, keyValue));
5994 keyValue = ref.get();
5995 break;
5996 }
5997 case id<meta_normal_pair_t>(): {
5998 auto mtPair = static_cast<meta_normal_pair_t*>(keyValue);
5999 auto normal_pair = keyValue->new_ptr<normal_pair_t>();
6000 if (auto name = mtPair->key.as<Name_t>()) {
6001 auto nameStr = _parser.toString(name);
6002 normal_pair->key.set(toAst<KeyName_t>("__"s + nameStr, keyValue));
6003 } else {
6004 normal_pair->key.set(mtPair->key);
6005 }
6006 normal_pair->value.set(mtPair->value);
6007 ref.set(normal_pair);
6008 keyValue = ref.get();
6009 break;
6010 }
6011 }
5988 BLOCK_START 6012 BLOCK_START
5989 auto normal_pair = ast_cast<normal_pair_t>(keyValue); 6013 auto normal_pair = ast_cast<normal_pair_t>(keyValue);
5990 BREAK_IF(!normal_pair); 6014 BREAK_IF(!normal_pair);