From 310adedc90fa39741eb7db30a81ea6ff4dbc1930 Mon Sep 17 00:00:00 2001 From: Kampfkarren Date: Wed, 27 Jul 2022 16:40:43 -0700 Subject: [PATCH] Optional ergonomics --- Ast/src/Lexer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Ast/src/Lexer.cpp b/Ast/src/Lexer.cpp index 92f460f6..8a369033 100644 --- a/Ast/src/Lexer.cpp +++ b/Ast/src/Lexer.cpp @@ -595,9 +595,7 @@ const Lexeme Lexer::nextInterpolatedString() Position start = position(); unsigned int startOffset = offset; - std::optional readSectionOpt = readInterpolatedStringSection(start, Lexeme::InterpStringMid); - - if (auto readSection = readSectionOpt) + if (auto readSection = readInterpolatedStringSection(start, Lexeme::InterpStringMid)) { lexeme = *readSection; return lexeme; @@ -635,7 +633,7 @@ std::optional Lexer::readInterpolatedStringSection(Position start, Lexem case 0: case '\r': case '\n': - return std::optional(Lexeme(Location(start, position()), Lexeme::BrokenString)); + return Lexeme(Location(start, position()), Lexeme::BrokenString); case '\\': readBackslashInString(); @@ -645,12 +643,12 @@ std::optional Lexer::readInterpolatedStringSection(Position start, Lexem { if (peekch(1) == '{') { - return std::optional(Lexeme(Location(start, position()), Lexeme::BrokenInterpDoubleBrace)); + return Lexeme(Location(start, position()), Lexeme::BrokenInterpDoubleBrace); } auto lexemeOutput = Lexeme(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset); consume(); - return std::optional(lexemeOutput); + return lexemeOutput; } default: