From 4fa72c045963ad63b2d9040361d8d85f223abe9c Mon Sep 17 00:00:00 2001 From: Username404 Date: Sat, 16 Jul 2022 12:36:39 +0200 Subject: [PATCH] Parser.hpp: Parse properties and methods Signed-off-by: Username404 --- src/headers/parsing/Parser.hpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/headers/parsing/Parser.hpp b/src/headers/parsing/Parser.hpp index 1f1788e..e953378 100644 --- a/src/headers/parsing/Parser.hpp +++ b/src/headers/parsing/Parser.hpp @@ -26,7 +26,9 @@ namespace Parser { const auto nextIterator = iterator + 1; if (nextIterator->toktype == tok::COMMA) { tokens.erase(nextIterator); - } else throw ParsingException("Missing comma after \"" + iterator->toktext + '"'); + } else if (nextIterator->toktype != tok::DOT && iterator->toktype != tok::DOT) { + throw ParsingException("Missing comma after \"" + iterator->toktext + '"'); + } } } } @@ -111,9 +113,17 @@ namespace Parser { }); parseTree << Define(isFinalDefine, current.toktext, parse(beginning, end)); i += 1 + isFinalDefine + distance(beginning, end); - } else if (next.toktype == LPAR) { - parseTree << Call(current.toktext); - } else parseTree << Reference(current.toktext); + } else { + const bool method = nextAre({DOT, IDENTIFIER, LPAR}); + const bool property = not method && nextAre({DOT, IDENTIFIER}); + const string name = property or method ? current.toktext + '.' + lexed[i + 2].toktext : current.toktext; + if (method or next.toktype == LPAR) { + parseTree << Call(name); + } else if (property) { + parseTree << Reference(name); + } + if (property or method) i += 2; + } } } case SEMICOLON: break;