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);
878 o =
new codeBlock{node_start_token, stmts};
879 o->endLine = endLine;
880 o->endColumn = endColumn;
883 panic(lex.line, lex.col,
"expected `}` to close codeBlock");
893 void parse(useStmt *&o, lexer &lex) {
894 lexer::token node_start_token;
896 node_start_token = lex.curToken;
902 identifier *
id =
nullptr;
903 lexer::token str_token{};
907 panic(lex.line, lex.col,
"expected identifier after `use`");
913 panic(lex.line, lex.col,
"expected string token after identifier while parsing useStmt");
917 str_token = lex.curToken;
919 o =
new useStmt{node_start_token, id, str_token};
922 void parse(funcDefStmt *&o, lexer &lex) {
929 lexer::token node_start_token = lex.curToken;
932 identifierWithDefTemplateArg *name =
nullptr;
933 definitionArguments *args =
nullptr;
934 typeSpec *spec =
nullptr;
935 codeBlock *block =
nullptr;
938 attrs.push_back(lex.curToken);
944 panic(lex.line, lex.col,
"expected function name");
951 panic(lex.line, lex.col,
"expected definitionArguments after identifierWithDefTemplateArg");
960 panic(lex.line, lex.col,
"expected `:` after definitionArguments");
968 panic(lex.line, lex.col,
"expected typeSpec after `:`");
977 panic(lex.line, lex.col,
"expected codeBlock after typeSpec");
981 o =
new funcDefStmt{node_start_token, attrs, name, args, spec, block};
984 void parse(interfaceDefInnerPair *&o, lexer &lex) {
985 identifierWithTypeSpec *var =
nullptr;
986 innerMethodDecl *method =
nullptr;
987 lexer::token node_start_token = lex.curToken;
991 o =
new interfaceDefInnerPair{node_start_token,
nullptr, method};
996 o =
new interfaceDefInnerPair{node_start_token, var,
nullptr};
1002 void parse(structDefInnerPair *&o, lexer &lex) {
1003 identifierWithTypeSpec *var =
nullptr;
1004 innerMethodDecl *method =
nullptr;
1005 constructorDecl *con =
nullptr;
1006 finalizerDecl *fin =
nullptr;
1007 lexer::token node_start_token = lex.curToken;
1020 o =
new structDefInnerPair{node_start_token, 1, mod,
nullptr, con,
nullptr,
nullptr};
1025 o =
new structDefInnerPair{node_start_token, 2, mod,
nullptr,
nullptr, method,
nullptr};
1030 o =
new structDefInnerPair{node_start_token, 3, mod,
nullptr,
nullptr,
nullptr, fin};
1035 o =
new structDefInnerPair{node_start_token, 0, mod, var,
nullptr,
nullptr,
nullptr};
1041 void parse(implInnerPair *&o, lexer &lex) {
1042 innerMethodDef *method =
nullptr;
1043 constructorDef *con =
nullptr;
1044 finalizerDef *fin =
nullptr;
1045 lexer::token node_start_token = lex.curToken;
1049 o =
new implInnerPair{node_start_token, con,
nullptr,
nullptr};
1054 o =
new implInnerPair{node_start_token,
nullptr, method,
nullptr};
1059 o =
new implInnerPair{node_start_token,
nullptr,
nullptr, fin};
1065 void parse(interfaceDefInner *&o, lexer &lex) {
1067 lexer::token node_start_token = lex.curToken;
1070 interfaceDefInnerPair *a =
nullptr;
1088 o =
new interfaceDefInner{node_start_token, vecA};
1091 panic(lex.line, lex.col,
"expected `}` to close interfaceDefInner");
1101 void parse(structDefInner *&o, lexer &lex) {
1103 lexer::token node_start_token = lex.curToken;
1106 structDefInnerPair *a =
nullptr;
1124 o =
new structDefInner{node_start_token, vecA};
1127 panic(lex.line, lex.col,
"expected `}` to close structDefInner");
1137 void parse(implInner *&o, lexer &lex) {
1139 lexer::token node_start_token = lex.curToken;
1142 implInnerPair *a =
nullptr;
1160 o =
new implInner{node_start_token, vecA};
1163 panic(lex.line, lex.col,
"expected `}` to close implInner");
1173 void parse(interfaceDefStmt *&o, lexer &lex) {
1180 lexer::token node_start_token = lex.curToken;
1182 identifierWithDefTemplateArg *
id =
nullptr;
1183 interfaceDefInner *inner =
nullptr;
1187 panic(lex.line, lex.col,
"expected interface name after `interface`");
1194 panic(lex.line, lex.col,
"expected interfaceDefInner after identifier");
1198 o =
new interfaceDefStmt{node_start_token, id, inner};
1201 void parse(structDefStmt *&o, lexer &lex) {
1208 lexer::token node_start_token = lex.curToken;
1210 identifierWithDefTemplateArg *
id =
nullptr;
1211 structDefInner *inner =
nullptr;
1215 panic(lex.line, lex.col,
"expected struct name after `struct`");
1222 panic(lex.line, lex.col,
"expected structDefInner after identifier");
1226 o =
new structDefStmt{node_start_token, id, inner};
1229 void parse(dataStructDefStmt *&o, lexer &lex) {
1236 lexer::token node_start_token = lex.curToken;
1238 identifier *
id =
nullptr;
1239 structDefInner *inner =
nullptr;
1243 panic(lex.line, lex.col,
"expected datastruct name after `datastruct`");
1250 panic(lex.line, lex.col,
"expected datastruct body after identifier");
1255 for (
auto &pair : inner->getInner()) {
1256 if (pair->kind != 0) {
1259 panic(lex.line, lex.col,
"datastruct can only contain fields, no methods or constructors allowed");
1265 o =
new dataStructDefStmt{node_start_token, id, inner};
1268 void parse(implStmt *&o, lexer &lex) {
1275 lexer::token node_start_token = lex.curToken;
1277 externModuleAccessExpression *first =
nullptr;
1278 externModuleAccessExpression *second =
nullptr;
1279 implInner *inner =
nullptr;
1287 panic(lex.line, lex.col,
"expected struct name after `impl`");
1298 panic(lex.line, lex.col,
"expected interface name after `:`");
1310 o =
new implStmt{node_start_token, first, second,
nullptr};
1315 o =
new implStmt{node_start_token, first, second, inner};
1318 void parse(letAssignmentPair *&o, lexer &lex) {
1319 letAssignmentPairLHS *lhs =
nullptr;
1320 typeSpec *type =
nullptr;
1321 rExpr *rhs =
nullptr;
1322 lexer::token node_start_token = lex.curToken;
1326 panic(lex.line, lex.col,
"expected left-hand-side in letAssignmentPair");
1334 panic(lex.line, lex.col,
"expected typeSpec after `:` in letAssignmentPair");
1343 panic(lex.line, lex.col,
"expected `=` after left-hand-side in letAssignmentPair");
1350 panic(lex.line, lex.col,
"expected right-hand-side in letAssignmentPair");
1354 o =
new letAssignmentPair{node_start_token, lhs, type, rhs};
1357 void parse(letAssignmentPairLHS *&o, lexer &lex) {
1358 lexer::token node_start_token = lex.curToken;
1360 identifier *
id =
new identifier{lex.curToken, lex.curToken};
1370 vecA.push_back(lex.curToken);
1379 vecA.push_back(lex.curToken);
1382 yoi_assert(vecA.empty() || vecA.size() < 2 ||
1386 "structured binding cannot have `...` both in the front and in the back of the list");
1387 if (vecA.size() > 2)
1392 "structured binding cannot have `...` in the middle of the list");
1398 panic(lex.line, lex.col,
"expected identifier or `[...]` after `let`");
1403 void parse(letStmt *&o, lexer &lex) {
1404 lexer::token node_start_token;
1406 node_start_token = lex.curToken;
1413 letAssignmentPair *a =
nullptr;
1419 panic(lex.line, lex.col,
"expected letAssignmentPair after `let`");
1421 panic(lex.line, lex.col,
"expected letAssignmentPair after comma in let statement");
1436 o =
new letStmt{node_start_token, vecA};
1439 void parse(globalStmt *&o, lexer &lex) {
1441 marcoDescriptor *marco =
nullptr;
1442 useStmt *a =
nullptr;
1443 interfaceDefStmt *b =
nullptr;
1444 structDefStmt *c =
nullptr;
1445 implStmt *d =
nullptr;
1446 letStmt *e =
nullptr;
1447 funcDefStmt *f =
nullptr;
1448 exportDecl *g =
nullptr;
1449 importDecl *h =
nullptr;
1450 typeAliasStmt *i =
nullptr;
1451 enumerationDefinition *j =
nullptr;
1452 conceptDefinition *k =
nullptr;
1454 lexer::token node_start_token = lex.curToken;
1476 dataStructDefStmt *ds =
nullptr;
1537 void parse(ifStmt::ifBlock &o, lexer &lex) {
1545 panic(lex.line, lex.col,
"expected `(`");
1551 panic(lex.line, lex.col,
"expected rExpr after `(`");
1559 panic(lex.line, lex.col,
"expected `)` after rExpr");
1563 parse(o.block, lex);
1566 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1571 void parse(ifStmt *&o, lexer &lex) {
1573 lexer::token node_start_token = lex.curToken;
1575 o =
new ifStmt{node_start_token, {}, {},
nullptr};
1582 ifStmt::ifBlock temp_if_block{};
1583 parse(temp_if_block, lex);
1584 if (!temp_if_block.cond || !temp_if_block.block) {
1589 o->ifB = temp_if_block;
1595 parse(temp_if_block, lex);
1596 if (!temp_if_block.cond || !temp_if_block.block) {
1598 panic(lex.line, lex.col,
"expected ifBlock after `elif`");
1602 o->elifB.push_back(temp_if_block);
1608 parse(o->elseB, lex);
1611 panic(lex.line, lex.col,
"expected codeBlock after `else`");
1618 void parse(whileStmt *&o, lexer &lex) {
1619 lexer::token node_start_token;
1621 node_start_token = lex.curToken;
1628 rExpr *expr =
nullptr;
1629 codeBlock *block =
nullptr;
1634 panic(lex.line, lex.col,
"expected `(` after `while`");
1641 panic(lex.line, lex.col,
"expected rExpr after `(`");
1650 panic(lex.line, lex.col,
"expected `)` after rExpr");
1658 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1663 o =
new whileStmt{node_start_token, expr, block};
1666 void parse(forStmt *&o, lexer &lex) {
1667 lexer::token node_start_token;
1669 node_start_token = lex.curToken;
1676 inCodeBlockStmt *initStmt =
nullptr;
1677 rExpr *cond =
nullptr;
1678 inCodeBlockStmt *afterStmt =
nullptr;
1679 codeBlock *block =
nullptr;
1684 panic(lex.line, lex.col,
"expected `(` after `for`");
1689 parse(initStmt, lex);
1694 panic(lex.line, lex.col,
"expected initStmt after `(`");
1703 panic(lex.line, lex.col,
"expected `;` after initStmt");
1712 panic(lex.line, lex.col,
"expected condition after `;`");
1722 panic(lex.line, lex.col,
"expected `;` after condition");
1727 parse(afterStmt, lex);
1731 panic(lex.line, lex.col,
"expected afterStmt after `;`");
1742 panic(lex.line, lex.col,
"expected `)` after afterStmt");
1751 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1755 o =
new forStmt{node_start_token, initStmt, cond, afterStmt, block};
1758 void parse(forEachStmt *&o, lexer &lex) {
1759 lexer::token node_start_token;
1761 node_start_token = lex.curToken;
1768 identifier *var =
nullptr;
1769 rExpr *container =
nullptr;
1770 codeBlock *block =
nullptr;
1775 panic(lex.line, lex.col,
"expected `(` after `forEach`");
1781 panic(lex.line, lex.col,
"expected variable name after `(`");
1789 panic(lex.line, lex.col,
"expected `:` after variable name");
1793 parse(container, lex);
1796 panic(lex.line, lex.col,
"expected container after `:`");
1805 panic(lex.line, lex.col,
"expected `)` after container");
1813 panic(lex.line, lex.col,
"expected codeBlock after `)`");
1817 o =
new forEachStmt{node_start_token, var, container, block};
1820 void parse(returnStmt *&o, lexer &lex) {
1822 lexer::token node_start_token = lex.curToken;
1824 rExpr *expr =
nullptr;
1826 o =
new returnStmt{node_start_token, expr};
1832 void parse(continueStmt *&o, lexer &lex) {
1834 lexer::token node_start_token = lex.curToken;
1836 o =
new continueStmt{node_start_token};
1843 void parse(breakStmt *&o, lexer &lex) {
1845 lexer::token node_start_token = lex.curToken;
1847 o =
new breakStmt{node_start_token};
1854 void parse(inCodeBlockStmt *&o, lexer &lex) {
1856 marcoDescriptor *marco =
nullptr;
1857 letStmt *letStmtVal =
nullptr;
1858 ifStmt *ifStmtVal =
nullptr;
1859 breakStmt *breakStmtVal =
nullptr;
1860 continueStmt *continueStmtVal =
nullptr;
1861 returnStmt *returnStmtVal =
nullptr;
1862 forEachStmt *forEachStmtVal =
nullptr;
1863 whileStmt *whileStmtVal =
nullptr;
1864 forStmt *forStmtVal =
nullptr;
1865 codeBlock *codeBlockVal =
nullptr;
1866 tryCatchStmt *tryCatchStmtVal =
nullptr;
1867 throwStmt *throwStmtVal =
nullptr;
1868 yieldStmt *yieldStmtVal =
nullptr;
1869 rExpr *rExprVal =
nullptr;
1871 lexer::token node_start_token = lex.curToken;
1878 parse(letStmtVal, lex);
1883 parse(ifStmtVal, lex);
1888 parse(breakStmtVal, lex);
1893 parse(continueStmtVal, lex);
1894 if (continueStmtVal) {
1898 parse(returnStmtVal, lex);
1899 if (returnStmtVal) {
1903 parse(forEachStmtVal, lex);
1904 if (forEachStmtVal) {
1908 parse(whileStmtVal, lex);
1914 parse(forStmtVal, lex);
1920 parse(tryCatchStmtVal, lex);
1921 if (tryCatchStmtVal) {
1926 parse(throwStmtVal, lex);
1932 parse(codeBlockVal, lex);
1938 parse(yieldStmtVal, lex);
1945 parse(rExprVal, lex);
1956 void parse(innerMethodDecl *&o, lexer &lex) {
1958 lexer::token node_start_token = lex.curToken;
1960 o =
new innerMethodDecl{node_start_token, {},
nullptr,
nullptr,
nullptr};
1963 o->attrs.push_back(lex.curToken);
1967 parse(o->name, lex);
1974 parse(o->args, lex);
1992 parse(o->resultType, lex);
1993 if (!o->resultType) {
2004 void parse(innerMethodDef *&o, lexer &lex) {
2006 lexer::token node_start_token = lex.curToken;
2008 o =
new innerMethodDef{node_start_token, {},
nullptr,
nullptr,
nullptr,
nullptr};
2011 o->attrs.push_back(lex.curToken);
2015 parse(o->name, lex);
2022 parse(o->args, lex);
2040 parse(o->resultType, lex);
2041 if (!o->resultType) {
2049 parse(o->block, lex);
2062 void parse(constructorDecl *&o, lexer &lex) {
2063 lexer::token node_start_token;
2065 node_start_token = lex.curToken;
2071 defTemplateArg *tempArg =
nullptr;
2073 parse(tempArg, lex);
2075 panic(lex.line, lex.col,
"expected template argument after `<` in constructor declaration");
2080 definitionArguments *args =
nullptr;
2083 panic(lex.line, lex.col,
"expected arguments after `constructor`");
2089 panic(lex.line, lex.col,
"constructor declaration cannot have a return type");
2092 o =
new constructorDecl{node_start_token, tempArg, args};
2095 void parse(constructorDef *&o, lexer &lex) {
2096 lexer::token node_start_token;
2098 node_start_token = lex.curToken;
2104 templateArg *tempArg =
nullptr;
2105 definitionArguments *args =
nullptr;
2106 codeBlock *block =
nullptr;
2109 parse(tempArg, lex);
2111 panic(lex.line, lex.col,
"expected template argument after `<` in constructor definition");
2118 panic(lex.line, lex.col,
"expected arguments after `constructor`");
2124 panic(lex.line, lex.col,
"constructor declaration cannot have a return type");
2130 panic(lex.line, lex.col,
"expected codeBlock after arguments");
2134 o =
new constructorDef{node_start_token, tempArg, args, block};
2137 void parse(hoshiModule *&o, lexer &lex) {
2139 globalStmt *a =
nullptr;
2141 lexer::token node_start_token = lex.curToken;
2149 panic(lex.line, lex.col,
"expected globalStmt");
2156 o =
new hoshiModule{node_start_token, vecA};
2159 void parse(importDecl *&o, lexer &lex) {
2160 lexer::token node_start_token;
2162 lexer::token node_start_token = lex.curToken;
2169 innerMethodDecl *a =
nullptr;
2172 panic(lex.line, lex.col,
"expected innerMethodDecl after `import`");
2177 o =
new importDecl{node_start_token, a};
2182 o->from_path = lex.curToken;
2186 panic(lex.line, lex.col,
"expected string literal after `from` in import declaration");
2192 panic(lex.line, lex.col,
"expected `from` after import declaration");
2198 void parse(exportDecl *&o, lexer &lex) {
2199 lexer::token node_start_token;
2201 node_start_token = lex.curToken;
2210 attrs.push_back(lex.curToken);
2214 typeSpec *a =
nullptr;
2217 panic(lex.line, lex.col,
"expected typeSpec after `export`");
2222 o =
new exportDecl{node_start_token, attrs, a,
nullptr};
2226 identifier *b =
nullptr;
2230 panic(lex.line, lex.col,
"expected identifier after `as` in export declaration");
2237 panic(lex.line, lex.col,
"expected `as` after export declaration");
2243 void parse(tryCatchStmt *&o, lexer &lex) {
2248 lexer::token node_start_token = lex.curToken;
2250 codeBlock *tryBlock =
nullptr;
2251 parse(tryBlock, lex);
2252 yoi_assert(tryBlock, lex.line, lex.col,
"expected codeBlock after `try`");
2260 panic(lex.line, lex.col,
"expected catchParam after `catch`");
2262 catchParams.push_back(param);
2264 codeBlock *finallyBlock =
nullptr;
2265 parse(finallyBlock, lex);
2266 if (!finallyBlock) {
2268 for (
auto p : catchParams)
2271 panic(lex.line, lex.col,
"expected codeBlock after `catch`");
2273 o =
new tryCatchStmt{node_start_token, tryBlock, catchParams, finallyBlock};
2276 void parse(throwStmt *&o, lexer &lex) {
2281 lexer::token node_start_token = lex.curToken;
2283 rExpr *expr =
nullptr;
2287 panic(lex.line, lex.col,
"expected expression after `throw`");
2289 o =
new throwStmt{node_start_token, expr};
2292 void parse(catchParam *&o, lexer &lex) {
2297 lexer::token node_start_token = lex.curToken;
2301 panic(lex.line, lex.col,
"expected `(` after `catch`");
2304 identifier *name =
nullptr;
2308 panic(lex.line, lex.col,
"expected identifier after typeSpec in catchParam");
2313 panic(lex.line, lex.col,
"expected `)` after identifier in catchParam");
2316 typeSpec *type =
nullptr;
2321 panic(lex.line, lex.col,
"expected typeSpec after `(` in catchParam");
2327 panic(lex.line, lex.col,
"expected `)` after typeSpec in catchParam");
2330 codeBlock *block =
nullptr;
2336 panic(lex.line, lex.col,
"expected codeBlock after identifier in catchParam");
2338 o =
new catchParam{node_start_token, type, name, block};
2341 void parse(typeIdExpression *&o, lexer &lex) {
2346 lexer::token node_start_token = lex.curToken;
2350 rExpr *expr =
nullptr;
2354 panic(lex.line, lex.col,
"expected expression after `(` in `type_id` expression");
2359 panic(lex.line, lex.col,
"expected `)` after expression in `type_id` expression");
2362 o =
new typeIdExpression{node_start_token,
nullptr, expr};
2365 typeSpec *type =
nullptr;
2369 panic(lex.line, lex.col,
"expected typeSpec after `<` in `type_id` expression");
2374 panic(lex.line, lex.col,
"expected `>` after typeSpec in `type_id` expression");
2377 o =
new typeIdExpression{node_start_token, type,
nullptr};
2380 panic(lex.line, lex.col,
"expected `(` or `<` after `type_id` in `type_id` expression");
2384 void parse(dynCastExpression *&o, lexer &lex) {
2389 lexer::token node_start_token = lex.curToken;
2393 panic(lex.line, lex.col,
"expected `<` after `dyn_cast`");
2396 typeSpec *type =
nullptr;
2400 panic(lex.line, lex.col,
"expected typeSpec after `<` in `dyn_cast` expression");
2405 panic(lex.line, lex.col,
"expected `>` after typeSpec in `dyn_cast` expression");
2411 panic(lex.line, lex.col,
"expected `(` after `>` in `dyn_cast` expression");
2414 rExpr *expr =
nullptr;
2419 panic(lex.line, lex.col,
"expected expression after `(` in `dyn_cast` expression");
2425 panic(lex.line, lex.col,
"expected `)` after expression in `dyn_cast` expression");
2428 o =
new dynCastExpression{node_start_token, type, expr};
2431 void parse(abstractExpr *&o, lexer &lex) {
2432 lexer::token node_start_token = lex.curToken;
2441 o =
new abstractExpr{node_start_token, lhs, {},
nullptr};
2444 o =
new abstractExpr{node_start_token, lhs, lex.curToken,
nullptr};
2451 panic(lex.line, lex.col,
"expected extern module access expression after `interfaceof` or `impl`");
2455 void parse(lambdaExpr *&o, lexer &lex) {
2456 lexer::token node_start_token = lex.curToken;
2469 vec<yoi::lambdaCapture *> captures;
2472 parse(capture, lex);
2474 for (
auto c : captures)
2477 panic(lex.line, lex.col,
"expected identifier in capture list in lambda expression");
2479 captures.push_back(capture);
2487 panic(lex.line, lex.col,
"expected `]` after capture list in lambda expression");
2490 definitionArguments *args =
nullptr;
2494 panic(lex.line, lex.col,
"expected arguments after capture list in lambda expression");
2499 panic(lex.line, lex.col,
"expected `:` after arguments in lambda expression");
2502 typeSpec *resultType =
nullptr;
2503 parse(resultType, lex);
2507 panic(lex.line, lex.col,
"expected typeSpec after `:` in lambda expression");
2509 codeBlock *block =
nullptr;
2515 panic(lex.line, lex.col,
"expected codeBlock after `:` in lambda expression");
2518 o =
new lambdaExpr{node_start_token, captures, args, resultType, block};
2521 void parse(unnamedDefinitionArguments *&o, lexer &lex) {
2526 lexer::token node_start_token = lex.curToken;
2528 vec<typeSpec *> types;
2530 typeSpec *type =
nullptr;
2536 types.push_back(type);
2544 for (
auto t : types)
2546 panic(lex.line, lex.col,
"expected `)` after typeSpecs in unnamed definition arguments");
2549 o =
new unnamedDefinitionArguments{node_start_token, types};
2552 void parse(marcoPair *&o, lexer &lex) {
2553 lexer::token node_start_token = lex.curToken;
2555 lexer::token lhs, constraint, rhs;
2564 switch (lex.curToken.kind) {
2571 constraint = lex.curToken;
2581 switch (lex.curToken.kind) {
2597 o =
new marcoPair{node_start_token, lhs, constraint, rhs};
2600 void parse(marcoDescriptor *&o, lexer &lex) {
2601 lexer::token current_token = lex.curToken;
2605 o =
new marcoDescriptor{current_token, {}};
2611 o =
new marcoDescriptor{current_token, {}};
2615 vec<marcoPair *> pairs;
2616 marcoPair *pair =
nullptr;
2619 pairs.push_back(pair);
2625 for (
auto p : pairs)
2632 for (
auto p : pairs)
2638 o =
new marcoDescriptor{current_token, pairs};
2641 void parse(typeAliasStmt *&o, lexer &lex) {
2642 lexer::token node_start_token = lex.curToken;
2648 identifierWithDefTemplateArg *lhs;
2651 panic(lex.line, lex.col,
"expected identifier with definition template arguments in type alias statement");
2658 panic(lex.line, lex.col,
"expected `=` after identifier in type alias statement");
2662 typeSpec *rhs =
nullptr;
2667 panic(lex.line, lex.col,
"expected typeSpec after `=` in type alias statement");
2670 o =
new typeAliasStmt{node_start_token, lhs, rhs};
2673 void parse(finalizerDecl *&o, lexer &lex) {
2674 lexer::token node_start_token = lex.curToken;
2682 panic(lex.line, lex.col,
"expected `(` after `finalizer` in finalizer declaration");
2687 panic(lex.line, lex.col,
"expected `)` after `finalizer` in finalizer declaration");
2690 o =
new finalizerDecl{node_start_token};
2693 void parse(finalizerDef *&o, lexer &lex) {
2694 lexer::token node_start_token = lex.curToken;
2702 panic(lex.line, lex.col,
"expected `(` after `finalizer` in finalizer definition");
2707 panic(lex.line, lex.col,
"expected `)` after `finalizer` in finalizer definition");
2710 codeBlock *block =
nullptr;
2714 panic(lex.line, lex.col,
"expected codeBlock after `finalizer` declaration");
2717 o =
new finalizerDef{node_start_token, block};
2720 void parse(funcExpr *&o, lexer &lex) {
2721 lexer::token node_start_token = lex.curToken;
2728 externModuleAccessExpression *name =
nullptr;
2736 unnamedDefinitionArguments *args =
nullptr;
2739 o =
new funcExpr{node_start_token, name,
nullptr};
2742 o =
new funcExpr{node_start_token, name, args};
2745 void parse(enumerationDefinition *&o, lexer &lex) {
2746 lexer::token node_start_token = lex.curToken;
2752 identifier *name =
nullptr;
2756 panic(lex.line, lex.col,
"expected identifier after `enum` in enumeration definition");
2762 panic(lex.line, lex.col,
"expected `{` after identifier in enumeration definition");
2766 vec<enumerationPair *> enumerators;
2767 enumerationPair *enumerator =
nullptr;
2768 parse(enumerator, lex);
2769 while (enumerator) {
2770 enumerators.push_back(enumerator);
2774 enumerator =
nullptr;
2776 parse(enumerator, lex);
2781 for (
auto e : enumerators)
2784 panic(lex.line, lex.col,
"expected `}` after enumerators in enumeration definition");
2788 o =
new enumerationDefinition{node_start_token, name, enumerators};
2791 void parse(enumerationPair *&o, lexer &lex) {
2792 lexer::token node_start_token = lex.curToken;
2793 identifier *name =
nullptr;
2800 o =
new enumerationPair{node_start_token, name, {}};
2804 lexer::token
value = lex.curToken;
2806 o =
new enumerationPair{node_start_token, name,
value};
2813 panic(lex.line, lex.col,
"expected integer literal after `-` in enumeration pair");
2816 value = lex.curToken;
2818 o =
new enumerationPair{node_start_token, name,
value};
2823 panic(lex.line, lex.col,
"expected integer literal after `=` in enumeration pair");
2828 void parse(bracedInitalizerList *&o, lexer &lex) {
2836 vec<rExpr *> expressions;
2837 rExpr *expression =
nullptr;
2838 parse(expression, lex);
2839 while (expression) {
2840 expressions.push_back(expression);
2844 expression =
nullptr;
2846 parse(expression, lex);
2851 for (
auto e : expressions)
2858 o =
new bracedInitalizerList{node_start_token, expressions};
2861 void parse(yieldStmt *&o, lexer &lex) {
2868 rExpr *expr =
nullptr;
2872 panic(lex.line, lex.col,
"expected rExpr after `yield` in yieldStmt");
2875 o =
new yieldStmt{node_start_token, expr};
2878 void parse(decltypeExpr *&o, lexer &lex) {
2879 lexer::token node_start_token{lex.curToken};
2889 yoi_assert(expr, lex.line, lex.col,
"expected expression after `(` for decltype-expression");
2893 panic(lex.line, lex.col,
"expected `)` after expression");
2896 o =
new decltypeExpr{node_start_token, expr};
2899 void parse(satisfyStmt *&o, lexer &lex) {
2906 externModuleAccessExpression *emae =
nullptr;
2910 panic(lex.line, lex.col,
"expected externModuleAccessExpression after `satisfy` in satisfyStmt");
2913 o =
new satisfyStmt{node_start_token, emae};
2916 void parse(conceptStmt *&o, lexer &lex) {
2934 void parse(conceptDefinition *&o, lexer &lex) {
2942 lexer::token name{};
2945 name = lex.curToken;
2952 typeParams.push_back(lex.curToken);
2967 identifierWithTypeSpec *spec{};
2970 specs.push_back(spec);
2984 for (
auto s : specs)
2986 panic(lex.line, lex.col,
"expected `{` after `)`");
2992 conceptStmt *stmt{};
2995 conceptStmts.push_back(stmt);
3002 o =
new conceptDefinition{node_start_token, name, typeParams, specs, conceptStmts};
3005 void parse(satisfyClause *&o, lexer &lex) {
3010 lexer::token node_start_token = lex.curToken;
3016 externModuleAccessExpression *spec{};
3019 specs.push_back(spec);
3030 for (
auto s : specs)
3032 panic(lex.line, lex.col,
"expected `)` after specs");
3036 o =
new satisfyClause{node_start_token, specs};
3039 void parse(lambdaCapture *&o, lexer &lex) {
3040 lexer::token node_start_token = lex.curToken;
3055 identifier *name =
nullptr;
3062 o =
new lambdaCapture{node_start_token, mod, name};
3066#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