primary method
Implementation
AstNode primary() {
if (match([TokenType.tartNull])) return const Literal(null);
if (match([
TokenType.integer,
TokenType.double,
TokenType.string,
TokenType.boolean
])) {
return Literal(previous().literal);
}
if (match([TokenType.identifier])) return Variable(previous());
if (match([TokenType.leftParen])) {
AstNode expr = expression();
consume(TokenType.rightParen, "Expect ')' after expression.");
return expr;
}
if (match([TokenType.assign])) {
return Assignment(previous(), peek(), expression());
}
if (match([TokenType.flutterWidget])) {
return flutterWidgetDeclaration();
}
if (match([TokenType.flutterParam])) {
return flutterParameter();
}
if (match([TokenType.leftParen])) {
return anonymousFunction();
}
if (match([TokenType.leftBracket])) {
return listOrSetLiteral();
}
if (match([TokenType.leftBrace])) {
return mapLiteral();
}
if (match([TokenType.tartToString])) {
consume(TokenType.leftParen, "Expect '(' after 'toString'.");
AstNode expr = expression();
consume(TokenType.rightParen, "Expect ')' after expression in toString.");
return ToString(expr);
}
throw error(peek(), "Expected expression.");
}