Optional ergonomics

This commit is contained in:
Kampfkarren 2022-07-27 16:40:43 -07:00
parent 8dcbebaa70
commit 310adedc90

View file

@ -595,9 +595,7 @@ const Lexeme Lexer::nextInterpolatedString()
Position start = position(); Position start = position();
unsigned int startOffset = offset; unsigned int startOffset = offset;
std::optional<Lexeme> readSectionOpt = readInterpolatedStringSection(start, Lexeme::InterpStringMid); if (auto readSection = readInterpolatedStringSection(start, Lexeme::InterpStringMid))
if (auto readSection = readSectionOpt)
{ {
lexeme = *readSection; lexeme = *readSection;
return lexeme; return lexeme;
@ -635,7 +633,7 @@ std::optional<Lexeme> Lexer::readInterpolatedStringSection(Position start, Lexem
case 0: case 0:
case '\r': case '\r':
case '\n': case '\n':
return std::optional(Lexeme(Location(start, position()), Lexeme::BrokenString)); return Lexeme(Location(start, position()), Lexeme::BrokenString);
case '\\': case '\\':
readBackslashInString(); readBackslashInString();
@ -645,12 +643,12 @@ std::optional<Lexeme> Lexer::readInterpolatedStringSection(Position start, Lexem
{ {
if (peekch(1) == '{') 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); auto lexemeOutput = Lexeme(Location(start, position()), Lexeme::InterpStringBegin, &buffer[startOffset], offset - startOffset);
consume(); consume();
return std::optional(lexemeOutput); return lexemeOutput;
} }
default: default: