An abstract class which is used as the base class for parsers. It contains basic methods which allow you to create a logical tree from a document.
示例#1
0
        /// <summary>
        /// Checks whether there is the tag at the specified position
        /// in the specified sql.
        /// </summary>
        /// <name>The value of the Name property.</name>
        /// <returns>
        /// The position after the tag or -1 there is no tag at the position.
        /// </returns>
        internal static int MatchStart(string firstWord, string secondWord, string sql, int position)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, firstWord, 0, firstWord.Length, true) != 0)
            {
                return(-1);
            }

            position += firstWord.Length;

            ParserBase.SkipWhiteSpace(sql, ref position);
            if (position == sql.Length)
            {
                return(-1);
            }

            if (string.Compare(sql, position, secondWord, 0, secondWord.Length, true) != 0)
            {
                return(-1);
            }

            return(position + secondWord.Length);
        }
示例#2
0
		/// <summary>
		/// Reads the tag at the specified position in the specified word and separator array.
		/// </summary>
		/// <returns>
		/// The position after the tag (at which to continue reading).
		/// </returns>
		protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
		{
			#region Check the arguments

			ParserBase.CheckTextAndPositionArguments(sql, position);

			#endregion

			int myAfterTagStartPos = MatchStartStatic(sql, position);

			if (myAfterTagStartPos < 0)
				throw new Exception("Cannot read the QuotedIdentifier tag.");

			#region Read the identifier's value

			int myTagEndPos = sql.IndexOf(cTagDelimiter, myAfterTagStartPos, StringComparison.InvariantCultureIgnoreCase);
			if (myTagEndPos < 0)
				throw new Exception("Cannot read the QuotedIdentifier tag.");

			if (myAfterTagStartPos == myTagEndPos)
				Value = string.Empty;
			else
				Value = sql.Substring(myAfterTagStartPos, myTagEndPos - myAfterTagStartPos);

			#endregion

			Parser = parser;

			HasContents = false;

			return myTagEndPos + cTagDelimiter.Length;
		}
示例#3
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        public override int MatchEnd(string sql, int position)
        {
            CheckInitialized();

            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (ParentTag != null && ParentTag.MatchEnd(sql, position) >= 0)
            {
                return(position);
            }

            Type myTag = (Parser as SqlParser).IsTag(sql, position);
            if (
                myTag != null &&
                !myTag.IsAssignableFrom(typeof(StringLiteralTag)) &&
                !myTag.IsAssignableFrom(typeof(BracesTag))
                )
            {
                return(position);
            }

            return(-1);
        }
示例#4
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        private int MatchEnd(string sql, int position, int literalStartPos)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, cTagDelimiter, 0, cTagDelimiter.Length, true) != 0)
            {
                return(-1);
            }
            return(position + 1);

#if ASDFASF
            #region Check the next and previous symbols (where there are ' symbols)
            #region Determine the number of ' symbols before

            int myNumberOfApostBefore = 0;
            for (int myCurPos = position - 1; myCurPos >= literalStartPos; myCurPos--)
            {
                if (string.Compare(sql, myCurPos, cTagDelimiter, 0, cTagDelimiter.Length, true) == 0)
                {
                    myNumberOfApostBefore++;
                }
                else
                {
                    break;
                }
            }

            #endregion

            if (!(myNumberOfApostBefore == 1 && position == literalStartPos + 1))
            {
                if (myNumberOfApostBefore % 2 == 1)
                {
                    return(-1);
                }

                #region Check whether the next symbol is '

                if (position + 1 < sql.Length)
                {
                    if (string.Compare(sql, position + 1, cTagDelimiter, 0, cTagDelimiter.Length, true) == 0)
                    {
                        return(-1);
                    }
                }

                #endregion
            }

            #endregion

            return(position + cTagDelimiter.Length);
#endif
        }
示例#5
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        protected virtual void InitializeFromDataCore(ParserBase parser, string value, bool hasContents)
        {
            Parser = parser;

            Value = value;

            HasContents = hasContents;

            IsInitialized = true;
        }
