Exemplo n.º 1
0
        private Expression CreateBuilderIfNeeded(MethodInvocationExpression child, string name)
        {
            int argsCount = child.Arguments.Count;

            if (argsCount >= 1)
            {
                ReferenceExpression builder = child.Arguments[0] as ReferenceExpression;
                if (builder != null)
                {
                    Block block;
                    if (argsCount > 2 || (argsCount == 2 && !MacroHelper.IsNewBlock(child, out block)))
                    {
                        _compileErrors.Add(CompilerErrorFactory.CustomError(
                                               child.Arguments[0].LexicalInfo,
                                               "Builder syntax must be in the format builder, prop: value,..."));
                        return(null);
                    }

                    MethodInvocationExpression builderCtor = new MethodInvocationExpression(builder);
                    builderCtor.Arguments.Add(new StringLiteralExpression(name));
                    builderCtor.NamedArguments.Extend(child.NamedArguments);
                    return(builderCtor);
                }
            }

            return(new StringLiteralExpression(name));
        }
Exemplo n.º 2
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);
        }