Skip to content

Commit 552c260

Browse files
committed
Fixed more error messages.
1 parent d745214 commit 552c260

7 files changed

Lines changed: 213 additions & 143 deletions

File tree

spec/inputs/import.yue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ do
2323
b, c from z
2424

2525
do
26-
import a
26+
import a,
2727
b
2828
c from z
2929

spec/inputs/unicode/import.yue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ do
2323
字段b, 字段c from 对象z
2424

2525
do
26-
import 字段a
26+
import 字段a,
2727
字段b
2828
字段c from 对象z
2929

src/yuescript/yue_ast.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ std::string Repeat_t::to_string(void* ud) const {
594594
std::string ForStepValue_t::to_string(void* ud) const {
595595
return value->to_string(ud);
596596
}
597-
std::string For_t::to_string(void* ud) const {
597+
std::string ForNum_t::to_string(void* ud) const {
598598
auto info = reinterpret_cast<YueFormat*>(ud);
599599
auto line = "for "s + varName->to_string(ud) + " = "s + startValue->to_string(ud) + ", "s + stopValue->to_string(ud);
600600
if (stepValue) {
@@ -633,6 +633,9 @@ std::string ForEach_t::to_string(void* ud) const {
633633
return line + '\n' + block;
634634
}
635635
}
636+
std::string For_t::to_string(void* ud) const {
637+
return forLoop->to_string(ud);
638+
}
636639
std::string Do_t::to_string(void* ud) const {
637640
auto info = reinterpret_cast<YueFormat*>(ud);
638641
if (body->content.is<Statement_t>()) {
@@ -784,7 +787,7 @@ static bool isInBlockExp(ast_node* node, bool last = false) {
784787
return false;
785788
}
786789
std::string Comprehension_t::to_string(void* ud) const {
787-
if (items.size() != 2 || !ast_is<CompInner_t>(items.back())) {
790+
if (items.size() != 2 || !ast_is<CompFor_t>(items.back())) {
788791
if (items.size() == 1) {
789792
str_list temp;
790793
for (const auto& item : items.objects()) {
@@ -851,14 +854,14 @@ std::string StarExp_t::to_string(void* ud) const {
851854
std::string CompForEach_t::to_string(void* ud) const {
852855
return "for "s + nameList->to_string(ud) + " in "s + loopValue->to_string(ud);
853856
}
854-
std::string CompFor_t::to_string(void* ud) const {
857+
std::string CompForNum_t::to_string(void* ud) const {
855858
auto line = "for "s + varName->to_string(ud) + " = "s + startValue->to_string(ud) + ", "s + stopValue->to_string(ud);
856859
if (stepValue) {
857860
line += stepValue->to_string(ud);
858861
}
859862
return line;
860863
}
861-
std::string CompInner_t::to_string(void* ud) const {
864+
std::string CompFor_t::to_string(void* ud) const {
862865
str_list temp;
863866
for (auto item : items.objects()) {
864867
if (ast_is<Exp_t>(item)) {

src/yuescript/yue_ast.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Statement_t;
6868
class Body_t;
6969
class AssignableNameList_t;
7070
class StarExp_t;
71-
class CompInner_t;
71+
class CompFor_t;
7272
class AssignableChain_t;
7373
class UnaryExp_t;
7474
class Parens_t;
@@ -358,14 +358,14 @@ AST_NODE(ForStepValue)
358358
AST_MEMBER(ForStepValue, &value)
359359
AST_END(ForStepValue)
360360

361-
AST_NODE(For)
361+
AST_NODE(ForNum)
362362
ast_ptr<true, Variable_t> varName;
363363
ast_ptr<true, Exp_t> startValue;
364364
ast_ptr<true, Exp_t> stopValue;
365365
ast_ptr<false, ForStepValue_t> stepValue;
366366
ast_sel<true, Block_t, Statement_t> body;
367-
AST_MEMBER(For, &varName, &startValue, &stopValue, &stepValue, &body)
368-
AST_END(For)
367+
AST_MEMBER(ForNum, &varName, &startValue, &stopValue, &stepValue, &body)
368+
AST_END(ForNum)
369369

370370
AST_NODE(ForEach)
371371
ast_ptr<true, AssignableNameList_t> nameList;
@@ -374,6 +374,11 @@ AST_NODE(ForEach)
374374
AST_MEMBER(ForEach, &nameList, &loopValue, &body)
375375
AST_END(ForEach)
376376

377+
AST_NODE(For)
378+
ast_sel<true, ForEach_t, ForNum_t> forLoop;
379+
AST_MEMBER(For, &forLoop)
380+
AST_END(For)
381+
377382
AST_NODE(Do)
378383
ast_ptr<true, Body_t> body;
379384
AST_MEMBER(Do, &body)
@@ -394,7 +399,7 @@ AST_END(Try)
394399

395400
AST_NODE(Comprehension)
396401
ast_ptr<true, Seperator_t> sep;
397-
ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompInner_t,
402+
ast_sel_list<false, NormalDef_t, SpreadListExp_t, CompFor_t,
398403
/*non-syntax-rule*/ Statement_t> items;
399404
AST_MEMBER(Comprehension, &sep, &items)
400405
AST_END(Comprehension)
@@ -407,7 +412,7 @@ AST_END(CompValue)
407412
AST_NODE(TblComprehension)
408413
ast_ptr<true, Exp_t> key;
409414
ast_ptr<false, CompValue_t> value;
410-
ast_ptr<true, CompInner_t> forLoop;
415+
ast_ptr<true, CompFor_t> forLoop;
411416
AST_MEMBER(TblComprehension, &key, &value, &forLoop)
412417
AST_END(TblComprehension)
413418

@@ -422,19 +427,19 @@ AST_NODE(CompForEach)
422427
AST_MEMBER(CompForEach, &nameList, &loopValue)
423428
AST_END(CompForEach)
424429

425-
AST_NODE(CompFor)
430+
AST_NODE(CompForNum)
426431
ast_ptr<true, Variable_t> varName;
427432
ast_ptr<true, Exp_t> startValue;
428433
ast_ptr<true, Exp_t> stopValue;
429434
ast_ptr<false, ForStepValue_t> stepValue;
430-
AST_MEMBER(CompFor, &varName, &startValue, &stopValue, &stepValue)
431-
AST_END(CompFor)
435+
AST_MEMBER(CompForNum, &varName, &startValue, &stopValue, &stepValue)
436+
AST_END(CompForNum)
432437

433-
AST_NODE(CompInner)
438+
AST_NODE(CompFor)
434439
ast_ptr<true, Seperator_t> sep;
435-
ast_sel_list<true, CompFor_t, CompForEach_t, Exp_t> items;
436-
AST_MEMBER(CompInner, &sep, &items)
437-
AST_END(CompInner)
440+
ast_sel_list<true, CompForNum_t, CompForEach_t, Exp_t> items;
441+
AST_MEMBER(CompFor, &sep, &items)
442+
AST_END(CompFor)
438443

439444
AST_NODE(Assign)
440445
ast_ptr<true, Seperator_t> sep;
@@ -553,7 +558,7 @@ AST_NODE(SimpleValue)
553558
ast_sel<true,
554559
TableLit_t, ConstValue_t,
555560
If_t, Switch_t, With_t, ClassDecl_t,
556-
ForEach_t, For_t, While_t, Repeat_t,
561+
For_t, While_t, Repeat_t,
557562
Do_t, Try_t, UnaryValue_t,
558563
TblComprehension_t, Comprehension_t,
559564
FunLit_t, Num_t, VarArg_t> value;
@@ -919,7 +924,7 @@ AST_NODE(PipeBody)
919924
AST_END(PipeBody)
920925

921926
AST_NODE(StatementAppendix)
922-
ast_sel<true, IfLine_t, WhileLine_t, CompInner_t> item;
927+
ast_sel<true, IfLine_t, WhileLine_t, CompFor_t> item;
923928
AST_MEMBER(StatementAppendix, &item)
924929
AST_END(StatementAppendix)
925930

@@ -949,7 +954,7 @@ AST_END(ChainAssign)
949954

950955
AST_NODE(Statement)
951956
ast_sel<true,
952-
Import_t, While_t, Repeat_t, For_t, ForEach_t,
957+
Import_t, While_t, Repeat_t, For_t,
953958
Return_t, Local_t, Global_t, Export_t, Macro_t, MacroInPlace_t,
954959
BreakLoop_t, Label_t, Goto_t, ShortTabAppending_t,
955960
Backcall_t, LocalAttrib_t, PipeBody_t, ExpListAssign_t, ChainAssign_t

0 commit comments

Comments
 (0)