scriptlang: more work on parser

This commit is contained in:
SimonFJ20 2023-01-11 11:52:15 +01:00
parent 04a8fdc4c3
commit 65fbfd26e2
2 changed files with 9 additions and 2 deletions

View File

@ -12,6 +12,7 @@ enum class Errors {
ParserExhausted,
ParserMalformedStringLiteral,
ParserStructNotTerminated,
ParserStructExpectedId,
};
}

View File

@ -5,11 +5,11 @@
namespace scriptlang {
auto parse_expression(bool strictly_values) noexcept
auto Parser::parse_expression(bool strictly_values) noexcept
-> Result<std::unique_ptr<Expression>, 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;