Esempio n. 1
0
        /// <summary>
        /// This method receives a test case string, along with an optional context type that defines the valid
        /// names and types in the expression and invokes Intellisense.Suggest on it, and returns a the result
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="contextTypeString"></param>
        /// <returns></returns>
        internal IIntellisenseResult Suggest(string expression, string contextTypeString = null)
        {
            Assert.NotNull(expression);

            var cursorMatches = Regex.Matches(expression, @"\|");

            Assert.True(cursorMatches.Count == 1, "Invalid cursor.  Exactly one cursor must be specified.");
            var cursorPosition = cursorMatches.First().Index;

            expression = expression.Replace("|", string.Empty);

            RecordType contextType;

            if (contextTypeString != null)
            {
                DType.TryParse(contextTypeString, out var contextDType);
                contextType = FormulaType.Build(contextDType) as RecordType;

                Assert.True(contextType != null, "Context type must be a record type");
            }
            else
            {
                // We leave the context type as an empty record when none is provided
                contextType = new RecordType();
            }

            return(Suggest(expression, contextType, cursorPosition));
        }
Esempio n. 2
0
        /// <returns>
        /// A mapping of enum identifier to containing enum type containing all enums within
        /// <see cref="_enums"/> and <see cref="_customEnumDict"/>.
        /// </returns>
        private static Dictionary <string, DType> RegenerateEnumTypes()
        {
            var enumTypes = _enums.ToDictionary(enumSpec => enumSpec.Key, enumSpec =>
            {
                DType.TryParse(enumSpec.Value, out var type).Verify();
                return(type);
            });

            // For custom enums, the value by which we identify their type may be different than the value
            // that we use to identify their spec, so we need a separate loop for them.
            foreach (var enumSpec in _customEnumDict.Values)
            {
                Contracts.Assert(DName.IsValidDName(enumSpec.Item1));
                Contracts.Assert(DName.IsValidDName(enumSpec.Item2));

                DType type;
                if (!enumTypes.TryGetValue(enumSpec.Item1, out type))
                {
                    DType.TryParse(enumSpec.Item3, out type).Verify();
                    enumTypes[enumSpec.Item2] = type;
                }
            }

            return(enumTypes);
        }
Esempio n. 3
0
        internal static DType GetEnum(string name)
        {
            Contracts.AssertValue(name);

            string enumString;

            TryGetEnumSpec(name, out enumString);
            Contracts.AssertValue(enumString, nameof(enumString));

            DType enumKind;

            DType.TryParse(enumString, out enumKind);
            Contracts.AssertValue(enumKind, nameof(enumKind));
            return(enumKind);
        }