parseLiteral function
Implementation
ValueIndex<LiteralNode>? parseLiteral(
String input, List<Token> tokenList, int index, Settings settings) {
// literal: STRING | NUMBER | TRUE | FALSE | NULL
final token = tokenList[index];
dynamic value;
switch (token.type) {
case TokenType.STRING:
{
value = parseString(safeSubstring(
input, token.loc!.start.offset! + 1, token.loc!.end.offset! - 1));
break;
}
case TokenType.NUMBER:
{
value = int.tryParse(token.value!);
value ??= double.tryParse(token.value!);
break;
}
case TokenType.TRUE:
{
value = true;
break;
}
case TokenType.FALSE:
{
value = false;
break;
}
case TokenType.NULL:
{
value = null;
break;
}
default:
{
return null;
}
}
var literal = LiteralNode(value, token.value);
if (settings.loc) {
literal = literal.copyWith(loc: token.loc);
}
return ValueIndex(literal, index + 1);
}