The base class for all the tags.
コード例 #1
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;
		}
コード例 #2
0
ファイル: ParserBase.cs プロジェクト: sojanml/eX-Portal
        /// <summary>
        /// Creates an xml node for the specified tag.
        /// </summary>
        protected XmlNode CreateTagXmlNode(TagBase tag)
        {
            #region Check the arguments

            if (tag == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            CheckXmlDocInitialized();

            XmlElement myTagNode = fParsedDocument.CreateElement(cTagXmlNodeName);

            XmlAttribute myTypeAttribute = fParsedDocument.CreateAttribute(cTagTypeXmlAttributeName);
            myTypeAttribute.Value = tag.Type;
            myTagNode.Attributes.Append(myTypeAttribute);

            if (tag.Value != null)
            {
                XmlAttribute myValueAttribute = fParsedDocument.CreateAttribute(cValueXmlAttributeName);
                myValueAttribute.Value = tag.Value;
                myTagNode.Attributes.Append(myValueAttribute);
            }

            return(myTagNode);
        }
コード例 #3
0
 /// <summary>
 /// Checks whether there is a string tag in the text at the specified position, and returns its type.
 /// </summary>
 protected Type IsStringTag(string text, int position)
 {
     foreach (Type myTagType in StringTags)
     {
         MatchTagAttributeBase myMatchTagAttribute = TagBase.GetTagMatchAttribute(myTagType);
         if (myMatchTagAttribute.Match(text, position))
         {
             return(myTagType);
         }
     }
     return(null);
 }
コード例 #4
0
ファイル: ParserBase.cs プロジェクト: sojanml/eX-Portal
        /// <summary>
        /// Retrurns the tag instance from its type and value.
        /// </summary>
        protected TagBase GetTagFromType(string type, string value, bool hasContents)
        {
            foreach (Type myTagType in Tags)
            {
                string myType = TagBase.GetTagType(myTagType);
                if (string.Compare(myType, type, true) == 0)
                {
                    TagBase myTag = Activator.CreateInstance(myTagType) as TagBase;
                    myTag.InitializeFromData(this, value, hasContents);
                    return(myTag);
                }
            }

            throw new Exception(string.Format("Tag cannot be found: {0}", type));
        }
コード例 #5
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);
        }
コード例 #6
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;
		}
コード例 #7
0
        /// <summary>
        /// Reads the tag at the specified position in the specified sql.
        /// </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 = MatchStart(sql, position);

            if (myResult < 0)
            {
                throw new Exception(string.Format("Cannot read the {0} tag.", Name));
            }

            Parser = parser;

            HasContents = true;

            ParentTag = parentTag;

            return(myResult);
        }
コード例 #8
0
ファイル: ParserBase.cs プロジェクト: sojanml/eX-Portal
        /// <summary>
        /// Converts the specified tag xml node to text.
        /// </summary>
        private void TagXmlNodeToText(StringBuilder output, XmlNode node)
        {
            #region Check arguments

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

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

            #endregion

            TagBase myTag = TagXmlNodeToTag(node);

            myTag.WriteStart(output);

            if (IsSkipWhiteSpace)
            {
                output.Append(cWhiteSpace);
            }

            if (node.ChildNodes.Count > 0)
            {
                XmlNodesToText(output, node.ChildNodes);
            }

            myTag.WriteEnd(output);

            if (IsSkipWhiteSpace)
            {
                output.Append(cWhiteSpace);
            }
        }
