matchString method
If the current token is an identifier, advance 1 and return the original token. If not, generate an error. Note this only accept string literal but not string interpolation.
Implementation
TokenStringLiteral matchString() {
if (curTok is TokenStringLiteral) {
return advance() as TokenStringLiteral;
} else {
final err = HTError.unexpectedToken(
HTLocale.current.literalString,
curTok.lexeme,
filename: currrentFileName,
line: curTok.line,
column: curTok.column,
offset: curTok.offset,
length: curTok.length,
);
errors.add(err);
final idTok = advance();
return TokenStringLiteral(
lexeme: idTok.lexeme,
line: idTok.line,
column: idTok.column,
offset: idTok.offset,
previous: idTok.previous,
next: idTok.next,
startMark: '"',
endMark: '"',
);
}
}