Beispiel #1
0
 void OnTagParsed(TagType tagtype, string id, TagAttributes attributes)
 {
     if (TagParsed != null)
     {
         TagParsed(this, tagtype, id, attributes);
     }
 }
Beispiel #2
0
        void GetServerTag(out TagType tagtype, out string id, out TagAttributes attributes)
        {
            string inside_tags;
            bool   old = tokenizer.ExpectAttrValue;

            tokenizer.ExpectAttrValue = false;
            if (Eat('@'))
            {
                tokenizer.ExpectAttrValue = old;
                tagtype = TagType.Directive;
                id      = "";
                if (Eat(Token.DIRECTIVE))
                {
                    id = tokenizer.Value;
                }

                attributes = GetAttributes();
                if (!Eat('%') || !Eat('>'))
                {
                    OnError("expecting '%>'");
                }

                return;
            }

            if (Eat(Token.DOUBLEDASH))
            {
                tokenizer.ExpectAttrValue = old;
                tokenizer.Verbatim        = true;
                inside_tags        = GetVerbatim(tokenizer.get_token(), "--%>");
                tokenizer.Verbatim = false;
                id         = null;
                attributes = null;
                tagtype    = TagType.ServerComment;
                return;
            }

            tokenizer.ExpectAttrValue = old;
            bool varname;
            bool databinding;

            varname     = Eat('=');
            databinding = !varname && Eat('#');

            tokenizer.Verbatim = true;
            inside_tags        = GetVerbatim(tokenizer.get_token(), "%>");
            tokenizer.Verbatim = false;
            id         = inside_tags;
            attributes = null;
            tagtype    = (databinding ? TagType.DataBinding :
                          (varname ? TagType.CodeRenderExpression : TagType.CodeRender));
        }
Beispiel #3
0
		void OnTagParsed (TagType tagtype, string id, TagAttributes attributes)
		{
			if (TagParsed != null)
				TagParsed (this, tagtype, id, attributes);
		}
Beispiel #4
0
		void GetServerTag (out TagType tagtype, out string id, out TagAttributes attributes)
		{
			string inside_tags;
			bool old = tokenizer.ExpectAttrValue;

			tokenizer.ExpectAttrValue = false;
			if (Eat ('@'))
			{
				tokenizer.ExpectAttrValue = old;
				tagtype = TagType.Directive;
				id = "";
				if (Eat (Token.DIRECTIVE))
					id = tokenizer.Value;

				attributes = GetAttributes ();
				if (!Eat ('%') || !Eat ('>'))
					OnError ("expecting '%>'");

				return;
			}
			
			if (Eat (Token.DOUBLEDASH)) 
			{
				tokenizer.ExpectAttrValue = old;
				tokenizer.Verbatim = true;
				inside_tags = GetVerbatim (tokenizer.get_token (), "--%>");
				tokenizer.Verbatim = false;
				id = null;
				attributes = null;
				tagtype = TagType.ServerComment;
				return;
			}

			tokenizer.ExpectAttrValue = old;
			bool varname;
			bool databinding;
			varname = Eat ('=');
			databinding = !varname && Eat ('#');

			tokenizer.Verbatim = true;
			inside_tags = GetVerbatim (tokenizer.get_token (), "%>");
			tokenizer.Verbatim = false;
			id = inside_tags;
			attributes = null;
			tagtype = (databinding ? TagType.DataBinding :
				(varname ? TagType.CodeRenderExpression : TagType.CodeRender));
		}
Beispiel #5
0
		TagAttributes GetAttributes ()
		{
			int token;
			TagAttributes attributes;
			string id;
			bool wellFormedForServer = true;

			attributes = new TagAttributes ();
			while ((token = tokenizer.get_token ()) != Token.EOF)
			{
				if (token == '<' && Eat ('%')) 
				{
					tokenizer.Verbatim = true;
					attributes.Add ("", "<%" + 
						GetVerbatim (tokenizer.get_token (), "%>") + "%>");
					tokenizer.Verbatim = false;
					tokenizer.InTag = true;
					continue;
				}
					
				if (token != Token.IDENTIFIER)
					break;

				id = tokenizer.Value;
				if (Eat ('='))
				{
					if (Eat (Token.ATTVALUE))
					{
						attributes.Add (id, tokenizer.Value);
						wellFormedForServer &= tokenizer.AlternatingQuotes;
					} 
					else if (Eat ('<') && Eat ('%')) 
					{
						/*
						TagType tagtypeTmp = TagType.ServerComment;
						string idTmp = null;
						TagAttributes attributesTmp = new TagAttributes ();
						GetServerTag (out tagtypeTmp, out idTmp, out attributesTmp);
						OnTagParsed (tagtypeTmp, idTmp, attributesTmp);
						*/
						tokenizer.Verbatim = true;
						attributes.Add (id, "<%" + 
							GetVerbatim (tokenizer.get_token (), "%>") + "%>");
						tokenizer.Verbatim = false;
						tokenizer.InTag = true;
					} 
					else 
					{
						OnError ("expected ATTVALUE");
						return null;
					}
				} 
				else 
				{
					attributes.Add (id, null);
				}
			}

			tokenizer.put_back ();

			if (attributes.IsRunAtServer () && !wellFormedForServer) 
			{
				OnError ("The server tag is not well formed.");
				return null;
			}
			
			return attributes;
		}
