string method
Implementation
void string(String c) {
bool interplote = false;
while (peek() != c && !isAtEnd()) {
if (peek() == '\n') line++;
if (peek() == '\$') {
advance();
if (peek() == '{') {
if (interplote == true) {
addToken(TokenType.PLUS);
}
if (current - start > 2) {
addToken1(
TokenType.STRING, source.substring(start + 1, current - 1));
addToken(TokenType.PLUS);
}
interplote = true;
addToken(TokenType.LEFT_PAREN);
advance();
var tolerance = 1;
// while (peek() != '}' && !isAtEnd()) {
while (!isAtEnd()) {
if (peek() == '{') {
tolerance++;
}
start = current;
scanToken();
if (peek() == '}') {
tolerance--;
if (tolerance == 0) {
break;
}
}
}
if (peek() == '}') {
addToken(TokenType.RIGHT_PAREN);
addToken(TokenType.DOT);
addToken2(TokenType.IDENTIFIER, "toString");
start = current;
advance();
} else {
error(line, "Unterminated expression in string interpolation.");
}
}
} else {
advance();
}
}
if (isAtEnd()) {
error(line, "Unterminated string.");
return;
}
advance();
if (interplote) {
addToken(TokenType.PLUS);
}
addToken1(TokenType.STRING, source.substring(start + 1, current - 1));
}