10#pragma clang diagnostic push
11#pragma clang diagnostic ignored "-Wextra-qualification"
12#pragma ide diagnostic ignored "misc-no-recursion"
100 parse(satisfyCondition, lex);
101 if (!satisfyCondition) {
103 panic(lex.
line, lex.
col,
"expected satisfyClause after `satisfy` in defTemplateArgSpec");
136 panic(lex.
line, lex.
col,
"expected defTemplateArgSpec after comma in defTemplateArg");
151 panic(lex.
line, lex.
col,
"expected `>` to close a defTemplateArg node");
187 panic(lex.
line, lex.
col,
"expected templateArgSpec after comma in templateArg");
220 args.emplace_back(t);
227 panic(lex.
line, lex.
col,
"expected rightValueExpr after comma in invocationArguments");
231 args.emplace_back(t);
240 panic(lex.
line, lex.
col,
"expected `)` to close an invocationArguments node");
266 panic(lex.
line, lex.
col,
"expected identifierWithTypeSpec after comma in definitionArguments");
279 panic(lex.
line, lex.
col,
"expected `)` to close a definitionArguments node");
299 panic(lex.
line, lex.
col,
"expected definitionArguments after `func`");
307 panic(lex.
line, lex.
col,
"expected `:` after definitionArguments");
314 panic(lex.
line, lex.
col,
"expected typeSpec after `:`");
341 panic(lex.
line, lex.
col,
"expected typeSpec after `...`");
357 parse(decltypeExpression, lex);
358 if (decltypeExpression) {
382 if (decltypeExpression)
finalizeAST(decltypeExpression);
383 delete arraySubscript;
385 panic(lex.
line, lex.
col,
"expected integer after `,` in array type specifier");
394 if (decltypeExpression)
finalizeAST(decltypeExpression);
395 delete arraySubscript;
402 if (decltypeExpression)
finalizeAST(decltypeExpression);
408 o =
new typeSpec{node_start_token, kind, expr, spec,
nullptr, decltypeExpression,
false, arraySubscript};
431 panic(lex.
line, lex.
col,
"expected `]` to close a subscript");
440 panic(lex.
line, lex.
col,
"expected invocationArguments in subscript");
444 o =
new subscript{node_start_token,
nullptr, args};
509 "expected identifier (except the last term) in externModuleAccessExpression, found identifier with template arguments followed "
520 panic(lex.
line, lex.
col,
"expected identifier after `.` in externModuleAccessExpression");
568 panic(lex.
line, lex.
col,
"expected subscriptExpr after `.` in memberExpr");
587 panic(lex.
line, lex.
col,
"expected externModuleAccessExpression after `new` in newExpression");
590 o =
new newExpression{node_start_token, expr,
nullptr,
nullptr};
597 panic(lex.
line, lex.
col,
"expected lengthExpr after `new` in newExpression");
605 panic(lex.
line, lex.
col,
"expected invocationArguments after `new` in newExpression");
645 node_start_token,
primary::primaryKind::dynCastExpression,
nullptr,
nullptr,
nullptr,
nullptr, e,
nullptr,
nullptr,
nullptr,
nullptr};
651 node_start_token,
primary::primaryKind::newExpression,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, f,
nullptr,
nullptr,
nullptr};
657 node_start_token,
primary::primaryKind::lambdaExpr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, g,
nullptr,
nullptr};
663 node_start_token,
primary::primaryKind::funcExpr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, h,
nullptr};
668 o =
new primary{node_start_token,
685 panic(lex.
line, lex.
col,
"expected rightValueExpr after `(` while parsing primary");
695 panic(lex.
line, lex.
col,
"expected `)` after rightValueExpr while parsing primary");
729 o =
new uniqueExpr{node_start_token, t, expr};
736 rExpr *expr =
nullptr;
757 panic(lex.
line, lex.
col,
"expected rightValueExpr after assignment operator");
761 o =
new leftExpr{node_start_token, t, a, expr};
765 o =
new leftExpr{node_start_token, t, a,
nullptr};
773#define PARSE_BINARY_EXPR(NODE_TYPE, CHILD_TYPE, OPERATORS, ERROR_MSG) \
774 void parse(NODE_TYPE *&o, lexer &lex) { \
775 yoi::vec<CHILD_TYPE *> vecA; \
776 yoi::vec<lexer::token> vecB; \
777 CHILD_TYPE *a = nullptr; \
778 lexer::token node_start_token = lex.curToken; \
785 vecB.push_back(lex.curToken); \
790 finalizeAST_vec(vecA); \
791 panic(lex.line, lex.col, ERROR_MSG); \
797 o = new NODE_TYPE{node_start_token, vecA, vecB}; \
807 "expected uniqueExpr after operators while parsing mulExpr")
810 (lex.curToken.kind ==
lexer::token::tokenKind::plus || lex.curToken.kind ==
lexer::token::tokenKind::minus),
814 (lex.curToken.kind ==
lexer::token::tokenKind::binaryShiftLeft ||
815 lex.curToken.kind ==
lexer::token::tokenKind::binaryShiftRight),
819 (lex.curToken.kind ==
lexer::token::tokenKind::lessThan || lex.curToken.kind ==
lexer::token::tokenKind::greaterThan ||
820 lex.curToken.kind ==
lexer::token::tokenKind::lessEqual || lex.curToken.kind ==
lexer::token::tokenKind::greaterEqual),
824 (lex.curToken.kind ==
lexer::token::tokenKind::equal || lex.curToken.kind ==
lexer::token::tokenKind::notEqual),
828 (lex.curToken.kind ==
lexer::token::tokenKind::binaryAnd),
832 (lex.curToken.kind ==
lexer::token::tokenKind::binaryXor),
836 (lex.curToken.kind ==
lexer::token::tokenKind::binaryOr),
840 (lex.curToken.kind ==
lexer::token::tokenKind::logicAnd),
844 (lex.curToken.kind ==
lexer::token::tokenKind::logicOr),
847#undef PARSE_BINARY_EXPR
854 o =
new rExpr{node_start_token, expr};
860 void parse(codeBlock *&o, lexer &lex) {
862 lexer::token node_start_token = lex.curToken;
865 inCodeBlockStmt *stmt =
nullptr;
871 stmts.push_back(stmt);
876 o =
new codeBlock{node_start_token, stmts};
879 panic(lex.line, lex.col,
"expected `}` to close codeBlock");
889 void parse(useStmt *&o, lexer &lex) {
890 lexer::token node_start_token;
892 node_start_token = lex.curToken;
898 identifier *
id =
nullptr;
899 lexer::token str_token{};
903 panic(lex.line, lex.col,
"expected identifier after `use`");
909 panic(lex.line, lex.col,
"expected string token after identifier while parsing useStmt");
913 str_token = lex.curToken;
915 o =
new useStmt{node_start_token, id, str_token};
918 void parse(funcDefStmt *&o, lexer &lex) {
925 lexer::token node_start_token = lex.curToken;
928 identifierWithDefTemplateArg *name =
nullptr;
929 definitionArguments *args =
nullptr;
930 typeSpec *spec =
nullptr;
931 codeBlock *block =
nullptr;
934 attrs.push_back(lex.curToken);
940 panic(lex.line, lex.col,
"expected function name");
947 panic(lex.line, lex.col,
"expected definitionArguments after identifierWithDefTemplateArg");
956 panic(lex.line, lex.col,
"expected `:` after definitionArguments");
964 panic(lex.line, lex.col,
"expected typeSpec after `:`");
973 panic(lex.line, lex.col,
"expected codeBlock after typeSpec");
977 o =
new funcDefStmt{node_start_token, attrs, name, args, spec, block};
980 void parse(interfaceDefInnerPair *&o, lexer &lex) {
981 identifierWithTypeSpec *var =
nullptr;
982 innerMethodDecl *method =
nullptr;
983 lexer::token node_start_token = lex.curToken;
987 o =
new interfaceDefInnerPair{node_start_token,
nullptr, method};
992 o =
new interfaceDefInnerPair{node_start_token, var,
nullptr};
998 void parse(structDefInnerPair *&o, lexer &lex) {
999 identifierWithTypeSpec *var =
nullptr;
1000 innerMethodDecl *method =
nullptr;
1001 constructorDecl *con =
nullptr;
1002 finalizerDecl *fin =
nullptr;
1003 lexer::token node_start_token = lex.curToken;
1013 o =
new structDefInnerPair{node_start_token, 1, mod,
nullptr, con,
nullptr,
nullptr};
1018 o =
new structDefInnerPair{node_start_token, 2, mod,
nullptr,
nullptr, method,
nullptr};
1023 o =
new structDefInnerPair{node_start_token, 3, mod,
nullptr,
nullptr,
nullptr, fin};
1028 o =
new structDefInnerPair{node_start_token, 0, mod, var,
nullptr,
nullptr,
nullptr};
1034 void parse(implInnerPair *&o, lexer &lex) {
1035 innerMethodDef *method =
nullptr;
1036 constructorDef *con =
nullptr;
1037 finalizerDef *fin =
nullptr;
1038 lexer::token node_start_token = lex.curToken;
1042 o =
new implInnerPair{node_start_token, con,
nullptr,
nullptr};
1047 o =
new implInnerPair{node_start_token,
nullptr, method,
nullptr};
1052 o =
new implInnerPair{node_start_token,
nullptr,
nullptr, fin};
1058 void parse(interfaceDefInner *&o, lexer &lex) {
1060 lexer::token node_start_token = lex.curToken;
1063 interfaceDefInnerPair *a =
nullptr;
1081 o =
new interfaceDefInner{node_start_token, vecA};
1084 panic(lex.line, lex.col,
"expected `}` to close interfaceDefInner");
1094 void parse(structDefInner *&o, lexer &lex) {
1096 lexer::token node_start_token = lex.curToken;
1099 structDefInnerPair *a =
nullptr;
1117 o =
new structDefInner{node_start_token, vecA};
1120 panic(lex.line, lex.col,
"expected `}` to close structDefInner");
1130 void parse(implInner *&o, lexer &lex) {
1132 lexer::token node_start_token = lex.curToken;
1135 implInnerPair *a =
nullptr;
1153 o =
new implInner{node_start_token, vecA};
1156 panic(lex.line, lex.col,
"expected `}` to close implInner");
1166 void parse(interfaceDefStmt *&o, lexer &lex) {
1173 lexer::token node_start_token = lex.curToken;
1175 identifierWithDefTemplateArg *
id =
nullptr;
1176 interfaceDefInner *inner =
nullptr;
1180 panic(lex.line, lex.col,
"expected interface name after `interface`");
1187 panic(lex.line, lex.col,
"expected interfaceDefInner after identifier");
1191 o =
new interfaceDefStmt{node_start_token, id, inner};
1194 void parse(structDefStmt *&o, lexer &lex) {
1201 lexer::token node_start_token = lex.curToken;
1203 identifierWithDefTemplateArg *
id =
nullptr;
1204 structDefInner *inner =
nullptr;
1208 panic(lex.line, lex.col,
"expected struct name after `struct`");
1215 panic(lex.line, lex.col,
"expected structDefInner after identifier");
1219 o =
new structDefStmt{node_start_token, id, inner};
1222 void parse(dataStructDefStmt *&o, lexer &lex) {
1229 lexer::token node_start_token = lex.curToken;
1231 identifier *
id =
nullptr;
1232 structDefInner *inner =
nullptr;
1236 panic(lex.line, lex.col,
"expected datastruct name after `datastruct`");
1243 panic(lex.line, lex.col,
"expected datastruct body after identifier");
1248 for (
auto &pair : inner->getInner()) {
1249 if (pair->kind != 0) {
1252 panic(lex.line, lex.col,
"datastruct can only contain fields, no methods or constructors allowed");
1258 o =
new dataStructDefStmt{node_start_token, id, inner};
1261 void parse(implStmt *&o, lexer &lex) {
1268 lexer::token node_start_token = lex.curToken;
1270 externModuleAccessExpression *first =
nullptr;
1271 externModuleAccessExpression *second =
nullptr;
1272 implInner *inner =
nullptr;
1280 panic(lex.line, lex.col,
"expected struct name after `impl`");
1291 panic(lex.line, lex.col,
"expected interface name after `:`");
1303 o =
new implStmt{node_start_token, first, second,
nullptr};
1308 o =
new implStmt{node_start_token, first, second, inner};
1311 void parse(letAssignmentPair *&o, lexer &lex) {
1312 letAssignmentPairLHS *lhs =
nullptr;
1313 typeSpec *type =
nullptr;
1314 rExpr *rhs =
nullptr;
1315 lexer::token node_start_token = lex.curToken;
1319 panic(lex.line, lex.col,
"expected left-hand-side in letAssignmentPair");
1327 panic(lex.line, lex.col,
"expected typeSpec after `:` in letAssignmentPair");
1336 panic(lex.line, lex.col,
"expected `=` after left-hand-side in letAssignmentPair");
1343 panic(lex.line, lex.col,
"expected right-hand-side in letAssignmentPair");
1347 o =
new letAssignmentPair{node_start_token, lhs, type, rhs};
1350 void parse(letAssignmentPairLHS *&o, lexer &lex) {
1351 lexer::token node_start_token = lex.curToken;
1353 identifier *
id =
new identifier{lex.curToken, lex.curToken};
1363 vecA.push_back(lex.curToken);
1372 vecA.push_back(lex.curToken);
1375 yoi_assert(vecA.empty() || vecA.size() < 2 ||
1379 "structured binding cannot have `...` both in the front and in the back of the list");
1380 if (vecA.size() > 2)
1385 "structured binding cannot have `...` in the middle of the list");
1391 panic(lex.line, lex.col,
"expected identifier or `[...]` after `let`");
1396 void parse(letStmt *&o, lexer &lex) {
1397 lexer::token node_start_token;
1399 node_start_token = lex.curToken;
1406 letAssignmentPair *a =
nullptr;
1412 panic(lex.line, lex.col,
"expected letAssignmentPair after `let`");
1414 panic(lex.line, lex.col,
"expected letAssignmentPair after comma in let statement");
1429 o =
new letStmt{node_start_token, vecA};
1432 void parse(globalStmt *&o, lexer &lex) {
1434 marcoDescriptor *marco =
nullptr;
1435 useStmt *a =
nullptr;
1436 interfaceDefStmt *b =
nullptr;
1437 structDefStmt *c =
nullptr;
1438 implStmt *d =
nullptr;
1439 letStmt *e =
nullptr;
1440 funcDefStmt *f =
nullptr;
1441 exportDecl *g =
nullptr;
1442 importDecl *h =
nullptr;
1443 typeAliasStmt *i =
nullptr;
1444 enumerationDefinition *j =
nullptr;
1445 conceptDefinition *k =
nullptr;
1447 lexer::token node_start_token = lex.curToken;
1469 dataStructDefStmt *ds =
nullptr;
1530 void parse(ifStmt::ifBlock &o, lexer &lex) {
1538 panic(lex.line, lex.col,
"expected `(`");
1544 panic(lex.line, lex.col,
"expected rExpr after `(`");
1552 panic(lex.line, lex.col,
"expected `)` after rExpr");
1556 parse(o.block, lex);
1559 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1564 void parse(ifStmt *&o, lexer &lex) {
1566 lexer::token node_start_token = lex.curToken;
1568 o =
new ifStmt{node_start_token, {}, {},
nullptr};
1575 ifStmt::ifBlock temp_if_block{};
1576 parse(temp_if_block, lex);
1577 if (!temp_if_block.cond || !temp_if_block.block) {
1582 o->ifB = temp_if_block;
1588 parse(temp_if_block, lex);
1589 if (!temp_if_block.cond || !temp_if_block.block) {
1591 panic(lex.line, lex.col,
"expected ifBlock after `elif`");
1595 o->elifB.push_back(temp_if_block);
1601 parse(o->elseB, lex);
1604 panic(lex.line, lex.col,
"expected codeBlock after `else`");
1611 void parse(whileStmt *&o, lexer &lex) {
1612 lexer::token node_start_token;
1614 node_start_token = lex.curToken;
1621 rExpr *expr =
nullptr;
1622 codeBlock *block =
nullptr;
1627 panic(lex.line, lex.col,
"expected `(` after `while`");
1634 panic(lex.line, lex.col,
"expected rExpr after `(`");
1643 panic(lex.line, lex.col,
"expected `)` after rExpr");
1651 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1656 o =
new whileStmt{node_start_token, expr, block};
1659 void parse(forStmt *&o, lexer &lex) {
1660 lexer::token node_start_token;
1662 node_start_token = lex.curToken;
1669 inCodeBlockStmt *initStmt =
nullptr;
1670 rExpr *cond =
nullptr;
1671 inCodeBlockStmt *afterStmt =
nullptr;
1672 codeBlock *block =
nullptr;
1677 panic(lex.line, lex.col,
"expected `(` after `for`");
1682 parse(initStmt, lex);
1687 panic(lex.line, lex.col,
"expected initStmt after `(`");
1696 panic(lex.line, lex.col,
"expected `;` after initStmt");
1705 panic(lex.line, lex.col,
"expected condition after `;`");
1715 panic(lex.line, lex.col,
"expected `;` after condition");
1720 parse(afterStmt, lex);
1724 panic(lex.line, lex.col,
"expected afterStmt after `;`");
1735 panic(lex.line, lex.col,
"expected `)` after afterStmt");
1744 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1748 o =
new forStmt{node_start_token, initStmt, cond, afterStmt, block};
1751 void parse(forEachStmt *&o, lexer &lex) {
1752 lexer::token node_start_token;
1754 node_start_token = lex.curToken;
1761 identifier *var =
nullptr;
1762 rExpr *container =
nullptr;
1763 codeBlock *block =
nullptr;
1768 panic(lex.line, lex.col,
"expected `(` after `forEach`");
1774 panic(lex.line, lex.col,
"expected variable name after `(`");
1782 panic(lex.line, lex.col,
"expected `:` after variable name");
1786 parse(container, lex);
1789 panic(lex.line, lex.col,
"expected container after `:`");
1798 panic(lex.line, lex.col,
"expected `)` after container");
1806 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1810 o =
new forEachStmt{node_start_token, var, container, block};
1813 void parse(returnStmt *&o, lexer &lex) {
1815 lexer::token node_start_token = lex.curToken;
1817 rExpr *expr =
nullptr;
1819 o =
new returnStmt{node_start_token, expr};
1825 void parse(continueStmt *&o, lexer &lex) {
1827 lexer::token node_start_token = lex.curToken;
1829 o =
new continueStmt{node_start_token};
1836 void parse(breakStmt *&o, lexer &lex) {
1838 lexer::token node_start_token = lex.curToken;
1840 o =
new breakStmt{node_start_token};
1847 void parse(inCodeBlockStmt *&o, lexer &lex) {
1849 marcoDescriptor *marco =
nullptr;
1850 letStmt *letStmtVal =
nullptr;
1851 ifStmt *ifStmtVal =
nullptr;
1852 breakStmt *breakStmtVal =
nullptr;
1853 continueStmt *continueStmtVal =
nullptr;
1854 returnStmt *returnStmtVal =
nullptr;
1855 forEachStmt *forEachStmtVal =
nullptr;
1856 whileStmt *whileStmtVal =
nullptr;
1857 forStmt *forStmtVal =
nullptr;
1858 codeBlock *codeBlockVal =
nullptr;
1859 tryCatchStmt *tryCatchStmtVal =
nullptr;
1860 throwStmt *throwStmtVal =
nullptr;
1861 yieldStmt *yieldStmtVal =
nullptr;
1862 rExpr *rExprVal =
nullptr;
1864 lexer::token node_start_token = lex.curToken;
1871 parse(letStmtVal, lex);
1876 parse(ifStmtVal, lex);
1881 parse(breakStmtVal, lex);
1886 parse(continueStmtVal, lex);
1887 if (continueStmtVal) {
1891 parse(returnStmtVal, lex);
1892 if (returnStmtVal) {
1896 parse(forEachStmtVal, lex);
1897 if (forEachStmtVal) {
1901 parse(whileStmtVal, lex);
1907 parse(forStmtVal, lex);
1913 parse(tryCatchStmtVal, lex);
1914 if (tryCatchStmtVal) {
1919 parse(throwStmtVal, lex);
1925 parse(codeBlockVal, lex);
1931 parse(yieldStmtVal, lex);
1938 parse(rExprVal, lex);
1949 void parse(innerMethodDecl *&o, lexer &lex) {
1951 lexer::token node_start_token = lex.curToken;
1953 o =
new innerMethodDecl{node_start_token, {},
nullptr,
nullptr,
nullptr};
1956 o->attrs.push_back(lex.curToken);
1960 parse(o->name, lex);
1967 parse(o->args, lex);
1985 parse(o->resultType, lex);
1986 if (!o->resultType) {
1997 void parse(innerMethodDef *&o, lexer &lex) {
1999 lexer::token node_start_token = lex.curToken;
2001 o =
new innerMethodDef{node_start_token, {},
nullptr,
nullptr,
nullptr,
nullptr};
2004 o->attrs.push_back(lex.curToken);
2008 parse(o->name, lex);
2015 parse(o->args, lex);
2033 parse(o->resultType, lex);
2034 if (!o->resultType) {
2042 parse(o->block, lex);
2055 void parse(constructorDecl *&o, lexer &lex) {
2056 lexer::token node_start_token;
2058 node_start_token = lex.curToken;
2064 defTemplateArg *tempArg =
nullptr;
2066 parse(tempArg, lex);
2068 panic(lex.line, lex.col,
"expected template argument after `<` in constructor declaration");
2073 definitionArguments *args =
nullptr;
2076 panic(lex.line, lex.col,
"expected arguments after `constructor`");
2082 panic(lex.line, lex.col,
"constructor declaration cannot have a return type");
2085 o =
new constructorDecl{node_start_token, tempArg, args};
2088 void parse(constructorDef *&o, lexer &lex) {
2089 lexer::token node_start_token;
2091 node_start_token = lex.curToken;
2097 templateArg *tempArg =
nullptr;
2098 definitionArguments *args =
nullptr;
2099 codeBlock *block =
nullptr;
2102 parse(tempArg, lex);
2104 panic(lex.line, lex.col,
"expected template argument after `<` in constructor definition");
2111 panic(lex.line, lex.col,
"expected arguments after `constructor`");
2117 panic(lex.line, lex.col,
"constructor declaration cannot have a return type");
2123 panic(lex.line, lex.col,
"expected codeBlock after arguments");
2127 o =
new constructorDef{node_start_token, tempArg, args, block};
2130 void parse(hoshiModule *&o, lexer &lex) {
2132 globalStmt *a =
nullptr;
2134 lexer::token node_start_token = lex.curToken;
2142 panic(lex.line, lex.col,
"expected globalStmt");
2149 o =
new hoshiModule{node_start_token, vecA};
2152 void parse(importDecl *&o, lexer &lex) {
2153 lexer::token node_start_token;
2155 lexer::token node_start_token = lex.curToken;
2162 innerMethodDecl *a =
nullptr;
2165 panic(lex.line, lex.col,
"expected innerMethodDecl after `import`");
2170 o =
new importDecl{node_start_token, a};
2175 o->from_path = lex.curToken;
2179 panic(lex.line, lex.col,
"expected string literal after `from` in import declaration");
2185 panic(lex.line, lex.col,
"expected `from` after import declaration");
2191 void parse(exportDecl *&o, lexer &lex) {
2192 lexer::token node_start_token;
2194 node_start_token = lex.curToken;
2203 attrs.push_back(lex.curToken);
2207 typeSpec *a =
nullptr;
2210 panic(lex.line, lex.col,
"expected typeSpec after `export`");
2215 o =
new exportDecl{node_start_token, attrs, a,
nullptr};
2219 identifier *b =
nullptr;
2223 panic(lex.line, lex.col,
"expected identifier after `as` in export declaration");
2230 panic(lex.line, lex.col,
"expected `as` after export declaration");
2236 void parse(tryCatchStmt *&o, lexer &lex) {
2241 lexer::token node_start_token = lex.curToken;
2243 codeBlock *tryBlock =
nullptr;
2244 parse(tryBlock, lex);
2245 yoi_assert(tryBlock, lex.line, lex.col,
"expected codeBlock after `try`");
2253 panic(lex.line, lex.col,
"expected catchParam after `catch`");
2255 catchParams.push_back(param);
2257 codeBlock *finallyBlock =
nullptr;
2258 parse(finallyBlock, lex);
2259 if (!finallyBlock) {
2261 for (
auto p : catchParams)
2264 panic(lex.line, lex.col,
"expected codeBlock after `catch`");
2266 o =
new tryCatchStmt{node_start_token, tryBlock, catchParams, finallyBlock};
2269 void parse(throwStmt *&o, lexer &lex) {
2274 lexer::token node_start_token = lex.curToken;
2276 rExpr *expr =
nullptr;
2280 panic(lex.line, lex.col,
"expected expression after `throw`");
2282 o =
new throwStmt{node_start_token, expr};
2285 void parse(catchParam *&o, lexer &lex) {
2290 lexer::token node_start_token = lex.curToken;
2294 panic(lex.line, lex.col,
"expected `(` after `catch`");
2297 identifier *name =
nullptr;
2301 panic(lex.line, lex.col,
"expected identifier after typeSpec in catchParam");
2306 panic(lex.line, lex.col,
"expected `)` after identifier in catchParam");
2309 typeSpec *type =
nullptr;
2314 panic(lex.line, lex.col,
"expected typeSpec after `(` in catchParam");
2320 panic(lex.line, lex.col,
"expected `)` after typeSpec in catchParam");
2323 codeBlock *block =
nullptr;
2329 panic(lex.line, lex.col,
"expected codeBlock after identifier in catchParam");
2331 o =
new catchParam{node_start_token, type, name, block};
2334 void parse(typeIdExpression *&o, lexer &lex) {
2339 lexer::token node_start_token = lex.curToken;
2343 rExpr *expr =
nullptr;
2347 panic(lex.line, lex.col,
"expected expression after `(` in `type_id` expression");
2352 panic(lex.line, lex.col,
"expected `)` after expression in `type_id` expression");
2355 o =
new typeIdExpression{node_start_token,
nullptr, expr};
2358 typeSpec *type =
nullptr;
2362 panic(lex.line, lex.col,
"expected typeSpec after `<` in `type_id` expression");
2367 panic(lex.line, lex.col,
"expected `>` after typeSpec in `type_id` expression");
2370 o =
new typeIdExpression{node_start_token, type,
nullptr};
2373 panic(lex.line, lex.col,
"expected `(` or `<` after `type_id` in `type_id` expression");
2377 void parse(dynCastExpression *&o, lexer &lex) {
2382 lexer::token node_start_token = lex.curToken;
2386 panic(lex.line, lex.col,
"expected `<` after `dyn_cast`");
2389 typeSpec *type =
nullptr;
2393 panic(lex.line, lex.col,
"expected typeSpec after `<` in `dyn_cast` expression");
2398 panic(lex.line, lex.col,
"expected `>` after typeSpec in `dyn_cast` expression");
2404 panic(lex.line, lex.col,
"expected `(` after `>` in `dyn_cast` expression");
2407 rExpr *expr =
nullptr;
2412 panic(lex.line, lex.col,
"expected expression after `(` in `dyn_cast` expression");
2418 panic(lex.line, lex.col,
"expected `)` after expression in `dyn_cast` expression");
2421 o =
new dynCastExpression{node_start_token, type, expr};
2424 void parse(abstractExpr *&o, lexer &lex) {
2425 lexer::token node_start_token = lex.curToken;
2434 o =
new abstractExpr{node_start_token, lhs, {},
nullptr};
2437 o =
new abstractExpr{node_start_token, lhs, lex.curToken,
nullptr};
2444 panic(lex.line, lex.col,
"expected extern module access expression after `interfaceof` or `impl`");
2448 void parse(lambdaExpr *&o, lexer &lex) {
2449 lexer::token node_start_token = lex.curToken;
2462 vec<yoi::identifier *> captures;
2464 identifier *capture =
nullptr;
2465 parse(capture, lex);
2466 captures.push_back(capture);
2468 for (
auto c : captures)
2471 panic(lex.line, lex.col,
"expected identifier in capture list in lambda expression");
2480 panic(lex.line, lex.col,
"expected `]` after capture list in lambda expression");
2483 definitionArguments *args =
nullptr;
2487 panic(lex.line, lex.col,
"expected arguments after capture list in lambda expression");
2492 panic(lex.line, lex.col,
"expected `:` after arguments in lambda expression");
2495 typeSpec *resultType =
nullptr;
2496 parse(resultType, lex);
2500 panic(lex.line, lex.col,
"expected typeSpec after `:` in lambda expression");
2502 codeBlock *block =
nullptr;
2508 panic(lex.line, lex.col,
"expected codeBlock after `:` in lambda expression");
2511 o =
new lambdaExpr{node_start_token, captures, args, resultType, block};
2514 void parse(unnamedDefinitionArguments *&o, lexer &lex) {
2519 lexer::token node_start_token = lex.curToken;
2521 vec<typeSpec *> types;
2523 typeSpec *type =
nullptr;
2529 types.push_back(type);
2537 for (
auto t : types)
2539 panic(lex.line, lex.col,
"expected `)` after typeSpecs in unnamed definition arguments");
2542 o =
new unnamedDefinitionArguments{node_start_token, types};
2545 void parse(marcoPair *&o, lexer &lex) {
2546 lexer::token node_start_token = lex.curToken;
2548 lexer::token lhs, constraint, rhs;
2557 switch (lex.curToken.kind) {
2564 constraint = lex.curToken;
2574 switch (lex.curToken.kind) {
2590 o =
new marcoPair{node_start_token, lhs, constraint, rhs};
2593 void parse(marcoDescriptor *&o, lexer &lex) {
2594 lexer::token current_token = lex.curToken;
2598 o =
new marcoDescriptor{current_token, {}};
2604 o =
new marcoDescriptor{current_token, {}};
2608 vec<marcoPair *> pairs;
2609 marcoPair *pair =
nullptr;
2612 pairs.push_back(pair);
2618 for (
auto p : pairs)
2625 for (
auto p : pairs)
2631 o =
new marcoDescriptor{current_token, pairs};
2634 void parse(typeAliasStmt *&o, lexer &lex) {
2635 lexer::token node_start_token = lex.curToken;
2641 identifierWithDefTemplateArg *lhs;
2644 panic(lex.line, lex.col,
"expected identifier with definition template arguments in type alias statement");
2651 panic(lex.line, lex.col,
"expected `=` after identifier in type alias statement");
2655 typeSpec *rhs =
nullptr;
2660 panic(lex.line, lex.col,
"expected typeSpec after `=` in type alias statement");
2663 o =
new typeAliasStmt{node_start_token, lhs, rhs};
2666 void parse(finalizerDecl *&o, lexer &lex) {
2667 lexer::token node_start_token = lex.curToken;
2675 panic(lex.line, lex.col,
"expected `(` after `finalizer` in finalizer declaration");
2680 panic(lex.line, lex.col,
"expected `)` after `finalizer` in finalizer declaration");
2683 o =
new finalizerDecl{node_start_token};
2686 void parse(finalizerDef *&o, lexer &lex) {
2687 lexer::token node_start_token = lex.curToken;
2695 panic(lex.line, lex.col,
"expected `(` after `finalizer` in finalizer definition");
2700 panic(lex.line, lex.col,
"expected `)` after `finalizer` in finalizer definition");
2703 codeBlock *block =
nullptr;
2707 panic(lex.line, lex.col,
"expected codeBlock after `finalizer` declaration");
2710 o =
new finalizerDef{node_start_token, block};
2713 void parse(funcExpr *&o, lexer &lex) {
2714 lexer::token node_start_token = lex.curToken;
2721 externModuleAccessExpression *name =
nullptr;
2729 unnamedDefinitionArguments *args =
nullptr;
2732 o =
new funcExpr{node_start_token, name,
nullptr};
2735 o =
new funcExpr{node_start_token, name, args};
2738 void parse(enumerationDefinition *&o, lexer &lex) {
2739 lexer::token node_start_token = lex.curToken;
2745 identifier *name =
nullptr;
2749 panic(lex.line, lex.col,
"expected identifier after `enum` in enumeration definition");
2755 panic(lex.line, lex.col,
"expected `{` after identifier in enumeration definition");
2759 vec<enumerationPair *> enumerators;
2760 enumerationPair *enumerator =
nullptr;
2761 parse(enumerator, lex);
2762 while (enumerator) {
2763 enumerators.push_back(enumerator);
2767 enumerator =
nullptr;
2769 parse(enumerator, lex);
2774 for (
auto e : enumerators)
2777 panic(lex.line, lex.col,
"expected `}` after enumerators in enumeration definition");
2781 o =
new enumerationDefinition{node_start_token, name, enumerators};
2784 void parse(enumerationPair *&o, lexer &lex) {
2785 lexer::token node_start_token = lex.curToken;
2786 identifier *name =
nullptr;
2793 o =
new enumerationPair{node_start_token, name, {}};
2797 lexer::token
value = lex.curToken;
2799 o =
new enumerationPair{node_start_token, name,
value};
2806 panic(lex.line, lex.col,
"expected integer literal after `-` in enumeration pair");
2809 value = lex.curToken;
2811 o =
new enumerationPair{node_start_token, name,
value};
2816 panic(lex.line, lex.col,
"expected integer literal after `=` in enumeration pair");
2821 void parse(bracedInitalizerList *&o, lexer &lex) {
2829 vec<rExpr *> expressions;
2830 rExpr *expression =
nullptr;
2831 parse(expression, lex);
2832 while (expression) {
2833 expressions.push_back(expression);
2837 expression =
nullptr;
2839 parse(expression, lex);
2844 for (
auto e : expressions)
2851 o =
new bracedInitalizerList{node_start_token, expressions};
2854 void parse(yieldStmt *&o, lexer &lex) {
2861 rExpr *expr =
nullptr;
2865 panic(lex.line, lex.col,
"expected rExpr after `yield` in yieldStmt");
2868 o =
new yieldStmt{node_start_token, expr};
2871 void parse(decltypeExpr *&o, lexer &lex) {
2872 lexer::token node_start_token{lex.curToken};
2882 yoi_assert(expr, lex.line, lex.col,
"expected expression after `(` for decltype-expression");
2886 panic(lex.line, lex.col,
"expected `)` after expression");
2889 o =
new decltypeExpr{node_start_token, expr};
2892 void parse(satisfyStmt *&o, lexer &lex) {
2899 externModuleAccessExpression *emae =
nullptr;
2903 panic(lex.line, lex.col,
"expected externModuleAccessExpression after `satisfy` in satisfyStmt");
2906 o =
new satisfyStmt{node_start_token, emae};
2909 void parse(conceptStmt *&o, lexer &lex) {
2927 void parse(conceptDefinition *&o, lexer &lex) {
2935 lexer::token name{};
2938 name = lex.curToken;
2945 typeParams.push_back(lex.curToken);
2960 identifierWithTypeSpec *spec{};
2963 specs.push_back(spec);
2977 for (
auto s : specs)
2979 panic(lex.line, lex.col,
"expected `{` after `)`");
2985 conceptStmt *stmt{};
2988 conceptStmts.push_back(stmt);
2995 o =
new conceptDefinition{node_start_token, name, typeParams, specs, conceptStmts};
2998 void parse(satisfyClause *&o, lexer &lex) {
3003 lexer::token node_start_token = lex.curToken;
3009 externModuleAccessExpression *spec{};
3012 specs.push_back(spec);
3023 for (
auto s : specs)
3025 panic(lex.line, lex.col,
"expected `)` after specs");
3029 o =
new satisfyClause{node_start_token, specs};
3033#pragma clang diagnostic pop
bool hasTemplateArg() const
invocationArguments * args
externModuleAccessExpression * type
enum yoi::typeSpec::typeSpecKind kind
constexpr E value(std::size_t i) noexcept
void yoi_assert(bool condition, yoi::indexT line, yoi::indexT col, const std::string &msg)
Asserts a condition that would be true and throws a runtime_error if it is false.
void finalizeAST(funcTypeSpec *ptr)
void finalizeAST_vec(yoi::vec< T * > &vec)
void parse(yoi::basicLiterals *&o, yoi::lexer &lex)
void panic(yoi::indexT line, yoi::indexT col, const std::string &msg)
#define PARSE_BINARY_EXPR(NODE_TYPE, CHILD_TYPE, OPERATORS, ERROR_MSG)
enum yoi::lexer::token::tokenKind kind
@ multiplicationAssignment
union yoi::lexer::token::vBasicValue basicVal