endsWithLineContinuation static method

bool endsWithLineContinuation(
  1. String sourceCode
)

Return whether the given source code ends in a token that signifies that the statement continues on the next line. That includes binary operators, open brackets or parentheses, etc.

Implementation

static bool endsWithLineContinuation(String sourceCode) {
  try {
    final lastTok = Lexer.lastToken(sourceCode);
    // Almost any token at the end will signify line continuation, except:
    switch (lastTok.type) {
      case TokenType.eol:
      case TokenType.identifier:
      case TokenType.number:
      case TokenType.rCurly:
      case TokenType.rParen:
      case TokenType.rSquare:
      case TokenType.string:
      case TokenType.unknown:
        return false;
      case TokenType.keyword:
        // of keywords, only these can cause line continuation:
        return lastTok.text == 'and' ||
            lastTok.text == 'or' ||
            lastTok.text == 'isa' ||
            lastTok.text == 'not' ||
            lastTok.text == 'new';
      default:
        return true;
    }
  } on LexerException {
    return false;
  }
}