diff --git a/scriptlang/error.hpp b/scriptlang/error.hpp index 7e84f29..dccb9f5 100644 --- a/scriptlang/error.hpp +++ b/scriptlang/error.hpp @@ -12,6 +12,7 @@ enum class Errors { ParserExhausted, ParserMalformedStringLiteral, ParserStructNotTerminated, + ParserStructExpectedId, }; } diff --git a/scriptlang/parser.cpp b/scriptlang/parser.cpp index f98e09a..95d4ad6 100644 --- a/scriptlang/parser.cpp +++ b/scriptlang/parser.cpp @@ -5,11 +5,11 @@ namespace scriptlang { -auto parse_expression(bool strictly_values) noexcept +auto Parser::parse_expression(bool strictly_values) noexcept -> Result, Errors> { if (strictly_values) - return parse_expression(true); + return parse_struct(true); return Errors::NotImplemented; } @@ -20,6 +20,12 @@ auto Parser::parse_struct(bool strictly_values) noexcept auto first_brace = TRY(lexer.peek()); if (TRY(lexer.peek()).type == Tokens::LBrace) { TRY(lexer.next()); + if (TRY(lexer.peek()).type != Tokens::Eof + && TRY(lexer.peek()).type != Tokens::LBrace) { + if (!(TRY(lexer.peek()).type != Tokens::Id)) { + return Errors::ParserStructExpectedId; + } + } auto last_brace = TRY(lexer.peek()); if (last_brace.type != Tokens::RBrace) return Errors::ParserStructNotTerminated;