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);
        }
        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);
        }
Example #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);
        }
Example #4
0
        public override void OnHashLiteralExpression(HashLiteralExpression node)
        {
            BoundSpillSequenceBuilder builder = null;

            node.Items = VisitExpressionPairList(ref builder, node.Items);
            ReplaceCurrentNode(UpdateExpression(builder, node));
        }
Example #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;
        }
 private bool Build(Block block, bool attributesOnly, CompilerErrorCollection compileErrors)
 {
     _attributesOnly = attributesOnly;
     _compileErrors  = compileErrors;
     _configuration  = new HashLiteralExpression();
     _childContext   = new Dictionary <string, object>();
     return(BuildHashConfiguration(block));
 }
Example #7
0
 public override void LeaveHashLiteralExpression(HashLiteralExpression node)
 {
     foreach (ExpressionPair pair in node.Items)
     {
         CheckExpressionType(pair.First);
         CheckExpressionType(pair.Second);
     }
 }
Example #8
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     Write("{");
     if (node.Items.Count > 0)
     {
         Write(" ");
         WriteCommaSeparatedList(node.Items);
         Write(" ");
     }
     Write("}");
 }
        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);
        }
        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);
        }
Example #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);
        }
Example #12
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     throw new NotImplementedException();
 }
Example #13
0
 override public void LeaveHashLiteralExpression(HashLiteralExpression node)
 {
     OnExpression(node);
 }
Example #14
0
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     MakeLiteralResult("Boo.Lang.Hash");
 }
 public override void OnHashLiteralExpression(HashLiteralExpression node)
 {
     base.OnHashLiteralExpression(node);
     Check(node);
 }