scriptlang: more work on parser
This commit is contained in:
parent
04a8fdc4c3
commit
65fbfd26e2
@ -12,6 +12,7 @@ enum class Errors {
|
|||||||
ParserExhausted,
|
ParserExhausted,
|
||||||
ParserMalformedStringLiteral,
|
ParserMalformedStringLiteral,
|
||||||
ParserStructNotTerminated,
|
ParserStructNotTerminated,
|
||||||
|
ParserStructExpectedId,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
namespace scriptlang {
|
namespace scriptlang {
|
||||||
|
|
||||||
auto parse_expression(bool strictly_values) noexcept
|
auto Parser::parse_expression(bool strictly_values) noexcept
|
||||||
-> Result<std::unique_ptr<Expression>, Errors>
|
-> Result<std::unique_ptr<Expression>, Errors>
|
||||||
{
|
{
|
||||||
if (strictly_values)
|
if (strictly_values)
|
||||||
return parse_expression(true);
|
return parse_struct(true);
|
||||||
return Errors::NotImplemented;
|
return Errors::NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +20,12 @@ auto Parser::parse_struct(bool strictly_values) noexcept
|
|||||||
auto first_brace = TRY(lexer.peek());
|
auto first_brace = TRY(lexer.peek());
|
||||||
if (TRY(lexer.peek()).type == Tokens::LBrace) {
|
if (TRY(lexer.peek()).type == Tokens::LBrace) {
|
||||||
TRY(lexer.next());
|
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());
|
auto last_brace = TRY(lexer.peek());
|
||||||
if (last_brace.type != Tokens::RBrace)
|
if (last_brace.type != Tokens::RBrace)
|
||||||
return Errors::ParserStructNotTerminated;
|
return Errors::ParserStructNotTerminated;
|
||||||
|
Loading…
Reference in New Issue
Block a user