Exemplo n.º 1
0
        public static HashSet <string> FindDependencies(TexlNode node, TexlBinding binding)
        {
            var v = new DependencyFinder
            {
                _binding = binding
            };

            node.Accept(v);
            return(v._vars);
        }
Exemplo n.º 2
0
        private CheckResult CheckInternal(string expressionText, FormulaType parameterType = null, bool intellisense = false)
        {
            if (parameterType == null)
            {
                parameterType = new RecordType();
            }

            var formula = new Formula(expressionText);

            formula.EnsureParsed(TexlParser.Flags.None);

            // Ok to continue with binding even if there are parse errors.
            // We can still use that for intellisense.

            var extraFunctions = _extraFunctions.Values.ToArray();

            var resolver = new RecalcEngineResolver(this, (RecordType)parameterType, EnumStore.EnumSymbols, extraFunctions);

            // $$$ - intellisense only works with ruleScope.
            // So if running for intellisense, pass the parameters in ruleScope.
            // But if running for eval, let the resolver handle the parameters.
            // Resolver is only invoked if not in RuleScope.

            var binding = TexlBinding.Run(
                new Glue2DocumentBinderGlue(),
                formula.ParseTree,
                resolver,
                ruleScope: intellisense ? parameterType._type : null,
                useThisRecordForRuleScope: false
                );

            var errors = (formula.HasParseErrors) ? formula.GetParseErrors() : binding.ErrorContainer.GetErrors();

            var result = new CheckResult
            {
                _binding = binding,
                _formula = formula,
            };

            if (errors != null && errors.Any())
            {
                result.SetErrors(errors.ToArray());
            }
            else
            {
                result.TopLevelIdentifiers = DependencyFinder.FindDependencies(binding.Top, binding);
                // TODO: Fix FormulaType.Build to not throw exceptions for Enum types then remove this check
                if (binding.ResultType.Kind != DKind.Enum)
                {
                    result.ReturnType = FormulaType.Build(binding.ResultType);
                }
            }

            return(result);
        }