Beispiel #6
0
		void GetTag (out TagType tagtype, out string id, out TagAttributes attributes)
		{
			int token = tokenizer.get_token ();

			tagtype = TagType.ServerComment;
			id = null;
			attributes = null;
			switch (token)
			{
				case '%':
					GetServerTag (out tagtype, out id, out attributes);
					break;
				/*
				case '/':
					if (!Eat (Token.IDENTIFIER))
						OnError ("expecting TAGNAME");

					id = tokenizer.Value;
					if (!Eat ('>'))
						OnError ("expecting '>'. Got '" + id + "'");

					tagtype = TagType.Close;
					break;
				case '!':
					bool double_dash = Eat (Token.DOUBLEDASH);
					if (double_dash)
						tokenizer.put_back ();

					tokenizer.Verbatim = true;
					string end = double_dash ? "-->" : ">";
					string comment = GetVerbatim (tokenizer.get_token (), end);
					tokenizer.Verbatim = false;
					if (comment == null)
						OnError ("Unfinished HTML comment/DTD");

					string pathType, filename;
					if (double_dash && GetInclude (comment, out pathType, out filename)) 
					{
						tagtype = TagType.Include;
						attributes = new TagAttributes ();
						attributes.Add (pathType, filename);
					} 
					else 
					{
						tagtype = TagType.Text;
						id = "<!" + comment + end;
					}
					break;
				case Token.IDENTIFIER:
					if (this.filename == "@@inner_string@@") 
					{
						// Actually not tag but "xxx < yyy" stuff in inner_string!
						tagtype = TagType.Text;
						tokenizer.InTag = false;
						id = "<" + tokenizer.Odds + tokenizer.Value;
					} 
					else 
					{
						id = tokenizer.Value;
						try 
						{
							attributes = GetAttributes ();
						} 
						catch (Exception e) 
						{
							OnError (e.Message);
							break;
						}
					
						tagtype = TagType.Tag;
						if (Eat ('/') && Eat ('>')) 
						{
							tagtype = TagType.SelfClosing;
						} 
						else if (!Eat ('>')) 
						{
							if (attributes.IsRunAtServer ()) 
							{
								OnError ("The server tag is not well formed.");
								break;
							}
							tokenizer.Verbatim = true;
							attributes.Add ("", GetVerbatim (tokenizer.get_token (), ">") + ">");
							tokenizer.Verbatim = false;
						}
					}

					break;
				*/
				default:
					tagtype = TagType.Text;
					tokenizer.InTag = false;
					id = "<" + tokenizer.Value;
					break;
			}
		}
Beispiel #7
0
		void ProcessDirective (string tagid, TagAttributes attributes)
		{
			if( tagid == "Import" )
			{
				_currentTemplateContext.Imports[attributes["Namespace"]] = attributes;
				return;
			}
			if( tagid == "Assembly" )
			{
				_currentTemplateContext.Assemblies[attributes["Name"]] = attributes;
				return;
			}
			_currentTemplateContext.Directives[tagid] = attributes;
		}
