protected bool EnsureAssignment(Expression expression,
                                 out BinaryExpression assignment)
 {
     if (!MacroHelper.IsAssignment(expression, out assignment))
     {
         AddCompilerError(expression.LexicalInfo, GetType().Name +
                          " properties must be in the format of name1=value2,name2=value2,...");
         return(false);
     }
     return(true);
 }
        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);
        }
        protected bool PropertiesToExpressionPairs(Expression expression,
                                                   ExpressionPairCollection pairs)
        {
            BinaryExpression assignment;

            if (!EnsureAssignment(expression, out assignment))
            {
                return(false);
            }

            ArrayLiteralExpression properties;

            if (MacroHelper.IsCompoundAssignment(assignment.Right, out properties))
            {
                foreach (Expression item in properties.Items)
                {
                    if (item == properties.Items[0])
                    {
                        pairs.Add(new ExpressionPair(assignment.Left, item));
                    }
                    else
                    {
                        BinaryExpression property;
                        if (!EnsureAssignment(item, out property))
                        {
                            return(false);
                        }

                        pairs.Add(new ExpressionPair(property.Left, property.Right));
                    }
                }
            }
            else
            {
                pairs.Add(new ExpressionPair(assignment.Left, assignment.Right));
            }

            return(true);
        }
Beispiel #4
0
        private bool BuildConfigurationChild(MethodInvocationExpression child)
        {
            Block                    configBlock;
            List <Expression>        attributes  = new List <Expression>();
            ConfigurationNodeVisitor nodeVisitor = new ConfigurationNodeVisitor();

            if (!nodeVisitor.GetNode(child, _compileErrors))
            {
                return(false);
            }

            if (!MacroHelper.IsNewBlock(child, out configBlock))
            {
                attributes.AddRange(child.Arguments);

                return(BuildConfigurationChild(nodeVisitor.Node, null, attributes));
            }
            else
            {
                if (configBlock.HasStatements)
                {
                    HashConfigurationBuilder nested = new HashConfigurationBuilder();
                    if (nested.BuildConfig(configBlock, _compileErrors) &&
                        nested.HasConfiguration)
                    {
                        _configuration.Items.Add(new ExpressionPair(nodeVisitor.Node,
                                                                    nested.HashConfiguration));
                        return(true);
                    }
                }
                else
                {
                    return(BuildConfigurationChild(nodeVisitor.Node, null, null));
                }
            }

            return(false);
        }
        private bool BuildConfigurationChild(Expression node, Expression value)
        {
            ArrayLiteralExpression attribs;
            List <Expression>      attributes = null;

            if (MacroHelper.IsCompoundAssignment(value, out attribs))
            {
                attributes = new List <Expression>();

                foreach (var attribute in attribs.Items)
                {
                    if (attribute == attribs.Items[0])
                    {
                        value = attribute;
                    }
                    else
                    {
                        attributes.Add(attribute);
                    }
                }
            }

            return(BuildConfigurationChild(node, value, attributes));
        }
 public override void OnBinaryExpression(BinaryExpression node)
 {
     _found   = true;
     _applied = MacroHelper.IsAssignment(node, out node) &&
                BuildConfigurationNode(node, false);
 }