Skip to content

Commit

Permalink
update Yuescript.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Oct 21, 2023
1 parent 2532763 commit af36caf
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 178 deletions.
2 changes: 1 addition & 1 deletion Assets/Script/Game/Touch the Sky/init.yue
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ addHeartUI = ->
loseHeart = ->
heart = heart - 1
heartNode\removeAllChildren!
heartSprite = if heart in [0, 3]
heartSprite = if 0 <= heart <= 3
Sprite "Image/heart_#{math.tointeger heart}.png"
else
Sprite "Image/heart_0.png"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Assets/Script/Lib/YarnRunner.yue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class YarnRunner
unless @option
return "Error", "there is no option to choose"
:title, :branches = @option
if choice not in [1, #branches]
if not (1 <= choice <= #branches)
return "Error", "choice #{choice} is out of range"
optionBranch = branches[choice]
@option = nil
Expand Down
27 changes: 15 additions & 12 deletions Source/3rdParty/yuescript/yue_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,6 @@ std::string ConstValue_t::to_string(void* ud) const {
auto info = reinterpret_cast<YueFormat*>(ud);
return info->convert(this);
}
std::string InRangeOpen_t::to_string(void*) const {
return {};
}
std::string InRangeClose_t::to_string(void*) const {
return {};
}
std::string NotIn_t::to_string(void*) const {
return {};
}
Expand Down Expand Up @@ -569,8 +563,18 @@ std::string Try_t::to_string(void* ud) const {
return join(temp, "\n"sv);
}
std::string Comprehension_t::to_string(void* ud) const {
auto valueStr = value->to_string(ud);
return '[' + (valueStr[0] == '[' ? " "s : ""s) + valueStr + ' ' + forLoop->to_string(ud) + ']';
str_list temp;
for (const auto& item : items.objects()) {
temp.push_back(item->to_string(ud));
}
if (temp.size() > 0) {
temp.front().insert(0, temp.front()[0] == '[' ? " "s : ""s);
}
if (items.size() != 2 || !ast_is<CompInner_t>(items.back())) {
return '[' + join(temp, ", "sv) + ']';
} else {
return '[' + join(temp, " "sv) + ']';
}
}
std::string CompValue_t::to_string(void* ud) const {
return value->to_string(ud);
Expand Down Expand Up @@ -830,6 +834,9 @@ std::string Invoke_t::to_string(void* ud) const {
std::string SpreadExp_t::to_string(void* ud) const {
return "..."s + exp->to_string(ud);
}
std::string SpreadListExp_t::to_string(void* ud) const {
return "..."s + exp->to_string(ud);
}
std::string TableLit_t::to_string(void* ud) const {
auto info = reinterpret_cast<YueFormat*>(ud);
if (values.empty()) {
Expand Down Expand Up @@ -1168,10 +1175,6 @@ std::string UnaryExp_t::to_string(void* ud) const {
}
return line;
}
std::string InRange_t::to_string(void* ud) const {
auto valueStr = openValue->to_string(ud);
return (open.is<InRangeOpen_t>() ? "("s : "["s + (valueStr[0] == '[' ? " "s : ""s)) + valueStr + ", "s + closeValue->to_string(ud) + (close.is<InRangeOpen_t>() ? ')' : ']');
}
std::string InDiscrete_t::to_string(void* ud) const {
str_list temp;
for (auto value : values.objects()) {
Expand Down
34 changes: 14 additions & 20 deletions Source/3rdParty/yuescript/yue_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class InvokeArgs_t;
class TableBlockIndent_t;
class Macro_t;
class In_t;
class NormalDef_t;
class SpreadListExp_t;
} // namespace yue

AST_LEAF(Num)
Expand Down Expand Up @@ -286,7 +288,7 @@ AST_NODE(SwitchList)
AST_END(SwitchList, "switch_list"sv)

AST_NODE(SwitchCase)
ast_sel<true, SwitchList_t, In_t> condition;
ast_ptr<true, SwitchList_t> condition;
ast_sel<true, Block_t, Statement_t> body;
AST_MEMBER(SwitchCase, &condition, &body)
AST_END(SwitchCase, "switch_case"sv)
Expand Down Expand Up @@ -374,9 +376,10 @@ AST_NODE(Try)
AST_END(Try, "try"sv)

AST_NODE(Comprehension)
ast_sel<true, Exp_t, /*non-syntax-rule*/ Statement_t> value;
ast_ptr<true, CompInner_t> forLoop;
AST_MEMBER(Comprehension, &value, &forLoop)
ast_ptr<true, Seperator_t> sep;
ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t,
/*non-syntax-rule*/ Statement_t> items;
AST_MEMBER(Comprehension, &sep, &items)
AST_END(Comprehension, "comp"sv)

AST_NODE(CompValue)
Expand Down Expand Up @@ -437,23 +440,9 @@ AST_END(BinaryOperator, "binary_op"sv)
AST_LEAF(UnaryOperator)
AST_END(UnaryOperator, "unary_op"sv)

AST_LEAF(InRangeOpen)
AST_END(InRangeOpen, "in_range_open"sv)

AST_LEAF(InRangeClose)
AST_END(InRangeClose, "in_range_close"sv)

AST_LEAF(NotIn)
AST_END(NotIn, "not_in"sv)

AST_NODE(InRange)
ast_sel<true, InRangeOpen_t, InRangeClose_t> open;
ast_ptr<true, Exp_t> openValue;
ast_ptr<true, Exp_t> closeValue;
ast_sel<true, InRangeOpen_t, InRangeClose_t> close;
AST_MEMBER(InRange, &open, &openValue, &closeValue, &close)
AST_END(InRange, "in_range"sv)

AST_NODE(InDiscrete)
ast_ptr<true, Seperator_t> sep;
ast_list<true, Exp_t> values;
Expand All @@ -462,7 +451,7 @@ AST_END(InDiscrete, "in_discrete"sv)

AST_NODE(In)
ast_ptr<false, NotIn_t> not_;
ast_sel<true, InRange_t, InDiscrete_t, Exp_t> item;
ast_sel<true, InDiscrete_t, Exp_t> item;
AST_MEMBER(In, &not_, &item)
AST_END(In, "in"sv)

Expand Down Expand Up @@ -666,14 +655,19 @@ AST_NODE(SpreadExp)
AST_MEMBER(SpreadExp, &exp)
AST_END(SpreadExp, "spread_exp"sv)

AST_NODE(SpreadListExp)
ast_ptr<true, Exp_t> exp;
AST_MEMBER(SpreadListExp, &exp)
AST_END(SpreadListExp, "spread_list_exp"sv)

AST_NODE(TableLit)
ast_ptr<true, Seperator_t> sep;
ast_sel_list<false,
VariablePairDef_t, NormalPairDef_t, SpreadExp_t, NormalDef_t,
MetaVariablePairDef_t, MetaNormalPairDef_t,
VariablePair_t, NormalPair_t, Exp_t,
MetaVariablePair_t, MetaNormalPair_t,
/*non-syntax-rule*/ TableBlockIndent_t> values;
/*non-syntax-rule*/ TableBlockIndent_t, SpreadListExp_t> values;
AST_MEMBER(TableLit, &sep, &values)
AST_END(TableLit, "table_lit"sv)

Expand Down
Loading

0 comments on commit af36caf

Please sign in to comment.