Ejemplo n.º 1
0
 public virtual T Visit(BindingParserNode node)
 {
     if (node is ArrayAccessBindingParserNode)
     {
         return(VisitArrayAccess((ArrayAccessBindingParserNode)node));
     }
     else if (node is BinaryOperatorBindingParserNode)
     {
         return(VisitBinaryOperator((BinaryOperatorBindingParserNode)node));
     }
     else if (node is ConditionalExpressionBindingParserNode)
     {
         return(VisitConditionalExpression((ConditionalExpressionBindingParserNode)node));
     }
     else if (node is FunctionCallBindingParserNode)
     {
         return(VisitFunctionCall((FunctionCallBindingParserNode)node));
     }
     else if (node is IdentifierNameBindingParserNode)
     {
         return(VisitIdentifierName((IdentifierNameBindingParserNode)node));
     }
     else if (node is LiteralExpressionBindingParserNode)
     {
         return(VisitLiteralExpression((LiteralExpressionBindingParserNode)node));
     }
     else if (node is MemberAccessBindingParserNode)
     {
         return(VisitMemberAccess((MemberAccessBindingParserNode)node));
     }
     else if (node is ParenthesizedExpressionBindingParserNode)
     {
         return(VisitParenthesizedExpression((ParenthesizedExpressionBindingParserNode)node));
     }
     else if (node is UnaryOperatorBindingParserNode)
     {
         return(VisitUnaryOperator((UnaryOperatorBindingParserNode)node));
     }
     else
     {
         throw new NotSupportedException($"The node of type {node.GetType()} is not supported!");
     }
 }
 public MemberAccessBindingParserNode(BindingParserNode targetExpression, IdentifierNameBindingParserNode memberNameExpression)
 {
     TargetExpression     = targetExpression;
     MemberNameExpression = memberNameExpression;
 }
Ejemplo n.º 3
0
 public ConditionalExpressionBindingParserNode(BindingParserNode conditionExpression, BindingParserNode trueExpression, BindingParserNode falseExpression)
 {
     ConditionExpression = conditionExpression;
     TrueExpression      = trueExpression;
     FalseExpression     = falseExpression;
 }
 public FunctionCallBindingParserNode(BindingParserNode targetExpression, List <BindingParserNode> argumentExpressions)
 {
     TargetExpression    = targetExpression;
     ArgumentExpressions = argumentExpressions;
 }
Ejemplo n.º 5
0
 protected virtual T DefaultVisit(BindingParserNode node)
 {
     throw new NotImplementedException("The visitor implementation should implement this method!");
 }
 public UnaryOperatorBindingParserNode(BindingParserNode innerExpression, BindingTokenType @operator)
 {
     InnerExpression = innerExpression;
     Operator        = @operator;
 }
Ejemplo n.º 7
0
 public ParenthesizedExpressionBindingParserNode(BindingParserNode innerExpression)
 {
     InnerExpression = innerExpression;
 }
Ejemplo n.º 8
0
 public ArrayAccessBindingParserNode(BindingParserNode targetExpression, BindingParserNode arrayIndexExpression)
 {
     TargetExpression     = targetExpression;
     ArrayIndexExpression = arrayIndexExpression;
 }
Ejemplo n.º 9
0
        private BindingParserNode ReadIdentifierExpression()
        {
            BindingParserNode expression = ReadAtomicExpression();

            var next = Peek();

            while (next != null)
            {
                var startIndex = CurrentIndex;
                if (next.Type == BindingTokenType.Dot)
                {
                    // member access
                    Read();
                    var member = ReadIdentifierNameExpression();
                    expression = CreateNode(new MemberAccessBindingParserNode(expression, member), startIndex);
                }
                else if (next.Type == BindingTokenType.OpenParenthesis)
                {
                    // function call
                    Read();
                    var arguments = new List <BindingParserNode>();
                    while (Peek() != null && Peek().Type != BindingTokenType.CloseParenthesis)
                    {
                        if (arguments.Count > 0)
                        {
                            SkipWhiteSpace();
                            if (IsCurrentTokenIncorrect(BindingTokenType.Comma))
                            {
                                arguments.Add(CreateNode(new LiteralExpressionBindingParserNode(null), CurrentIndex, "The ',' was expected"));
                            }
                            else
                            {
                                Read();
                            }
                        }
                        arguments.Add(ReadExpression());
                    }
                    var error = IsCurrentTokenIncorrect(BindingTokenType.CloseParenthesis);
                    Read();
                    SkipWhiteSpace();
                    expression = CreateNode(new FunctionCallBindingParserNode(expression, arguments), startIndex, error ? "The ')' was expected." : null);
                }
                else if (next.Type == BindingTokenType.OpenArrayBrace)
                {
                    // array access
                    Read();
                    var innerExpression = ReadExpression();
                    var error           = IsCurrentTokenIncorrect(BindingTokenType.CloseArrayBrace);
                    Read();
                    SkipWhiteSpace();
                    expression = CreateNode(new ArrayAccessBindingParserNode(expression, innerExpression), startIndex, error ? "The ']' was expected." : null);
                }
                else
                {
                    break;
                }

                next = Peek();
            }
            return(expression);
        }
 public BinaryOperatorBindingParserNode(BindingParserNode firstExpression, BindingParserNode secondExpression, BindingTokenType @operator)
 {
     FirstExpression  = firstExpression;
     SecondExpression = secondExpression;
     Operator         = @operator;
 }