示例#6
0
        /// <summary>
        /// Returns a value indicating whether there is the tag ending at the specified position.		///
        /// </summary>
        /// <returns>
        /// If this value is less than zero, then there is no ending; otherwise the
        /// position after ending is returned.
        /// </returns>
        public override int MatchEnd(string sql, int position)
        {
            CheckInitialized();

            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            return(MatchEndStatic(sql, position));
        }
示例#7
0
        /// <summary>
        /// Reads the tag at the specified position in the specified sql string.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myLiteralStartPos = position;

            position = MatchStartStatic(sql, position);

            if (position < 0)
            {
                throw new Exception("Cannot read the StringLiteral tag.");
            }

            #region Read the literal value

            int myResult        = -1;
            int myValueStartPos = position;
            while (position < sql.Length)
            {
                myResult = MatchEnd(sql, position, myLiteralStartPos);
                if (myResult >= 0)
                {
                    if (position == myValueStartPos)
                    {
                        Value = string.Empty;
                    }
                    else
                    {
                        Value = sql.Substring(myValueStartPos, position - myValueStartPos);
                    }
                    break;
                }
                position++;
            }

            if (myResult < 0)
            {
                throw new Exception("Cannot read the StringLiteral tag.");
            }

            #endregion

            Parser = parser;

            HasContents = false;

            return(myResult);
        }
示例#8
0
        /// <summary>
        /// Checks whether there is the tag start at the specified position
        /// in the specified sql.
        /// </summary>
        /// <returns>
        /// The position after the tag or -1 there is no tag start at the position.
        /// </returns>
        public static int MatchStartStatic(string sql, int position)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, cTagDelimiter, 0, cTagDelimiter.Length, true) != 0)
            {
                return(-1);
            }

            return(position + cTagDelimiter.Length);
        }
示例#9
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        public void InitializeFromData(ParserBase parser, string value, bool hasContents)
        {
            #region Check the arguments

            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            #endregion

            InitializeFromDataCore(parser, value, hasContents);

            IsInitialized = true;
        }
示例#10
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <param name="parentTag">
        /// The parent tag of this tag. This argument is used to determine
        /// the end of the tag (it can be the end of the parent tag).
        /// </param>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        public int InitializeFromText(ParserBase parser, string text, int position, TagBase parentTag)
        {
            #region Check the arguments

            if (parser == null)
            {
                throw new ArgumentNullException("parser");
            }

            #endregion

            int myResult = InitializeCoreFromText(parser, text, position, parentTag);

            IsInitialized = true;

            return(myResult);
        }
		/// <summary>
		/// Reads the tag at the specified position in the specified sql string.
		/// </summary>
		/// <returns>
		/// The position after the tag (at which to continue reading).
		/// </returns>
		protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
		{
			#region Check the arguments

			ParserBase.CheckTextAndPositionArguments(sql, position);

			#endregion

			int myLiteralStartPos = position;

			position = MatchStartStatic(sql, position);

			if (position < 0)
				throw new Exception("Cannot read the StringLiteral tag.");

			#region Read the literal value

			int myResult = -1;
			int myValueStartPos = position;
			while (position < sql.Length)
			{
				myResult = MatchEnd(sql, position, myLiteralStartPos);
				if (myResult >= 0)
				{
					if (position == myValueStartPos)
						Value = string.Empty;
					else
						Value = sql.Substring(myValueStartPos, position - myValueStartPos);
					break;
				}
				position++;
			}

			if (myResult < 0)
				throw new Exception("Cannot read the StringLiteral tag.");

			#endregion

			Parser = parser;

			HasContents = false;

			return myResult;
		}
        /// <summary>
        /// Checks whether there is the tag at the specified position
        /// in the specified sql.
        /// </summary>
        /// <name>The value of the Name property.</name>
        /// <returns>
        /// The position after the tag or -1 there is no tag at the position.
        /// </returns>
        internal static int MatchStart(string name, string sql, int position)
        {
            #region Check the arguments

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            if (string.Compare(sql, position, name, 0, name.Length, true) != 0)
            {
                return(-1);
            }

            return(position + name.Length);
        }
