diff options
Diffstat (limited to '')
| -rw-r--r-- | MoonParser/moon_ast.cpp | 129 | ||||
| -rw-r--r-- | MoonParser/moon_parser.cpp | 96 |
2 files changed, 130 insertions, 95 deletions
diff --git a/MoonParser/moon_ast.cpp b/MoonParser/moon_ast.cpp index fcbaa90..fa95097 100644 --- a/MoonParser/moon_ast.cpp +++ b/MoonParser/moon_ast.cpp | |||
| @@ -11,10 +11,8 @@ | |||
| 11 | using namespace std::string_view_literals; | 11 | using namespace std::string_view_literals; |
| 12 | #include "moon_ast.h" | 12 | #include "moon_ast.h" |
| 13 | 13 | ||
| 14 | const input& AstLeaf::getValue() | 14 | const input& AstLeaf::getValue() { |
| 15 | { | 15 | if (_value.empty()) { |
| 16 | if (_value.empty()) | ||
| 17 | { | ||
| 18 | _value.assign(m_begin.m_it, m_end.m_it); | 16 | _value.assign(m_begin.m_it, m_end.m_it); |
| 19 | return trim(_value); | 17 | return trim(_value); |
| 20 | } | 18 | } |
| @@ -289,13 +287,11 @@ private: | |||
| 289 | } | 287 | } |
| 290 | 288 | ||
| 291 | std::string toString(ast_node* node) { | 289 | std::string toString(ast_node* node) { |
| 292 | auto str = _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); | 290 | return _converter.to_bytes(std::wstring(node->m_begin.m_it, node->m_end.m_it)); |
| 293 | return trim(str); | ||
| 294 | } | 291 | } |
| 295 | 292 | ||
| 296 | std::string toString(input::iterator begin, input::iterator end) { | 293 | std::string toString(input::iterator begin, input::iterator end) { |
| 297 | auto str = _converter.to_bytes(std::wstring(begin, end)); | 294 | return _converter.to_bytes(std::wstring(begin, end)); |
| 298 | return trim(str); | ||
| 299 | } | 295 | } |
| 300 | 296 | ||
| 301 | void noop(ast_node* node, std::vector<std::string>& out) { | 297 | void noop(ast_node* node, std::vector<std::string>& out) { |
| @@ -396,25 +392,25 @@ private: | |||
| 396 | default: break; | 392 | default: break; |
| 397 | } | 393 | } |
| 398 | } | 394 | } |
| 399 | auto node = statement->content.get(); | 395 | auto content = statement->content.get(); |
| 400 | if (!node) { | 396 | if (!content) { |
| 401 | out.push_back(Empty); | 397 | out.push_back(Empty); |
| 402 | return; | 398 | return; |
| 403 | } | 399 | } |
| 404 | switch (node->getId()) { | 400 | switch (content->getId()) { |
| 405 | case "Import"_id: transformImport(node, out); break; | 401 | case "Import"_id: transformImport(content, out); break; |
| 406 | case "While"_id: transformWhile(node, out); break; | 402 | case "While"_id: transformWhile(content, out); break; |
| 407 | case "With"_id: transformWith(node, out); break; | 403 | case "With"_id: transformWith(content, out); break; |
| 408 | case "For"_id: transformFor(static_cast<For_t*>(node), out); break; | 404 | case "For"_id: transformFor(static_cast<For_t*>(content), out); break; |
| 409 | case "ForEach"_id: transformForEach(static_cast<ForEach_t*>(node), out); break; | 405 | case "ForEach"_id: transformForEach(static_cast<ForEach_t*>(content), out); break; |
| 410 | case "Switch"_id: transformSwitch(node, out); break; | 406 | case "Switch"_id: transformSwitch(content, out); break; |
| 411 | case "Return"_id: transformReturn(static_cast<Return_t*>(node), out); break; | 407 | case "Return"_id: transformReturn(static_cast<Return_t*>(content), out); break; |
| 412 | case "Local"_id: transformLocal(node, out); break; | 408 | case "Local"_id: transformLocal(content, out); break; |
| 413 | case "Export"_id: transformExport(node, out); break; | 409 | case "Export"_id: transformExport(content, out); break; |
| 414 | case "BreakLoop"_id: transformBreakLoop(node, out); break; | 410 | case "BreakLoop"_id: transformBreakLoop(content, out); break; |
| 415 | case "Assignment"_id: transformStatementAssign(statement, out); break; | 411 | case "Assignment"_id: transformStatementAssign(statement, out); break; |
| 416 | case "ExpList"_id: { | 412 | case "ExpList"_id: { |
| 417 | auto expList = static_cast<ExpList_t*>(node); | 413 | auto expList = static_cast<ExpList_t*>(content); |
| 418 | if (expList->exprs.objects().empty()) { | 414 | if (expList->exprs.objects().empty()) { |
| 419 | out.push_back(Empty); | 415 | out.push_back(Empty); |
| 420 | break; | 416 | break; |
| @@ -740,23 +736,23 @@ private: | |||
| 740 | } | 736 | } |
| 741 | 737 | ||
| 742 | void transformSimpleValue(SimpleValue_t* simpleValue, std::vector<std::string>& out) { | 738 | void transformSimpleValue(SimpleValue_t* simpleValue, std::vector<std::string>& out) { |
| 743 | auto node = simpleValue->value.get(); | 739 | auto value = simpleValue->value.get(); |
| 744 | switch (node->getId()) { | 740 | switch (value->getId()) { |
| 745 | case "const_value"_id: transform_const_value(node, out); break; | 741 | case "const_value"_id: transform_const_value(value, out); break; |
| 746 | case "If"_id: transformIfClosure(static_cast<If_t*>(node), out); break; | 742 | case "If"_id: transformIfClosure(static_cast<If_t*>(value), out); break; |
| 747 | case "Switch"_id: transformSwitch(node, out); break; | 743 | case "Switch"_id: transformSwitch(value, out); break; |
| 748 | case "With"_id: transformWith(node, out); break; | 744 | case "With"_id: transformWith(value, out); break; |
| 749 | case "ClassDecl"_id: transformClassDecl(node, out); break; | 745 | case "ClassDecl"_id: transformClassDecl(static_cast<ClassDecl_t*>(value), out); break; |
| 750 | case "ForEach"_id: transformForEachClosure(static_cast<ForEach_t*>(node), out); break; | 746 | case "ForEach"_id: transformForEachClosure(static_cast<ForEach_t*>(value), out); break; |
| 751 | case "For"_id: transformForClosure(static_cast<For_t*>(node), out); break; | 747 | case "For"_id: transformForClosure(static_cast<For_t*>(value), out); break; |
| 752 | case "While"_id: transformWhile(node, out); break; | 748 | case "While"_id: transformWhile(value, out); break; |
| 753 | case "Do"_id: transformDo(node, out); break; | 749 | case "Do"_id: transformDo(value, out); break; |
| 754 | case "unary_exp"_id: transform_unary_exp(static_cast<unary_exp_t*>(node), out); break; | 750 | case "unary_exp"_id: transform_unary_exp(static_cast<unary_exp_t*>(value), out); break; |
| 755 | case "TblComprehension"_id: transformTblComprehension(node, out); break; | 751 | case "TblComprehension"_id: transformTblComprehension(value, out); break; |
| 756 | case "TableLit"_id: transformTableLit(static_cast<TableLit_t*>(node), out); break; | 752 | case "TableLit"_id: transformTableLit(static_cast<TableLit_t*>(value), out); break; |
| 757 | case "Comprehension"_id: transformComprehension(static_cast<Comprehension_t*>(node), out); break; | 753 | case "Comprehension"_id: transformComprehension(static_cast<Comprehension_t*>(value), out); break; |
| 758 | case "FunLit"_id: transformFunLit(static_cast<FunLit_t*>(node), out); break; | 754 | case "FunLit"_id: transformFunLit(static_cast<FunLit_t*>(value), out); break; |
| 759 | case "Num"_id: transformNum(static_cast<Num_t*>(node), out); break; | 755 | case "Num"_id: transformNum(static_cast<Num_t*>(value), out); break; |
| 760 | default: break; | 756 | default: break; |
| 761 | } | 757 | } |
| 762 | } | 758 | } |
| @@ -1020,6 +1016,7 @@ private: | |||
| 1020 | case "LuaString"_id: transformLuaString(static_cast<LuaString_t*>(argument), out); break; | 1016 | case "LuaString"_id: transformLuaString(static_cast<LuaString_t*>(argument), out); break; |
| 1021 | default: break; | 1017 | default: break; |
| 1022 | } | 1018 | } |
| 1019 | out.back() = s("("sv) + out.back() + s(")"sv); | ||
| 1023 | } | 1020 | } |
| 1024 | 1021 | ||
| 1025 | void transformFnArgs(FnArgs_t* fnArgs, std::vector<std::string>& out) { | 1022 | void transformFnArgs(FnArgs_t* fnArgs, std::vector<std::string>& out) { |
| @@ -1028,7 +1025,7 @@ private: | |||
| 1028 | transformExp(static_cast<Exp_t*>(node), temp); | 1025 | transformExp(static_cast<Exp_t*>(node), temp); |
| 1029 | } | 1026 | } |
| 1030 | std::string args = join(temp, ", "sv); | 1027 | std::string args = join(temp, ", "sv); |
| 1031 | out.push_back(args.empty() ? s("()"sv) : s("("sv) + args + s(")"sv)); | 1028 | out.push_back(args); |
| 1032 | } | 1029 | } |
| 1033 | 1030 | ||
| 1034 | void transformColonChain(ColonChain_t* colonChain, std::vector<std::string>& out) { | 1031 | void transformColonChain(ColonChain_t* colonChain, std::vector<std::string>& out) { |
| @@ -1211,13 +1208,14 @@ private: | |||
| 1211 | 1208 | ||
| 1212 | void transformAssignableNameList(AssignableNameList_t* nameList, std::vector<std::string>& out) { | 1209 | void transformAssignableNameList(AssignableNameList_t* nameList, std::vector<std::string>& out) { |
| 1213 | std::vector<std::string> temp; | 1210 | std::vector<std::string> temp; |
| 1214 | for (auto node : nameList->items.objects()) { | 1211 | for (auto _item : nameList->items.objects()) { |
| 1215 | switch (node->getId()) { | 1212 | auto item = static_cast<NameOrDestructure_t*>(_item)->item.get(); |
| 1213 | switch (item->getId()) { | ||
| 1216 | case "Name"_id: | 1214 | case "Name"_id: |
| 1217 | transformName(static_cast<Name_t*>(node), temp); | 1215 | transformName(static_cast<Name_t*>(item), temp); |
| 1218 | break; | 1216 | break; |
| 1219 | case "TableLit"_id: | 1217 | case "TableLit"_id: |
| 1220 | transformTableLit(static_cast<TableLit_t*>(node), temp); | 1218 | transformTableLit(static_cast<TableLit_t*>(item), temp); |
| 1221 | break; | 1219 | break; |
| 1222 | default: break; | 1220 | default: break; |
| 1223 | } | 1221 | } |
| @@ -1506,6 +1504,48 @@ private: | |||
| 1506 | } | 1504 | } |
| 1507 | } | 1505 | } |
| 1508 | 1506 | ||
| 1507 | void transformClassDecl(ClassDecl_t* classDecl, std::vector<std::string>& out) { | ||
| 1508 | std::vector<std::string> temp; | ||
| 1509 | if (classDecl->name) { | ||
| 1510 | transformAssignable(classDecl->name, temp); | ||
| 1511 | } | ||
| 1512 | if (classDecl->extend) { | ||
| 1513 | transformExp(classDecl->extend, temp); | ||
| 1514 | } | ||
| 1515 | if (classDecl->body) { | ||
| 1516 | transformClassBlock(classDecl->body, temp); | ||
| 1517 | } | ||
| 1518 | out.push_back(join(temp, "\n"sv)); | ||
| 1519 | } | ||
| 1520 | |||
| 1521 | void transformClassBlock(ClassBlock_t* classBlock, std::vector<std::string>& out) { | ||
| 1522 | std::vector<std::string> temp; | ||
| 1523 | for (auto _line : classBlock->lines.objects()) { | ||
| 1524 | auto line = static_cast<ClassLine_t*>(_line); | ||
| 1525 | transformClassLine(line, temp); | ||
| 1526 | } | ||
| 1527 | out.push_back(join(temp,"\n"sv)); | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | void transformClassLine(ClassLine_t* classLine, std::vector<std::string>& out) { | ||
| 1531 | auto content = classLine->content.get(); | ||
| 1532 | switch (content->getId()) { | ||
| 1533 | case "class_member_list"_id: | ||
| 1534 | transform_class_member_list(static_cast<class_member_list_t*>(content), out); | ||
| 1535 | break; | ||
| 1536 | case "Statement"_id: | ||
| 1537 | transformStatement(static_cast<Statement_t*>(content), out); | ||
| 1538 | break; | ||
| 1539 | case "Exp"_id: | ||
| 1540 | transformExp(static_cast<Exp_t*>(content), out); | ||
| 1541 | break; | ||
| 1542 | } | ||
| 1543 | } | ||
| 1544 | |||
| 1545 | void transform_class_member_list(class_member_list_t* class_member_list, std::vector<std::string>& out) {noop(class_member_list, out);} | ||
| 1546 | |||
| 1547 | void transformAssignable(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | ||
| 1548 | |||
| 1509 | void transformUpdate(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1549 | void transformUpdate(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1510 | void transformImport(ast_node* node, std::vector<std::string>& out) {noopnl(node, out);} | 1550 | void transformImport(ast_node* node, std::vector<std::string>& out) {noopnl(node, out);} |
| 1511 | void transformWhile(ast_node* node, std::vector<std::string>& out) {noopnl(node, out);} | 1551 | void transformWhile(ast_node* node, std::vector<std::string>& out) {noopnl(node, out);} |
| @@ -1518,7 +1558,6 @@ private: | |||
| 1518 | void transform_unless_line(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1558 | void transform_unless_line(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1519 | void transform_simple_table(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1559 | void transform_simple_table(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1520 | void transform_const_value(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1560 | void transform_const_value(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1521 | void transformClassDecl(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | ||
| 1522 | void transformDo(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1561 | void transformDo(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1523 | void transformTblComprehension(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1562 | void transformTblComprehension(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
| 1524 | void transform_chain_dot_chain(ast_node* node, std::vector<std::string>& out) {noop(node, out);} | 1563 | void transform_chain_dot_chain(ast_node* node, std::vector<std::string>& out) {noop(node, out);} |
diff --git a/MoonParser/moon_parser.cpp b/MoonParser/moon_parser.cpp index ae8c53d..3009ee5 100644 --- a/MoonParser/moon_parser.cpp +++ b/MoonParser/moon_parser.cpp | |||
| @@ -43,10 +43,8 @@ rule Seperator = true_(); | |||
| 43 | #define symx(str) expr(str) | 43 | #define symx(str) expr(str) |
| 44 | #define ensure(patt, finally) (((patt) >> (finally)) | ((finally) >> (Cut))) | 44 | #define ensure(patt, finally) (((patt) >> (finally)) | ((finally) >> (Cut))) |
| 45 | #define key(str) (Space >> str >> not_(AlphaNum)) | 45 | #define key(str) (Space >> str >> not_(AlphaNum)) |
| 46 | #define opWord(str) (Space >> str >> not_(AlphaNum)) | ||
| 47 | #define op(str) (Space >> str) | ||
| 48 | 46 | ||
| 49 | rule Name = user(SpaceName, [](const item_t& item) | 47 | rule Name = user(_Name, [](const item_t& item) |
| 50 | { | 48 | { |
| 51 | State* st = reinterpret_cast<State*>(item.user_data); | 49 | State* st = reinterpret_cast<State*>(item.user_data); |
| 52 | for (auto it = item.begin; it != item.end; ++it) st->buffer << static_cast<char>(*it); | 50 | for (auto it = item.begin; it != item.end; ++it) st->buffer << static_cast<char>(*it); |
| @@ -142,11 +140,11 @@ rule InBlock = Advance >> Block >> PopIndent; | |||
| 142 | 140 | ||
| 143 | extern rule NameList; | 141 | extern rule NameList; |
| 144 | 142 | ||
| 145 | rule local_flag = op('*') | op('^'); | 143 | rule local_flag = expr('*') | expr('^'); |
| 146 | rule Local = key("local") >> (local_flag | NameList); | 144 | rule Local = key("local") >> ((Space >> local_flag) | NameList); |
| 147 | 145 | ||
| 148 | rule colon_import_name = sym('\\') >> Name; | 146 | rule colon_import_name = sym('\\') >> Space >> Name; |
| 149 | rule ImportName = colon_import_name | Name; | 147 | rule ImportName = colon_import_name | Space >> Name; |
| 150 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); | 148 | rule ImportNameList = Seperator >> *SpaceBreak >> ImportName >> *((+SpaceBreak | sym(',') >> *SpaceBreak) >> ImportName); |
| 151 | 149 | ||
| 152 | extern rule Exp; | 150 | extern rule Exp; |
| @@ -185,7 +183,7 @@ rule Unless = key("unless") >> IfCond >> -key("then") >> Body >> Seperator >> *I | |||
| 185 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; | 183 | rule While = key("while") >> DisableDo >> ensure(Exp, PopDo) >> -key("do") >> Body; |
| 186 | 184 | ||
| 187 | rule for_step_value = sym(',') >> Exp; | 185 | rule for_step_value = sym(',') >> Exp; |
| 188 | rule for_args = Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; | 186 | rule for_args = Space >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; |
| 189 | 187 | ||
| 190 | rule For = key("for") >> DisableDo >> | 188 | rule For = key("for") >> DisableDo >> |
| 191 | ensure(for_args, PopDo) >> | 189 | ensure(for_args, PopDo) >> |
| @@ -232,7 +230,7 @@ extern rule CompForEach, CompFor, CompClause; | |||
| 232 | rule CompInner = (CompForEach | CompFor) >> Seperator >> *CompClause; | 230 | rule CompInner = (CompForEach | CompFor) >> Seperator >> *CompClause; |
| 233 | rule star_exp = sym('*') >> Exp; | 231 | rule star_exp = sym('*') >> Exp; |
| 234 | rule CompForEach = key("for") >> AssignableNameList >> key("in") >> (star_exp | Exp); | 232 | rule CompForEach = key("for") >> AssignableNameList >> key("in") >> (star_exp | Exp); |
| 235 | rule CompFor = key("for") >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; | 233 | rule CompFor = key("for") >> Space >> Name >> sym('=') >> Exp >> sym(',') >> Exp >> -for_step_value; |
| 236 | rule CompClause = CompFor | CompForEach | key("when") >> Exp; | 234 | rule CompClause = CompFor | CompForEach | key("when") >> Exp; |
| 237 | 235 | ||
| 238 | extern rule TableBlock; | 236 | extern rule TableBlock; |
| @@ -240,44 +238,42 @@ extern rule TableBlock; | |||
| 240 | rule Assign = sym('=') >> (With | If | Switch | TableBlock | ExpListLow); | 238 | rule Assign = sym('=') >> (With | If | Switch | TableBlock | ExpListLow); |
| 241 | 239 | ||
| 242 | rule update_op = | 240 | rule update_op = |
| 243 | sym("..=") | | 241 | expr("..=") | |
| 244 | sym("+=") | | 242 | expr("+=") | |
| 245 | sym("-=") | | 243 | expr("-=") | |
| 246 | sym("*=") | | 244 | expr("*=") | |
| 247 | sym("/=") | | 245 | expr("/=") | |
| 248 | sym("%=") | | 246 | expr("%=") | |
| 249 | sym("or=") | | 247 | expr("or=") | |
| 250 | sym("and=") | | 248 | expr("and=") | |
| 251 | sym("&=") | | 249 | expr("&=") | |
| 252 | sym("|=") | | 250 | expr("|=") | |
| 253 | sym(">>=") | | 251 | expr(">>=") | |
| 254 | sym("<<="); | 252 | expr("<<="); |
| 255 | 253 | ||
| 256 | rule Update = update_op >> Exp; | 254 | rule Update = Space >> update_op >> Exp; |
| 257 | 255 | ||
| 258 | rule CharOperators = Space >> set("+-*/%^><|&"); | 256 | rule BinaryOperator = |
| 259 | rule WordOperators = | 257 | (expr("or") >> not_(AlphaNum)) | |
| 260 | opWord("or") | | 258 | (expr("and") >> not_(AlphaNum)) | |
| 261 | opWord("and") | | 259 | expr("<=") | |
| 262 | op("<=") | | 260 | expr(">=") | |
| 263 | op(">=") | | 261 | expr("~=") | |
| 264 | op("~=") | | 262 | expr("!=") | |
| 265 | op("!=") | | 263 | expr("==") | |
| 266 | op("==") | | 264 | expr("..") | |
| 267 | op("..") | | 265 | expr("<<") | |
| 268 | op("<<") | | 266 | expr(">>") | |
| 269 | op(">>") | | 267 | expr("//") | |
| 270 | op("//"); | 268 | set("+-*/%^><|&"); |
| 271 | |||
| 272 | rule BinaryOperator = (WordOperators | CharOperators) >> *SpaceBreak; | ||
| 273 | 269 | ||
| 274 | extern rule Chain; | 270 | extern rule Chain; |
| 275 | 271 | ||
| 276 | rule Assignable = Chain | Name | SelfName; | 272 | rule Assignable = Chain | Space >> Name | SelfName; |
| 277 | 273 | ||
| 278 | extern rule Value; | 274 | extern rule Value; |
| 279 | 275 | ||
| 280 | rule exp_op_value = BinaryOperator >> Value; | 276 | rule exp_op_value = Space >> BinaryOperator >> *SpaceBreak >> Value; |
| 281 | rule Exp = Value >> *exp_op_value; | 277 | rule Exp = Value >> *exp_op_value; |
| 282 | 278 | ||
| 283 | extern rule Callable, InvokeArgs; | 279 | extern rule Callable, InvokeArgs; |
| @@ -328,7 +324,7 @@ rule LuaString = user(LuaStringOpen >> -Break >> LuaStringContent >> LuaStringCl | |||
| 328 | }); | 324 | }); |
| 329 | 325 | ||
| 330 | rule Parens = sym('(') >> *SpaceBreak >> Exp >> *SpaceBreak >> sym(')'); | 326 | rule Parens = sym('(') >> *SpaceBreak >> Exp >> *SpaceBreak >> sym(')'); |
| 331 | rule Callable = Name | SelfName | VarArg | Parens; | 327 | rule Callable = Space >> Name | SelfName | VarArg | Parens; |
| 332 | rule FnArgsExpList = Exp >> *((Break | sym(',')) >> White >> Exp); | 328 | rule FnArgsExpList = Exp >> *((Break | sym(',')) >> White >> Exp); |
| 333 | 329 | ||
| 334 | rule FnArgs = Seperator >> | 330 | rule FnArgs = Seperator >> |
| @@ -420,10 +416,10 @@ rule ClassDecl = | |||
| 420 | -ClassBlock; | 416 | -ClassBlock; |
| 421 | 417 | ||
| 422 | rule export_values = NameList >> -(sym('=') >> ExpListLow); | 418 | rule export_values = NameList >> -(sym('=') >> ExpListLow); |
| 423 | rule export_op = op('*') | op('^'); | 419 | rule export_op = expr('*') | expr('^'); |
| 424 | rule Export = key("export") >> (ClassDecl | export_op | export_values); | 420 | rule Export = key("export") >> (ClassDecl | (Space >> export_op) | export_values); |
| 425 | 421 | ||
| 426 | rule variable_pair = sym(':') >> not_(SomeSpace) >> Name; | 422 | rule variable_pair = sym(':') >> not_(SomeSpace) >> Space >> Name; |
| 427 | 423 | ||
| 428 | rule normal_pair = | 424 | rule normal_pair = |
| 429 | ( | 425 | ( |
| @@ -440,7 +436,7 @@ rule KeyValue = variable_pair | normal_pair; | |||
| 440 | rule KeyValueList = KeyValue >> *(sym(',') >> KeyValue); | 436 | rule KeyValueList = KeyValue >> *(sym(',') >> KeyValue); |
| 441 | rule KeyValueLine = CheckIndent >> KeyValueList >> -sym(','); | 437 | rule KeyValueLine = CheckIndent >> KeyValueList >> -sym(','); |
| 442 | 438 | ||
| 443 | rule FnArgDef = (Name | SelfName) >> -(sym('=') >> Exp); | 439 | rule FnArgDef = (Space >> Name | SelfName) >> -(sym('=') >> Exp); |
| 444 | 440 | ||
| 445 | rule FnArgDefList = Seperator >> | 441 | rule FnArgDefList = Seperator >> |
| 446 | ( | 442 | ( |
| @@ -456,11 +452,11 @@ rule FnArgDefList = Seperator >> | |||
| 456 | rule outer_var_shadow = key("using") >> (NameList | Space >> expr("nil")); | 452 | rule outer_var_shadow = key("using") >> (NameList | Space >> expr("nil")); |
| 457 | 453 | ||
| 458 | rule FnArgsDef = sym('(') >> White >> -FnArgDefList >> -outer_var_shadow >> White >> sym(')'); | 454 | rule FnArgsDef = sym('(') >> White >> -FnArgDefList >> -outer_var_shadow >> White >> sym(')'); |
| 459 | rule fn_arrow = sym("->") | sym("=>"); | 455 | rule fn_arrow = expr("->") | expr("=>"); |
| 460 | rule FunLit = -FnArgsDef >> fn_arrow >> -Body; | 456 | rule FunLit = -FnArgsDef >> Space >> fn_arrow >> -Body; |
| 461 | 457 | ||
| 462 | rule NameList = Seperator >> Name >> *(sym(',') >> Name); | 458 | rule NameList = Seperator >> Space >> Name >> *(sym(',') >> Space >> Name); |
| 463 | rule NameOrDestructure = Name | TableLit; | 459 | rule NameOrDestructure = Space >> Name | TableLit; |
| 464 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); | 460 | rule AssignableNameList = Seperator >> NameOrDestructure >> *(sym(',') >> NameOrDestructure); |
| 465 | 461 | ||
| 466 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); | 462 | rule ExpList = Seperator >> Exp >> *(sym(',') >> Exp); |
