Example #1
0
        /// <summary>
        /// Reads the next available character and confirms its type, then advances the reader until the next significant character.
        /// </summary>
        /// <param name="chartype">The expected character type.</param>
        /// <returns>The initially read character.</returns>
        public int ExpectAndSkip(StonChartype chartype)
        {
            int result = ExpectChartype(chartype);

            PeekSignificant();
            return(result);
        }
Example #2
0
        // validates the structure of a named value content string
        private static void ValidateNamedValueContent(string content)
        {
            if (content == "")
            {
                throw new StonException("A named simple value cannot be empty.");
            }

            StonChartype expectedChartype = StonChartype.CanunBegin;

            foreach (char c in content)
            {
                if (!c.HasChartype(expectedChartype))
                {
                    throw new StonException("A named simple value must be a valid CANUN path.");
                }
                if (c == '.')
                {
                    expectedChartype = StonChartype.CanunBegin;
                }
                else
                {
                    expectedChartype = StonChartype.CanunContinue | StonChartype.NameSeparator;
                }
            }
            // the CANUN path cannot end with a dot
            if (expectedChartype == StonChartype.CanunBegin)
            {
                throw new StonException("A named simple value must be a valid CANUN path.");
            }
        }
Example #3
0
        /// <summary>
        /// Reads the next available character and confirms its character type.
        /// If the character type is invalid, throws an exception.
        /// </summary>
        /// <param name="chartype">The expected character type.</param>
        /// <returns>The read character.</returns>
        public int ExpectChartype(StonChartype chartype)
        {
            int ch = InnerReader.Peek();

            if (!ch.HasChartype(chartype))
            {
                throw MakeUnexpectedCharacterException(chartype);
            }
            else
            {
                return(Read());
            }
        }
Example #4
0
        /// <summary>
        /// Checks whether the next available character has specific character type, and advances the reader until the next significant character if that's the case.
        /// </summary>
        /// <param name="chartype">The suspected character type.</param>
        /// <returns>True if the character has the specified chartype, false otherwise.</returns>
        public bool TryAndSkip(StonChartype chartype)
        {
            var result = TryChartype(chartype);

            if (!result)
            {
                return(false);
            }
            else
            {
                PeekSignificant();
                return(true);
            }
        }
Example #5
0
        /// <summary>
        /// Checks whether the next available character has specific character type, and reads the character if that's the case.
        /// </summary>
        /// <param name="chartype">The suspected character type.</param>
        /// <returns>True if the character has the specified chartype, false otherwise.</returns>
        public bool TryChartype(StonChartype chartype)
        {
            int ch = InnerReader.Peek();

            if (!ch.HasChartype(chartype))
            {
                return(false);
            }
            else
            {
                Read();
                return(true);
            }
        }
Example #6
0
 public StonUnexpectedCharacterParsingException MakeUnexpectedCharacterException(StonChartype expectedChartype, string message, Exception innerException)
 => new StonUnexpectedCharacterParsingException(Position, Line, Column, Peek(), expectedChartype, message, innerException);
Example #7
0
 public StonUnexpectedCharacterParsingException MakeUnexpectedCharacterException(StonChartype expectedChartype)
 => new StonUnexpectedCharacterParsingException(Position, Line, Column, Peek(), expectedChartype);
Example #8
0
        // reads a sequence of elements, using a given element reading function and sequence terminator chartype
        private IList <TElement> ReadSequence <TElement>(StonTokenReader reader, Func <StonTokenReader, TElement> elementReading, StonChartype sequenceTerminator)
        {
            var result = new List <TElement>();

            while (!reader.TryAndSkip(sequenceTerminator))
            {
                result.Add(elementReading(reader));
                if (reader.TryAndSkip(StonChartype.SequenceSeparator))
                {
                    continue;
                }
                else if (!reader.Peek().HasChartype(sequenceTerminator))
                {
                    throw reader.MakeUnexpectedCharacterException(StonChartype.SequenceSeparator | sequenceTerminator);
                }
            }

            return(result);
        }
Example #9
0
 /// <summary>
 /// Checks whether the given character is of specific STON character type.
 /// </summary>
 /// <param name="c">The character to check the type of.</param>
 /// <param name="chartype">The character type.</param>
 /// <returns>True if the character matches the specified type, false otherwise.</returns>
 public static bool HasChartype(this int c, StonChartype chartype)
 {
     return((c.GetChartype() & chartype) > 0);
 }