Exemplo n.º 1
0
        static IEnumerable <string> GetDependencies(TemplateToken token, AnalysisContext context)
        {
            if (token is TextToken)
            {
                yield break;
            }

            var st = token as SubstitutionToken;

            if (st != null)
            {
                foreach (var symbol in GetSymbols(st.Expression))
                {
                    yield return(context.Expand(symbol));
                }
                yield break;
            }

            var ct = token as ConditionalToken;

            if (ct != null)
            {
                yield return(context.Expand(ct.Token.LeftSide));

                var exp = ct.Token as ConditionalSymbolExpressionToken;
                if (exp != null)
                {
                    yield return(context.Expand(exp.RightSide));
                }
                foreach (var templateDependency in GetDependencies(ct.TruthyTemplate.Concat(ct.FalsyTemplate), context))
                {
                    yield return(templateDependency);
                }
                yield break;
            }

            var rt = token as RepetitionToken;

            if (rt != null)
            {
                var ctx = context.BeginChild(rt.Enumerator, rt.Collection);
                foreach (var dependency in GetDependencies(rt.Template, ctx))
                {
                    yield return(dependency);
                }

                yield break;
            }

            throw new NotImplementedException("Unknown token type: " + token);
        }
Exemplo n.º 2
0
        public IEnumerable <SymbolExpressionStep> Expand(IEnumerable <SymbolExpressionStep> expression)
        {
            var nodes = expression.ToArray();

            if (nodes.FirstOrDefault() is Identifier first &&
                string.Equals(first.Text, identifier.Text, StringComparison.OrdinalIgnoreCase))
            {
                nodes = expansion.Steps.Concat(new[] { new DependencyWildcard() }).Concat(nodes.Skip(1)).ToArray();
            }

            nodes = parent.Expand(nodes).ToArray();

            return(nodes);
        }
Exemplo n.º 3
0
        public IEnumerable <SymbolExpressionStep> Expand(IEnumerable <SymbolExpressionStep> expression)
        {
            var nodes = expression;
            var first = nodes.FirstOrDefault() as Identifier;

            if (identifier != null && first != null && string.Compare(first.Text, identifier.Text, StringComparison.OrdinalIgnoreCase) == 0)
            {
                nodes = expansion.Steps.Concat(new [] { new DependencyWildcard() }).Concat(nodes.Skip(1));
            }

            if (parent != null)
            {
                nodes = parent.Expand(nodes);
            }

            return(nodes);
        }