Line data Source code
1 : #include "../../../../inc/parsingAnalysis/algorithm/topDown.h"
2 :
3 : namespace nicole {
4 :
5 : const std::expected<std::shared_ptr<AST>, Error>
6 0 : TopDown::parseAssignment(const bool insideFor) const noexcept {
7 0 : const auto firsToken{tkStream_.current()};
8 0 : const auto left{parseOr()};
9 0 : if (!left || !*left) {
10 0 : return createError(left ? Error{ERROR_TYPE::NULL_NODE, "left is null"}
11 0 : : left.error());
12 0 : }
13 0 : const Token token{*tkStream_.current()};
14 0 : if (insideFor and
15 0 : (token.type() == TokenType::COMMA or token.type() == TokenType::RP)) {
16 0 : return left;
17 0 : }
18 0 : if (auto res = tryEat(); !res) {
19 0 : return createError(res.error());
20 0 : }
21 0 : const auto value{parseOr()};
22 0 : if (!value || !*value) {
23 0 : return createError(value ? Error{ERROR_TYPE::NULL_NODE, "left is null"}
24 0 : : value.error());
25 0 : }
26 :
27 0 : std::expected<std::shared_ptr<AST>, Error> operation{
28 0 : Builder::createAssignment(
29 0 : SourceLocation{*firsToken, *tkStream_.lastRead()}, token, *left,
30 0 : *value)};
31 :
32 0 : if (!operation || !*operation) {
33 0 : return createError(operation ? Error{ERROR_TYPE::NULL_NODE, "right is null"}
34 0 : : operation.error());
35 0 : }
36 :
37 0 : if (!insideFor and tkStream_.current()->type() != TokenType::SEMICOLON) {
38 0 : return createError(ERROR_TYPE::SINTAX,
39 0 : "Expected ';' at the end of assigment expression at " +
40 0 : token.locInfo());
41 0 : }
42 :
43 0 : return operation;
44 0 : }
45 :
46 : } // namespace nicole
|