Ejemplo n.º 1
0
        private bool BuildConfigurationAttribute(Expression node, Expression value,
                                                 HashLiteralExpression configuration)
        {
            ArrayLiteralExpression attributes;

            if (MacroHelper.IsCompoundAssignment(value, out attributes))
            {
                // @attrib1=value1, attrib2=value2: Multiple attributes

                foreach (var attribute in attributes.Items)
                {
                    if (attribute == attributes.Items[0])
                    {
                        configuration.Items.Add(new ExpressionPair(node, attribute));
                    }
                    else if (BuildAttribute(attribute, configuration) == false)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                // @attrib=value: Single attribute
                configuration.Items.Add(new ExpressionPair(node, value));
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool BuildConfigurationChild(Expression child, Expression value, ICollection <Expression> attributes)
        {
            child = EnsureUniqueChild(child);

            if (attributes != null && attributes.Count > 0)
            {
                var childAttributes = new HashLiteralExpression();
                if (value != null)
                {
                    childAttributes.Items.Add(new ExpressionPair(new StringLiteralExpression("value"), value));
                }

                // child=value, attrib2=value2: Child with attributes
                foreach (var attribute in attributes)
                {
                    if (BuildAttribute(attribute, childAttributes) == false)
                    {
                        return(false);
                    }
                }

                _configuration.Items.Add(new ExpressionPair(child, childAttributes));
            }
            else
            {
                // child=value: Child without attributes
                _configuration.Items.Add(new ExpressionPair(child, value ?? new StringLiteralExpression("")));
            }

            return(true);
        }
Ejemplo n.º 3
0
        private HashLiteralExpression ObtainListeners(MacroStatement macro)
        {
            var listeners       = new HashLiteralExpression();
            var componentMethod = new ComponentMethodVisitor();

            foreach (var statement in macro.Body.Statements)
            {
                var expression = statement as ExpressionStatement;
                if (expression == null || !(expression.Expression is MethodInvocationExpression))
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                var mie = (MethodInvocationExpression)expression.Expression;
                var to  = mie.Target as ReferenceExpression;
                if (to == null || mie.Arguments.Count != 1 ||
                    "to".Equals(to.Name, StringComparison.InvariantCultureIgnoreCase) == false)
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                var listener = mie.Arguments[0] as MemberReferenceExpression;
                if (listener == null || componentMethod.ExtractMethod(listener) == false)
                {
                    AddSubscriberSyntaxError(statement);
                    return(null);
                }

                listeners.Items.Add(new ExpressionPair(componentMethod.Component, componentMethod.Method));
            }

            return(listeners);
        }
Ejemplo n.º 4
0
        public override void OnHashLiteralExpression(HashLiteralExpression node)
        {
            BoundSpillSequenceBuilder builder = null;

            node.Items = VisitExpressionPairList(ref builder, node.Items);
            ReplaceCurrentNode(UpdateExpression(builder, node));
        }
Ejemplo n.º 5
0
        public override void Switch(IAstTransformer transformer, out Node resultingNode)
        {
            HashLiteralExpression thisNode           = (HashLiteralExpression)this;
            Expression            resultingTypedNode = thisNode;

            transformer.OnHashLiteralExpression(thisNode, ref resultingTypedNode);
            resultingNode = resultingTypedNode;
        }
Ejemplo n.º 6
0
 private bool Build(Block block, bool attributesOnly, CompilerErrorCollection compileErrors)
 {
     _attributesOnly = attributesOnly;
     _compileErrors  = compileErrors;
     _configuration  = new HashLiteralExpression();
     _childContext   = new Dictionary <string, object>();
     return(BuildHashConfiguration(block));
 }
Ejemplo n.º 7
0
 public override void LeaveHashLiteralExpression(HashLiteralExpression node)
 {
     foreach (ExpressionPair pair in node.Items)
     {
         CheckExpressionType(pair.First);
         CheckExpressionType(pair.Second);
     }
 }
Ejemplo n.º 8
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     Write("{");
     if (node.Items.Count > 0)
     {
         Write(" ");
         WriteCommaSeparatedList(node.Items);
         Write(" ");
     }
     Write("}");
 }
Ejemplo n.º 9
0
        private bool BuildAttribute(Expression expression, HashLiteralExpression configuration)
        {
            BinaryExpression attribute;

            if (MacroHelper.IsAssignment(expression, out attribute))
            {
                BuildConfigurationNode(attribute, true, configuration);
            }
            else
            {
                _compileErrors.Add(CompilerErrorFactory.CustomError(expression.LexicalInfo,
                                                                    "Attributes must be in the format @attrib1=value1, attrib2=value2,..."));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        private bool BuildConfigurationNode(BinaryExpression node, bool asAttribute,
                                            HashLiteralExpression configuration)
        {
            var nodeVisitor = new ConfigurationNodeVisitor();

            if (!nodeVisitor.GetNode(node.Left, asAttribute, _compileErrors))
            {
                return(false);
            }

            if (nodeVisitor.IsAttribute || asAttribute)
            {
                return(BuildConfigurationAttribute(nodeVisitor.Node, node.Right, configuration));
            }

            if ((_skip = _attributesOnly) == false)
            {
                return(BuildConfigurationChild(nodeVisitor.Node, node.Right));
            }

            return(true);
        }
Ejemplo n.º 11
0
        protected override bool ExpandExtension(ref MethodInvocationExpression extension,
                                                MacroStatement macro, MacroStatement parent,
                                                ref Statement expansion)
        {
            Expression eventName = ObtainEventName(macro);

            if (eventName == null)
            {
                AddCompilerError(macro.LexicalInfo,
                                 "A wireEvent statement must be in the form wireEvent eventName");
                return(false);
            }

            HashLiteralExpression listeners = ObtainListeners(macro);

            if (listeners != null && listeners.Items.Count > 0)
            {
                extension.Arguments.Add(eventName);
                extension.Arguments.Add(listeners);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 12
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 override public void LeaveHashLiteralExpression(HashLiteralExpression node)
 {
     OnExpression(node);
 }
Ejemplo n.º 14
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     MakeLiteralResult("Boo.Lang.Hash");
 }
Ejemplo n.º 15
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     base.OnHashLiteralExpression(node);
     Check(node);
 }