//not_test: 'not' not_test | comparison private Expression ParseNotTest() { if (MaybeEat(TokenKind.KeywordNot)) { var start = GetStart(); Expression ret = new UnaryExpression(PythonOperator.Not, ParseNotTest()); ret.SetLoc(_globalParent, start, GetEnd()); return ret; } else { return ParseComparison(); } }
// factor: ('+'|'-'|'~') factor | power private Expression ParseFactor() { var start = _lookahead.Span.Start; Expression ret; switch (PeekToken().Kind) { case TokenKind.Add: NextToken(); ret = new UnaryExpression(PythonOperator.Pos, ParseFactor()); break; case TokenKind.Subtract: NextToken(); ret = FinishUnaryNegate(); break; case TokenKind.Twiddle: NextToken(); ret = new UnaryExpression(PythonOperator.Invert, ParseFactor()); break; default: return ParsePower(); } ret.SetLoc(_globalParent, start, GetEnd()); return ret; }
// factor: ('+'|'-'|'~') factor | power private Expression ParseFactor() { Token t = PeekToken(); Location start = GetStart(); Expression ret; switch (t.Kind) { case TokenKind.Add: NextToken(); ret = new UnaryExpression(PythonOperator.Pos, ParseFactor()); break; case TokenKind.Subtract: NextToken(); ret = FinishUnaryNegate(); break; case TokenKind.Twiddle: NextToken(); ret = new UnaryExpression(PythonOperator.Invert, ParseFactor()); break; default: return ParsePower(); } ret.SetLoc(GetExternal(), start, GetEnd()); return ret; }