From 65fbfd26e2d1ec7fa7d959acc48fb1417882826f Mon Sep 17 00:00:00 2001 From: SimonFJ20 Date: Wed, 11 Jan 2023 11:52:15 +0100 Subject: [PATCH] scriptlang: more work on parser --- scriptlang/error.hpp | 1 + scriptlang/parser.cpp | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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;