stringValue property

String stringValue

For symbol and keyword tokens, returns the string value represented by this token. For StringTokens this method returns null.

For SymbolTokens and KeywordTokens, the string value is a compile-time constant originating in the TokenType or in the Keyword instance. This allows testing for keywords and symbols using identical, e.g., identical('class', token.value).

Note that returning null for string tokens is important to identify symbols and keywords, we cannot use lexeme instead. The string literal "$a($b" produces ..., SymbolToken($), StringToken(a), StringToken((), ...

After parsing the identifier 'a', the parser tests for a function declaration using identical(next.stringValue, '('), which (rightfully) returns false because stringValue returns null.

Implementation

String get stringValue;