stringValue property
For symbol and keyword tokens, returns the string value represented by this
token. For StringToken
s this method returns null
.
For SymbolToken
s and KeywordToken
s, 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
@override
String? get stringValue => type.stringValue;