public static void PrintPostfixUnaryOperatorExpression(PrintState s, PostfixUnaryOperatorExpression a) { PrintLine(s, "PostfixUnaryOperatorExpression"); Indent(s); PrintDescWithAny(s, "Op", a.Op); PrintDescWithAny(s, "Expr", a.Expr); UnIndent(s); }
public static object ParseExpressionTail(ParserState s, object lhs, int minLevel, bool allowStructInitializer) { while (true) { if (s.Token.Type == TokenType.OpenParen && minLevel <= 25) { var result = new CallExpression { Target = lhs, Args = new List <object>() }; ReadToken(s); while (s.Token.Type != TokenType.CloseParen) { result.Args.Add(ParseExpression(s, 0, true)); if (s.Token.Type == TokenType.CloseParen) { break; } ParseTokenWithType(s, TokenType.Comma); } ParseTokenWithType(s, TokenType.CloseParen); lhs = result; } else if (s.Token.Type == TokenType.OpenBracket && minLevel <= 25) { var result = new IndexExpression { Target = lhs }; ReadToken(s); result.Arg = ParseExpression(s, 0, true); ParseTokenWithType(s, TokenType.CloseBracket); lhs = result; } else if (s.Token.Type == TokenType.OpenAngleBracket && (lhs is Token || lhs is DotExpression) && minLevel <= 25) { if (lhs is Token) { var token = (Token)lhs; if (IsProbablyANamespace(token.Value)) { lhs = ParseTypeArgsExpressionTail(s, token); } else { s.Token.Type = TokenType.Operator; } } else { var e = (DotExpression)lhs; var exLhs = e.Lhs; if (exLhs is Token && IsProbablyANamespace(((Token)exLhs).Value)) { lhs = ParseTypeArgsExpressionTail(s, e); } else { s.Token.Type = TokenType.Operator; } } } else if (s.Token.Type == TokenType.OpenBrace && minLevel <= 25 && allowStructInitializer) { if ((lhs is Token && ((Token)lhs).Type == TokenType.Identifier) || lhs is TypeModifierExpression || lhs is TypeArgsExpression) { var result = new StructInitializerExpression { Target = lhs, Args = new List <FieldInitializerExpression>() }; ReadToken(s); while (s.Token.Type != TokenType.CloseBrace) { var fie = new FieldInitializerExpression { FieldName = ParseTokenWithType(s, TokenType.Identifier) }; ReadToken(s); fie.Expr = ParseExpression(s, 0, true); result.Args.Add(fie); if (s.Token.Type == TokenType.CloseBrace) { break; } ParseTokenWithType(s, TokenType.Comma); } ParseTokenWithType(s, TokenType.CloseBrace); lhs = result; } else { return(lhs); } } else if (s.Token.Type == TokenType.CloseAngleBracket) { s.Token.Type = TokenType.Operator; } else if (s.Token.Type == TokenType.Operator) { var level = GetBindingLevel(s.Token.Value); if (level < minLevel) { return(lhs); } if (s.Token.Value == "?") { var result = new TernaryOperatorExpression { ConditionExpr = lhs }; ReadToken(s); result.First = ParseExpression(s, 10, allowStructInitializer); ParseTokenWithType(s, TokenType.Colon); result.Second = ParseExpression(s, 10, allowStructInitializer); lhs = result; } else if (s.Token.Value == "^") { var result = new PostfixUnaryOperatorExpression { Expr = lhs }; result.Op = s.Token; ReadToken(s); lhs = result; } else if (s.Token.Value == ".") { var result = new DotExpression { Lhs = lhs }; ReadToken(s); if (s.Token.Type == TokenType.Identifier) { result.Rhs = s.Token; ReadToken(s); } lhs = result; } else if (level >= 0) { var result = new BinaryOperatorExpression { Lhs = lhs }; result.Op = s.Token; ReadToken(s); result.Rhs = ParseExpression(s, level + 1, allowStructInitializer); lhs = result; } else { return(lhs); } } else { return(lhs); } } }
public static void CheckPostfixUnaryOperatorExpression(RangeFinderState s, PostfixUnaryOperatorExpression a) { CheckAny(s, a.Expr); CheckToken(s, a.Op); }