Esempio n. 1
0
        public bool CheckIfOnlyContainsValidIdentifierAtomChars(out int characterWithError)
        {
            for (int i = 0; i < Length; i++)
            {
                if (!SymbolAtom.IsValidIdentifierAtomChar(this[i]))
                {
                    characterWithError = i;
                    return(false);
                }
            }

            characterWithError = -1;
            return(true);
        }
Esempio n. 2
0
        public bool CheckIfOnlyContainsValidIdentifierAtomChars(out int characterWithError)
        {
            int end = m_index + Length;

            for (int i = m_index; i < end; i++)
            {
                if (!SymbolAtom.IsValidIdentifierAtomChar(m_value[i]))
                {
                    characterWithError = i;
                    return(false);
                }
            }

            characterWithError = -1;
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Extends a relative identifier with a new identifier components.
        /// </summary>
        public PartialSymbol Combine(SymbolAtom atom)
        {
            Contract.Requires(IsValid);
            Contract.Requires(atom.IsValid);

            var components = new StringId[m_components.Length + 1];
            int count      = 0;

            foreach (StringId component in m_components)
            {
                components[count++] = component;
            }

            components[count] = atom.StringId;

            return(new PartialSymbol(components));
        }
Esempio n. 4
0
        /// <summary>
        /// Concatenates a identifier atom to the end of a relative identifier.
        /// </summary>
        /// <remarks>
        /// The relative identifier may not be empty when calling this method.
        /// </remarks>
        public PartialSymbol Concat(StringTable table, SymbolAtom addition)
        {
            Contract.Requires(IsValid);
            Contract.RequiresNotNull(table);
            Contract.Requires(addition.IsValid);
            Contract.Requires(!IsEmpty);

            StringId changed = new SymbolAtom(m_components[m_components.Length - 1]).Concat(table, addition).StringId;

            var components = new StringId[m_components.Length];
            int count      = 0;

            foreach (StringId component in m_components)
            {
                components[count++] = component;
            }

            components[count - 1] = changed;
            return(new PartialSymbol(components));
        }
Esempio n. 5
0
        /// <summary>
        /// Extends a relative identifier with new identifier components.
        /// </summary>
        public PartialSymbol Combine(SymbolAtom atom1, SymbolAtom atom2)
        {
            Contract.Requires(IsValid);
            Contract.Requires(atom1.IsValid);
            Contract.Requires(atom2.IsValid);
            Contract.Ensures(Contract.Result <PartialSymbol>().IsValid);

            var components = new StringId[m_components.Length + 2];
            int count      = 0;

            foreach (StringId component in m_components)
            {
                components[count++] = component;
            }

            components[count++] = atom1.StringId;
            components[count]   = atom2.StringId;

            return(new PartialSymbol(components));
        }
Esempio n. 6
0
 /// <summary>
 /// Writes a SymbolAtom
 /// </summary>
 public virtual void Write(SymbolAtom value)
 {
     Start <SymbolAtom>();
     Write(value.StringId.Value);
     End();
 }
Esempio n. 7
0
        /// <summary>
        /// Try to create a PartialSymbol from a string.
        /// </summary>
        /// <returns>Return the parser result indicating success, or what was wrong with the parsing.</returns>
        public static ParseResult TryCreate <T>(StringTable table, T partialSymbol, out PartialSymbol result, out int characterWithError)
            where T : struct, ICharSpan <T>
        {
            Contract.RequiresNotNull(table);

            using (var wrap = Pools.GetStringIdList())
            {
                List <StringId> components = wrap.Instance;

                int index = 0;
                int start = 0;
                int last  = partialSymbol.Length - 1;
                while (index < partialSymbol.Length)
                {
                    var ch = partialSymbol[index];

                    // trivial reject of invalid characters
                    if (!SymbolCharacters.IsValidDottedIdentifierChar(ch))
                    {
                        characterWithError = index;
                        result             = Invalid;
                        return(ParseResult.FailureDueToInvalidCharacter);
                    }

                    if (ch == SymbolCharacters.DottedIdentifierSeparatorChar)
                    {
                        // found a component separator
                        if (index == start || index == last)
                        {
                            characterWithError = index;
                            result             = Invalid;
                            return(ParseResult.LeadingOrTrailingDot);
                        }
                        else if (index > start)
                        {
                            // make a identifier atom out of [start..index]
                            SymbolAtom             atom;
                            int                    charError;
                            SymbolAtom.ParseResult papr = SymbolAtom.TryCreate(
                                table,
                                partialSymbol.Subsegment(start, index - start),
                                out atom,
                                out charError);

                            if (papr != SymbolAtom.ParseResult.Success)
                            {
                                characterWithError = index + charError;
                                result             = Invalid;
                                return(ParseResult.FailureDueToInvalidCharacter);
                            }

                            components.Add(atom.StringId);
                        }

                        // skip over the dot
                        index++;
                        start = index;
                        continue;
                    }

                    index++;
                }

                if (index > start)
                {
                    // make a identifier atom out of [start..index]
                    SymbolAtom             atom;
                    int                    charError;
                    SymbolAtom.ParseResult papr = SymbolAtom.TryCreate(
                        table,
                        partialSymbol.Subsegment(start, index - start),
                        out atom,
                        out charError);

                    if (papr != SymbolAtom.ParseResult.Success)
                    {
                        characterWithError = index + charError;
                        result             = Invalid;
                        return(ParseResult.FailureDueToInvalidCharacter);
                    }

                    components.Add(atom.StringId);
                }

                result = new PartialSymbol(components.ToArray());

                characterWithError = -1;
                return(ParseResult.Success);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a PartialSymbol from a identifier atom.
        /// </summary>
        public static PartialSymbol Create(SymbolAtom atom)
        {
            Contract.Requires(atom.IsValid);

            return(new PartialSymbol(atom.StringId));
        }