예제 #1
0
        // Parses a typed name map specification, returns true and sets 'map' on success.
        // A map specification has the form: [name:type, ...]
        private static bool TryParseTypeMap(DTypeSpecLexer lexer, out TypeTree map)
        {
            Contracts.AssertValue(lexer);

            string token;

            if (!lexer.TryNextToken(out token) || token != "[")
            {
                map = default(TypeTree);
                return(false);
            }

            map = new TypeTree();

            while (lexer.TryNextToken(out token) && token != "]")
            {
                string name = token;
                if (name.Length >= 2 && name.StartsWith("'") && name.EndsWith("'"))
                {
                    name = TexlLexer.UnescapeName(name);
                }

                DType type;
                if (!DName.IsValidDName(name) ||
                    !lexer.TryNextToken(out token) ||
                    token != ":" ||
                    map.Contains(name) ||
                    !TryParse(lexer, out type))
                {
                    map = default(TypeTree);
                    return(false);
                }

                map = map.SetItem(name, type);

                if (!lexer.TryNextToken(out token) || (token != "," && token != "]"))
                {
                    map = default(TypeTree);
                    return(false);
                }
                else if (token == "]")
                {
                    return(true);
                }
            }

            if (token != "]")
            {
                map = default(TypeTree);
                return(false);
            }

            return(true);
        }
예제 #2
0
        internal bool SetMatchArea(int startIndex, int endIndex, int replacementLength = -1)
        {
            Contracts.Assert(0 <= startIndex && startIndex <= endIndex && endIndex <= _script.Length);

            // If we have already provided suggestions, we can't set the match area
            if (Suggestions.Count > 0 || SubstringSuggestions.Count > 0)
            {
                return(false);
            }

            // Trim leading whitespace as there is no point to matching it
            while (startIndex < endIndex && string.IsNullOrWhiteSpace(Script.Substring(startIndex, 1)))
            {
                startIndex++;
            }

            _replacementStartIndex = startIndex;
            _matchingLength        = endIndex - startIndex;
            _replacementLength     = replacementLength < 0 ? _matchingLength : replacementLength;
            _matchingStr           = TexlLexer.UnescapeName(_script.Substring(startIndex, _matchingLength));

            return(true);
        }