diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-05-16 10:25:19 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-05-16 10:25:19 +0800 |
| commit | de91fff7af15ae9c4a27d34b5b9266f900412a29 (patch) | |
| tree | 9ececd242d326c8d5fec84043112782c95174b76 /src/yuescript/yue_compiler.cpp | |
| parent | a9fe6a5c4c17cf7e8305c1d614939ce510fb1103 (diff) | |
| download | yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.gz yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.tar.bz2 yuescript-de91fff7af15ae9c4a27d34b5b9266f900412a29.zip | |
fix issue #101 by supporting metamethod syntax in class block.
Diffstat (limited to '')
| -rwxr-xr-x | src/yuescript/yue_compiler.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
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 | ||
| 61 | typedef std::list<std::string> str_list; | 61 | typedef std::list<std::string> str_list; |
| 62 | 62 | ||
| 63 | const std::string_view version = "0.10.21"sv; | 63 | const std::string_view version = "0.10.22"sv; |
| 64 | const std::string_view extension = "yue"sv; | 64 | const std::string_view extension = "yue"sv; |
| 65 | 65 | ||
| 66 | class YueCompilerImpl { | 66 | class 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); |
