private Expression ParsePrimary() {
Token t = PeekToken();
Expression ret;
switch (t.Kind) {
case TokenKind.LeftParenthesis: // parenth_form, generator_expression, yield_atom
NextToken();
return FinishTupleOrGenExp();
case TokenKind.LeftBracket: // list_display
NextToken();
return FinishListValue();
case TokenKind.LeftBrace: // dict_display
NextToken();
return FinishDictOrSetValue();
case TokenKind.BackQuote: // string_conversion
NextToken();
return FinishStringConversion();
case TokenKind.Name: // identifier
NextToken();
string name = (string)t.Value;
if (_sink != null) {
_sink.StartName(GetSourceSpan(), name);
}
ret = new NameExpression(FixName(name));
ret.SetLoc(_globalParent, GetStart(), GetEnd());
return ret;
case TokenKind.Constant: // literal
NextToken();
var start = GetStart();
object cv = t.Value;
string cvs = cv as string;
if (cvs != null) {
cv = FinishStringPlus(cvs);
} else {
Bytes bytes = cv as Bytes;
if (bytes != null) {
cv = FinishBytesPlus(bytes);
}
}
if (t is UnicodeStringToken) {
ret = ConstantExpression.MakeUnicode((string)cv);
} else {
ret = new ConstantExpression(cv);
}
ret.SetLoc(_globalParent, start, GetEnd());
return ret;
default:
ReportSyntaxError(_lookahead.Token, _lookahead.Span, ErrorCodes.SyntaxError, _allowIncomplete || _tokenizer.EndContinues);
// error node
ret = new ErrorExpression();
ret.SetLoc(_globalParent, _lookahead.Span.Start, _lookahead.Span.End);
return ret;
}
}