コード例 #9
0
        /// <summary>
        /// Parses the specified block of a text.
        /// </summary>
        /// <returns>
        /// Returns the end position of the parsed block.
        /// </returns>
        protected int ParseBlock(XmlNode parentNode, TagBase parentTag, string text, int position)
        {
            #region Check the arguments

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

            CheckTextAndPositionArguments(text, position);

            #endregion

            while (position < text.Length)
            {
                if (IsSkipWhiteSpace)
                    SkipWhiteSpace(text, ref position);

                if (position == text.Length)
                    break;

                #region Read the parent tag ending

                if (parentTag != null)
                {
                    int myParentTagEndingEndPosition = parentTag.MatchEnd(text, position);
                    if (myParentTagEndingEndPosition >= 0)
                    {
                        position = myParentTagEndingEndPosition;
                        return position;
                    }
                }

                #endregion

                Type myTagType = IsTag(text, position);
                if (myTagType != null)
                {
                    #region Read a tag

                    #region Create the tag class instance

                    TagBase myTag = Activator.CreateInstance(myTagType) as TagBase;
                    position = myTag.InitializeFromText(this, text, position, parentTag);

                    #endregion

                    #region Create an xml node for the tag

                    XmlNode myTagXmlNode = CreateTagXmlNode(myTag);
                    parentNode.AppendChild(myTagXmlNode);

                    #endregion

                    if (myTag.HasContents)
                        position = ParseBlock(myTagXmlNode, myTag, text, position);

                    #endregion
                }
                else
                {
                    #region Read text

                    string myText = ReadWordOrSeparator(text, ref position, !IsSkipWhiteSpace);
                    parentNode.AppendChild(CreateTextXmlNode(myText));

                    #endregion
                }
            }

            if (parentTag != null && !parentTag.CanTerminateByStringEnd)
                throw new Exception("Invalid format");

            return position;
        }
コード例 #10
0
        /// <summary>
        /// Creates an xml node for the specified tag.
        /// </summary>
        protected XmlNode CreateTagXmlNode(TagBase tag)
        {
            #region Check the arguments

            if (tag == null)
                throw new ArgumentNullException();

            #endregion

            CheckXmlDocInitialized();

            XmlElement myTagNode = fParsedDocument.CreateElement(cTagXmlNodeName);

            XmlAttribute myTypeAttribute = fParsedDocument.CreateAttribute(cTagTypeXmlAttributeName);
            myTypeAttribute.Value = tag.Type;
            myTagNode.Attributes.Append(myTypeAttribute);

            if (tag.Value != null)
            {
                XmlAttribute myValueAttribute = fParsedDocument.CreateAttribute(cValueXmlAttributeName);
                myValueAttribute.Value = tag.Value;
                myTagNode.Attributes.Append(myValueAttribute);
            }

            return myTagNode;
        }
コード例 #11
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);
        }
コード例 #12
0
ファイル: ParserBase.cs プロジェクト: sojanml/eX-Portal
        /// <summary>
        /// Parses the specified block of a text.
        /// </summary>
        /// <returns>
        /// Returns the end position of the parsed block.
        /// </returns>
        protected int ParseBlock(XmlNode parentNode, TagBase parentTag, string text, int position)
        {
            #region Check the arguments

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

            CheckTextAndPositionArguments(text, position);

            #endregion

            while (position < text.Length)
            {
                if (IsSkipWhiteSpace)
                {
                    SkipWhiteSpace(text, ref position);
                }

                if (position == text.Length)
                {
                    break;
                }

                #region Read the parent tag ending

                if (parentTag != null)
                {
                    int myParentTagEndingEndPosition = parentTag.MatchEnd(text, position);
                    if (myParentTagEndingEndPosition >= 0)
                    {
                        position = myParentTagEndingEndPosition;
                        return(position);
                    }
                }

                #endregion

                Type myTagType = IsTag(text, position);
                if (myTagType != null)
                {
                    #region Read a tag

                    #region Create the tag class instance

                    TagBase myTag = Activator.CreateInstance(myTagType) as TagBase;
                    position = myTag.InitializeFromText(this, text, position, parentTag);

                    #endregion

                    #region Create an xml node for the tag

                    XmlNode myTagXmlNode = CreateTagXmlNode(myTag);
                    parentNode.AppendChild(myTagXmlNode);

                    #endregion

                    if (myTag.HasContents)
                    {
                        position = ParseBlock(myTagXmlNode, myTag, text, position);
                    }

                    #endregion
                }
                else
                {
                    #region Read text

                    string myText = ReadWordOrSeparator(text, ref position, !IsSkipWhiteSpace);
                    parentNode.AppendChild(CreateTextXmlNode(myText));

                    #endregion
                }
            }

            if (parentTag != null && !parentTag.CanTerminateByStringEnd)
            {
                throw new Exception("Invalid format");
            }

            return(position);
        }
コード例 #13
0
ファイル: TagBase.cs プロジェクト: totpero/SqlParser
 /// <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);
コード例 #14
0
ファイル: TagBase.cs プロジェクト: totpero/SqlParser
        /// <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;
        }
コード例 #15
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);
コード例 #16
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);
        }
コード例 #17
0
ファイル: BracesTag.cs プロジェクト: totpero/SqlParser
        /// <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;
        }