示例#13
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myResult = MatchStartStatic(sql, position);

            if (myResult < 0)
            {
                throw new Exception("Cannot read the Braces tag.");
            }

            Parser = parser;

            HasContents = true;

            return(myResult);
        }
示例#14
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myAfterTagStartPos = MatchStartStatic(sql, position);

            if (myAfterTagStartPos < 0)
            {
                throw new Exception("Cannot read the QuotedIdentifier tag.");
            }

            #region Read the identifier's value

            int myTagEndPos = sql.IndexOf(cTagDelimiter, myAfterTagStartPos, StringComparison.InvariantCultureIgnoreCase);
            if (myTagEndPos < 0)
            {
                throw new Exception("Cannot read the QuotedIdentifier tag.");
            }

            if (myAfterTagStartPos == myTagEndPos)
            {
                Value = string.Empty;
            }
            else
            {
                Value = sql.Substring(myAfterTagStartPos, myTagEndPos - myAfterTagStartPos);
            }

            #endregion

            Parser = parser;

            HasContents = false;

            return(myTagEndPos + cTagDelimiter.Length);
        }
示例#15
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        public void InitializeFromData(ParserBase parser, string value, bool hasContents)
        {
            #region Check the arguments

            if (parser == null)
                throw new ArgumentNullException("parser");

            #endregion

            InitializeFromDataCore(parser, value, hasContents);

            IsInitialized = true;
        }
示例#16
0
 /// <summary>
 /// Reads the tag at the specified position in the specified word and separator array.
 /// </summary>
 /// <param name="parentTag">
 /// The parent tag of this tag. This argument is used to determine
 /// the end of the tag (it can be the end of the parent tag).
 /// </param>
 /// <returns>
 /// The position after the tag (at which to continue reading).
 /// </returns>
 protected abstract int InitializeCoreFromText(ParserBase parser, string text, int position, TagBase parentTag);
示例#17
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <param name="parentTag">
        /// The parent tag of this tag. This argument is used to determine 
        /// the end of the tag (it can be the end of the parent tag).
        /// </param>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        public int InitializeFromText(ParserBase parser, string text, int position, TagBase parentTag)
        {
            #region Check the arguments

            if (parser == null)
                throw new ArgumentNullException("parser");

            #endregion

            int myResult = InitializeCoreFromText(parser, text, position, parentTag);

            IsInitialized = true;

            return myResult;
        }
示例#18
0
 /// <summary>
 /// Reads the tag at the specified position in the specified word and separator array.
 /// </summary>
 /// <param name="parentTag">
 /// The parent tag of this tag. This argument is used to determine 
 /// the end of the tag (it can be the end of the parent tag).
 /// </param>
 /// <returns>
 /// The position after the tag (at which to continue reading).
 /// </returns>
 protected abstract int InitializeCoreFromText(ParserBase parser, string text, int position, TagBase parentTag);
示例#19
0
        /// <summary>
        /// Reads the tag from the specified data.
        /// </summary>
        protected virtual void InitializeFromDataCore(ParserBase parser, string value, bool hasContents)
        {
            Parser = parser;

            Value = value;

            HasContents = hasContents;

            IsInitialized = true;
        }
示例#20
0
        /// <summary>
        /// Reads the tag at the specified position in the specified word and separator array.
        /// </summary>
        /// <returns>
        /// The position after the tag (at which to continue reading).
        /// </returns>
        protected override int InitializeCoreFromText(ParserBase parser, string sql, int position, TagBase parentTag)
        {
            #region Check the arguments

            ParserBase.CheckTextAndPositionArguments(sql, position);

            #endregion

            int myResult = MatchStartStatic(sql, position);

            if (myResult < 0)
                throw new Exception("Cannot read the Braces tag.");

            Parser = parser;

            HasContents = true;

            return myResult;
        }