Beispiel #8
0
		private void TagParsed(ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
		{
			switch(tagtype)
			{
				case TagType.Directive:
					ProcessDirective (tagid, attributes);
					break;
				case TagType.ServerComment:
					break;
				case TagType.CodeRender:
				{
					DumpContent();
					_codeBuilder.Append(tagid);
					_contentBuilder.Length = 0;
				}
					break;
				case TagType.CodeRenderExpression:
				{
					DumpContent();
					string str = string.Format("System.Console.Write({0});\n", tagid);
					_codeBuilder.Append(str);
					_contentBuilder.Length = 0;
				}
					break;
			}
		}
Beispiel #9
0
        TagAttributes GetAttributes()
        {
            int           token;
            TagAttributes attributes;
            string        id;
            bool          wellFormedForServer = true;

            attributes = new TagAttributes();
            while ((token = tokenizer.get_token()) != Token.EOF)
            {
                if (token == '<' && Eat('%'))
                {
                    tokenizer.Verbatim = true;
                    attributes.Add("", "<%" +
                                   GetVerbatim(tokenizer.get_token(), "%>") + "%>");
                    tokenizer.Verbatim = false;
                    tokenizer.InTag    = true;
                    continue;
                }

                if (token != Token.IDENTIFIER)
                {
                    break;
                }

                id = tokenizer.Value;
                if (Eat('='))
                {
                    if (Eat(Token.ATTVALUE))
                    {
                        attributes.Add(id, tokenizer.Value);
                        wellFormedForServer &= tokenizer.AlternatingQuotes;
                    }
                    else if (Eat('<') && Eat('%'))
                    {
                        /*
                         * TagType tagtypeTmp = TagType.ServerComment;
                         * string idTmp = null;
                         * TagAttributes attributesTmp = new TagAttributes ();
                         * GetServerTag (out tagtypeTmp, out idTmp, out attributesTmp);
                         * OnTagParsed (tagtypeTmp, idTmp, attributesTmp);
                         */
                        tokenizer.Verbatim = true;
                        attributes.Add(id, "<%" +
                                       GetVerbatim(tokenizer.get_token(), "%>") + "%>");
                        tokenizer.Verbatim = false;
                        tokenizer.InTag    = true;
                    }
                    else
                    {
                        OnError("expected ATTVALUE");
                        return(null);
                    }
                }
                else
                {
                    attributes.Add(id, null);
                }
            }

            tokenizer.put_back();

            if (attributes.IsRunAtServer() && !wellFormedForServer)
            {
                OnError("The server tag is not well formed.");
                return(null);
            }

            return(attributes);
        }
Beispiel #10
0
        void GetTag(out TagType tagtype, out string id, out TagAttributes attributes)
        {
            int token = tokenizer.get_token();

            tagtype    = TagType.ServerComment;
            id         = null;
            attributes = null;
            switch (token)
            {
            case '%':
                GetServerTag(out tagtype, out id, out attributes);
                break;

            /*
             * case '/':
             *      if (!Eat (Token.IDENTIFIER))
             *              OnError ("expecting TAGNAME");
             *
             *      id = tokenizer.Value;
             *      if (!Eat ('>'))
             *              OnError ("expecting '>'. Got '" + id + "'");
             *
             *      tagtype = TagType.Close;
             *      break;
             * case '!':
             *      bool double_dash = Eat (Token.DOUBLEDASH);
             *      if (double_dash)
             *              tokenizer.put_back ();
             *
             *      tokenizer.Verbatim = true;
             *      string end = double_dash ? "-->" : ">";
             *      string comment = GetVerbatim (tokenizer.get_token (), end);
             *      tokenizer.Verbatim = false;
             *      if (comment == null)
             *              OnError ("Unfinished HTML comment/DTD");
             *
             *      string pathType, filename;
             *      if (double_dash && GetInclude (comment, out pathType, out filename))
             *      {
             *              tagtype = TagType.Include;
             *              attributes = new TagAttributes ();
             *              attributes.Add (pathType, filename);
             *      }
             *      else
             *      {
             *              tagtype = TagType.Text;
             *              id = "<!" + comment + end;
             *      }
             *      break;
             * case Token.IDENTIFIER:
             *      if (this.filename == "@@inner_string@@")
             *      {
             *              // Actually not tag but "xxx < yyy" stuff in inner_string!
             *              tagtype = TagType.Text;
             *              tokenizer.InTag = false;
             *              id = "<" + tokenizer.Odds + tokenizer.Value;
             *      }
             *      else
             *      {
             *              id = tokenizer.Value;
             *              try
             *              {
             *                      attributes = GetAttributes ();
             *              }
             *              catch (Exception e)
             *              {
             *                      OnError (e.Message);
             *                      break;
             *              }
             *
             *              tagtype = TagType.Tag;
             *              if (Eat ('/') && Eat ('>'))
             *              {
             *                      tagtype = TagType.SelfClosing;
             *              }
             *              else if (!Eat ('>'))
             *              {
             *                      if (attributes.IsRunAtServer ())
             *                      {
             *                              OnError ("The server tag is not well formed.");
             *                              break;
             *                      }
             *                      tokenizer.Verbatim = true;
             *                      attributes.Add ("", GetVerbatim (tokenizer.get_token (), ">") + ">");
             *                      tokenizer.Verbatim = false;
             *              }
             *      }
             *
             *      break;
             */
            default:
                tagtype         = TagType.Text;
                tokenizer.InTag = false;
                id = "<" + tokenizer.Value;
                break;
            }
        }