コード例 #1
0
        void OnTagParsed(TagType tagtype, string id, TagAttributes attributes)
        {
            TagParsedHandler eh = events [tagParsedEvent] as TagParsedHandler;

            if (eh != null)
            {
                eh(this, tagtype, id, attributes);
            }
        }
コード例 #2
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(String.Empty, GetVerbatim(tokenizer.get_token(), ">") + ">");
                        tokenizer.Verbatim = false;
                    }
                }

                break;

            default:
                string idvalue = null;
                // This is to handle code like:
                //
                //  <asp:ListItem runat="server"> < </asp:ListItem>
                //
                if ((char)token == '<')
                {
                    string odds = tokenizer.Odds;
                    if (odds != null && odds.Length > 0 && Char.IsWhiteSpace(odds [0]))
                    {
                        tokenizer.put_back();
                        idvalue = odds;
                    }
                    else
                    {
                        idvalue = tokenizer.Value;
                    }
                }
                else
                {
                    idvalue = tokenizer.Value;
                }

                tagtype         = TagType.Text;
                tokenizer.InTag = false;
                id = "<" + idvalue;
                break;
            }
        }
コード例 #3
0
		internal virtual void AddAssemblyDirective (ILocation location, TagAttributes attrs)
		{
			Hashtable tbl = attrs.GetDictionary (null);
			string name = GetAndRemove (tbl, "Name");
			string src = GetAndRemove (tbl, "Src");
			if (name == null && src == null)
				throw new ParseException (location, "You gotta specify Src or Name");

			if (name != null && src != null)
				throw new ParseException (location, "Src and Name cannot be used together");

			if (name != null) {
				AddAssemblyByName (name, location);
			} else {
				GetAssemblyFromSource (src, location);
			}

			if (tbl.Count > 0)
				throw new ParseException (location, "Unrecognized attribute in Assembly directive");
		}
コード例 #4
0
		internal virtual void AddDefaultDirective (ILocation location, TagAttributes attrs)
		{
#if NET_2_0
			CompilationSection compConfig;
#else
			CompilationConfiguration compConfig;
#endif
			compConfig = CompilationConfig;
			
			if (gotDefault)
				throw new ParseException (location, "duplicate " + DefaultDirectiveName + " directive");

			gotDefault = true;
			Hashtable attributes = attrs.GetDictionary (null);
			className = GetAndRemove (attributes, "class");
			if (className == null)
				throw new ParseException (null, "No Class attribute found.");
			
			string d = GetAndRemove (attributes, "debug");
			if (d != null) {
				debug = (String.Compare (d, "true", true, Helpers.InvariantCulture) == 0);
				if (debug == false && String.Compare (d, "false", true, Helpers.InvariantCulture) != 0)
					throw new ParseException (null, "Invalid value for Debug attribute");
			} else
				debug = compConfig.Debug;

			language = GetAndRemove (attributes, "language");
			if (language == null)
				language = compConfig.DefaultLanguage;

			GetAndRemove (attributes, "codebehind");
			if (attributes.Count > 0)
				throw new ParseException (location, "Unrecognized attribute in " +
							  DefaultDirectiveName + " directive");
		}
コード例 #5
0
		bool ProcessTag (string tagid, TagAttributes atts, TagType tagtype)
		{
			if ((atts == null || !atts.IsRunAtServer ()) && String.Compare (tagid, "tbody", true) == 0) {
				// MS completely ignores tbody or, if runat="server", fails when compiling
				if (stack.Count > 0)
					return stack.Builder.ChildrenAsProperties;

				return false;
			}

			if (isApplication) {
				if (String.Compare (tagid, "object", true) != 0)
					throw new ParseException (location, "Invalid tag for application file.");
			}

			ControlBuilder parent = stack.Builder;
			ControlBuilder builder = null;
			Hashtable htable = (atts != null) ? atts.GetDictionary (null) : emptyHash;
			if (stack.Count > 1) {
				try {
					builder = parent.CreateSubBuilder (tagid, htable, null, tparser, location);
				} catch (TypeLoadException e) {
					throw new ParseException (Location, "Type not found.", e);
				} catch (Exception e) {
					throw new ParseException (Location, e.Message, e);
				}
			}

			if (builder == null && atts != null && atts.IsRunAtServer ()) {
				string id = htable ["id"] as string;
				if (id != null && !CodeGenerator.IsValidLanguageIndependentIdentifier (id))
					throw new ParseException (Location, "'" + id + "' is not a valid identifier");
					
				try {
					builder = rootBuilder.CreateSubBuilder (tagid, htable, null, tparser, location);
				} catch (TypeLoadException e) {
					throw new ParseException (Location, "Type not found.", e);
				} catch (Exception e) {
					throw new ParseException (Location, e.Message, e);
				}
			}
			
			if (builder == null)
				return false;

			builder.location = location;
			builder.ID = htable ["id"] as string;
			if (typeof (HtmlForm).IsAssignableFrom (builder.ControlType)) {
				if (inForm)
					throw new ParseException (location, "Only one <form> allowed.");

				inForm = true;
			}

			if (builder.HasBody () && !(builder is ObjectTagBuilder)) {
				if (builder is TemplateBuilder) {
				//	push the id list
				}
				stack.Push (builder, location);
			} else {
				if (!isApplication && builder is ObjectTagBuilder) {
					ObjectTagBuilder ot = (ObjectTagBuilder) builder;
					if (ot.Scope != null && ot.Scope != "")
						throw new ParseException (location, "Scope not allowed here");

					if (tagtype == TagType.Tag) {
						stack.Push (builder, location);
						return true;
					}
				}
				
				parent.AppendSubBuilder (builder);
				builder.CloseControl ();
			}

			return true;
		}
コード例 #6
0
ファイル: AspGenerator.cs プロジェクト: tgiphil/mono
		// KLUDGE WARNING!!
		//
		// The code below (ProcessTagsInAttributes, ParseAttributeTag) serves the purpose to work
		// around a limitation of the current asp.net parser which is unable to parse server
		// controls inside client tag attributes. Since the architecture of the current
		// parser does not allow for clean solution of this problem, hence the kludge
		// below. It will be gone as soon as the parser is rewritten.
		//
		// The kludge supports only self-closing tags inside attributes.
		//
		// KLUDGE WARNING!!
		bool ProcessTagsInAttributes (ILocation location, string tagid, TagAttributes attributes, TagType type)
		{
			if (attributes == null || attributes.Count == 0)
				return false;
			
			Match match;
			Group group;
			string value;
			bool retval = false;
			int index, length;
			StringBuilder sb = new StringBuilder ();

			sb.AppendFormat ("\t<{0}", tagid);
			foreach (string key in attributes.Keys) {
				value = attributes [key] as string;
				if (value == null || value.Length < 16) { // optimization
					sb.AppendFormat (" {0}=\"{1}\"", key, value);
					continue;
				}
				
				match = runatServer.Match (attributes [key] as string);
				if (!match.Success) {
					sb.AppendFormat (" {0}=\"{1}\"", key, value);
					continue;
				}
				if (sb.Length > 0) {
					TextParsed (location, sb.ToString ());
					sb.Length = 0;
				}
				
				retval = true;
				group = match.Groups [0];
				index = group.Index;
				length = group.Length;

				TextParsed (location, String.Format (" {0}=\"{1}", key, index > 0 ? value.Substring (0, index) : String.Empty));;
				FlushText ();
				ParseAttributeTag (group.Value, location);
				if (index + length < value.Length)
					TextParsed (location, value.Substring (index + length) + "\"");
				else
					TextParsed (location, "\"");
			}
			if (type == TagType.SelfClosing)
				sb.Append ("/>");
			else
				sb.Append (">");

			if (retval && sb.Length > 0)
				TextParsed (location, sb.ToString ());
			
			return retval;
		}
コード例 #7
0
ファイル: AspGenerator.cs プロジェクト: tgiphil/mono
		bool ProcessScript (TagType tagtype, TagAttributes attributes)
		{
			if (tagtype != TagType.Close) {
				if (attributes != null && attributes.IsRunAtServer ()) {
					string language = (string) attributes ["language"];
					if (language != null && language.Length > 0 && tparser.ImplicitLanguage)
						tparser.SetLanguage (language);
					CheckLanguage (language);
					string src = (string) attributes ["src"];
					if (src != null) {
						if (src.Length == 0)
							throw new ParseException (Parser,
								"src cannot be an empty string");

						string content = ReadFile (src);
						inScript = true;
						TextParsed (Parser, content);
						FlushText ();
						inScript = false;
						if (tagtype != TagType.SelfClosing) {
							ignore_text = true;
							Parser.VerbatimID = "script";
						}
					} else if (tagtype == TagType.Tag) {
						Parser.VerbatimID = "script";
						inScript = true;
					}

					return true;
				} else {
					if (tagtype != TagType.SelfClosing) {
						Parser.VerbatimID = "script";
						javascript = true;
					}
					string content = location.PlainText;
					/* HACK, HACK, HACK */
					if (content.StartsWith ("<script")) {
						TextParsed (location, "<script");
						content = content.Substring (7);
					}

					TextParsed (location, content);
					return true;
				}
			}

			bool result;
			if (inScript) {
				result = inScript;
				inScript = false;
			} else if (!ignore_text) {
				result = javascript;
				javascript = false;
				TextParsed (location, location.PlainText);
			} else {
				ignore_text = false;
				result = true;
			}

			return result;
		}
コード例 #8
0
ファイル: AspParser.cs プロジェクト: sbc100/mono
		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 (String.Empty, GetVerbatim (tokenizer.get_token (), ">") + ">");
						tokenizer.Verbatim = false;
					}
				}

				break;
			default:
				string idvalue = null;
				// This is to handle code like:
				//
				//  <asp:ListItem runat="server"> < </asp:ListItem>
				//
				if ((char)token == '<') {
					string odds = tokenizer.Odds;
					if (odds != null && odds.Length > 0 && Char.IsWhiteSpace (odds [0])) {
						tokenizer.put_back ();
						idvalue = odds;
					} else
						idvalue = tokenizer.Value;
				} else
					idvalue = tokenizer.Value;
				
				tagtype = TagType.Text;
				tokenizer.InTag = false;
				id = "<" + idvalue;
				break;
			}
		}
コード例 #9
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));
		}
コード例 #10
0
		void OnTagParsed (TagType tagtype, string id, TagAttributes attributes)
		{
			if (TagParsed != null)
				TagParsed (this, tagtype, id, attributes);
		}
コード例 #11
0
		TagAttributes GetAttributes ()
		{
			int token;
			TagAttributes attributes;
			string id;

			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);
					} else if (Eat ('<') && Eat ('%')) {
						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 ();
			return attributes;
		}
コード例 #12
0
			void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
			{
				if (tagtype == TagType.CodeRender)
					builder.AppendSubBuilder (new CodeRenderBuilder (tagid, false, location));
				else if (tagtype == TagType.CodeRenderExpression)
					builder.AppendSubBuilder (new CodeRenderBuilder (tagid, true, location));
				else if (tagtype == TagType.DataBinding)
					builder.AppendSubBuilder (new DataBindingBuilder (tagid, location));
				else
					builder.AppendLiteralString (location.PlainText);
			}
コード例 #13
0
		bool ProcessScript (TagType tagtype, TagAttributes attributes)
		{
			if (tagtype != TagType.Close) {
				if (attributes != null && attributes.IsRunAtServer ()) {
					CheckLanguage ((string) attributes ["language"]);
					if (tagtype == TagType.Tag) {
						Parser.VerbatimID = "script";
						inScript = true;
					} //else if (tagtype == TagType.SelfClosing)
						// load script file here

					return true;
				} else {
					if (tagtype != TagType.SelfClosing) {
						Parser.VerbatimID = "script";
						javascript = true;
					}
					TextParsed (location, location.PlainText);
					return true;
				}
			}

			bool result;
			if (inScript) {
				result = inScript;
				inScript = false;
			} else {
				result = javascript;
				javascript = false;
				TextParsed (location, location.PlainText);
			}

			return result;
		}
コード例 #14
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(String.Empty, "<%" +
                                   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('%'))
                    {
                        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);
        }
コード例 #15
0
ファイル: AspParser.cs プロジェクト: sbc100/mono
		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 (String.Empty, "<%" + 
							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 ('%')) {
						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;
		}
コード例 #16
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;

#if NET_4_0
            bool codeRenderEncode;
#endif
            varname     = Eat('=');
            databinding = !varname && Eat('#');
#if NET_4_0
            codeRenderEncode = !databinding && !varname && Eat(':');
#endif
            string odds = tokenizer.Odds;

            tokenizer.Verbatim = true;
            inside_tags        = GetVerbatim(tokenizer.get_token(), "%>");
            if (databinding && odds != null && odds.Length > 0)
            {
                databinding = false;

                // We encountered <% #something here %>, this should be passed
                // verbatim to the compiler
                inside_tags = '#' + inside_tags;
            }

            tokenizer.Verbatim = false;
            id         = inside_tags;
            attributes = null;
            if (databinding)
            {
                tagtype = TagType.DataBinding;
            }
            else if (varname)
            {
                tagtype = TagType.CodeRenderExpression;
            }
#if NET_4_0
            else if (codeRenderEncode)
            {
                tagtype = TagType.CodeRenderEncode;
            }
#endif
            else
            {
                tagtype = TagType.CodeRender;
            }
        }
コード例 #17
0
ファイル: AspParser.cs プロジェクト: sbc100/mono
		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;
#if NET_4_0
			bool codeRenderEncode;
#endif
			varname = Eat ('=');
			databinding = !varname && Eat ('#');
#if NET_4_0
			codeRenderEncode = !databinding && !varname && Eat (':');
#endif
			string odds = tokenizer.Odds;
			
			tokenizer.Verbatim = true;
			inside_tags = GetVerbatim (tokenizer.get_token (), "%>");
			if (databinding && odds != null && odds.Length > 0) {
				databinding = false;

				// We encountered <% #something here %>, this should be passed
				// verbatim to the compiler
				inside_tags = '#' + inside_tags;
			}			

			tokenizer.Verbatim = false;
			id = inside_tags;
			attributes = null;
			if (databinding)
				tagtype = TagType.DataBinding;
			else if (varname)
				tagtype = TagType.CodeRenderExpression;
#if NET_4_0
			else if (codeRenderEncode)
				tagtype = TagType.CodeRenderEncode;
#endif
			else
				tagtype = TagType.CodeRender;
		}
コード例 #18
0
ファイル: AspGenerator.cs プロジェクト: tgiphil/mono
		bool ProcessTag (ILocation location, string tagid, TagAttributes atts, TagType tagtype, out bool ignored)
		{
			ignored = false;
			if (isApplication) {
				if (String.Compare (tagid, "object", true, Helpers.InvariantCulture) != 0)
					throw new ParseException (location, "Invalid tag for application file.");
			}

			ControlBuilder parent = stack.Builder;
			ControlBuilder builder = null;
			if (parent != null && parent.ControlType == typeof (HtmlTable) &&
			    (String.Compare (tagid, "thead", true, Helpers.InvariantCulture) == 0 ||
			     String.Compare (tagid, "tbody", true, Helpers.InvariantCulture) == 0)) {
				ignored = true;
				return true;
			}
				
			IDictionary htable = (atts != null) ? atts.GetDictionary (null) : emptyHash;
			if (stack.Count > 1) {
				try {
					builder = parent.CreateSubBuilder (tagid, htable, null, tparser, location);
				} catch (TypeLoadException e) {
					throw new ParseException (Location, "Type not found.", e);
				} catch (Exception e) {
					throw new ParseException (Location, e.Message, e);
				}
			}

			bool runatServer = atts != null && atts.IsRunAtServer ();
			if (builder == null && runatServer) {
				string id = htable ["id"] as string;
				if (id != null && !CodeGenerator.IsValidLanguageIndependentIdentifier (id))
					throw new ParseException (Location, "'" + id + "' is not a valid identifier");
					
				try {
					builder = RootBuilder.CreateSubBuilder (tagid, htable, null, tparser, location);
				} catch (TypeLoadException e) {
					throw new ParseException (Location, "Type not found.", e);
				} catch (HttpException e) {
					CompilationException inner = e.InnerException as CompilationException;
					if (inner != null)
						throw inner;
					
					throw new ParseException (Location, e.Message, e);
				} catch (Exception e) {
					throw new ParseException (Location, e.Message, e);
				}
			}
			
			if (builder == null)
				return false;

			// This is as good as we can do for now - if the parsed location contains
			// both expressions and code render blocks then we're out of luck...
			string plainText = location.PlainText;
			if (!runatServer && plainText.IndexOf ("<%$") == -1&& plainText.IndexOf ("<%") > -1)
				return false;

			PageParserFilter pfilter = PageParserFilter;
			if (pfilter != null && !pfilter.AllowControl (builder.ControlType, builder))
				throw new ParseException (Location, "Control type '" + builder.ControlType + "' not allowed.");
			
			if (!OtherControlsAllowed (builder))
				throw new ParseException (Location, "Only Content controls are allowed directly in a content page that contains Content controls.");
			
			builder.Location = location;
			builder.ID = htable ["id"] as string;
			if (typeof (HtmlForm).IsAssignableFrom (builder.ControlType)) {
				if (inForm)
					throw new ParseException (location, "Only one <form> allowed.");

				inForm = true;
			}

			if (builder.HasBody () && !(builder is ObjectTagBuilder)) {
				if (builder is TemplateBuilder) {
				//	push the id list
				}
				stack.Push (builder, location);
			} else {
				if (!isApplication && builder is ObjectTagBuilder) {
					ObjectTagBuilder ot = (ObjectTagBuilder) builder;
					if (ot.Scope != null && ot.Scope.Length > 0)
						throw new ParseException (location, "Scope not allowed here");

					if (tagtype == TagType.Tag) {
						stack.Push (builder, location);
						return true;
					}
				}
				
				parent.AppendSubBuilder (builder);
				builder.CloseControl ();
			}

			return true;
		}
コード例 #19
0
ファイル: AspParser.cs プロジェクト: sbc100/mono
		void OnTagParsed (TagType tagtype, string id, TagAttributes attributes)
		{
			TagParsedHandler eh = events [tagParsedEvent] as TagParsedHandler;
			if (eh != null)
				eh (this, tagtype, id, attributes);
		}
コード例 #20
0
ファイル: AspGenerator.cs プロジェクト: tgiphil/mono
			void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
			{
				switch (tagtype) {
					case TagType.CodeRender:
						builder.AppendSubBuilder (new CodeRenderBuilder (tagid, false, location));
						break;
						
					case TagType.CodeRenderExpression:
						builder.AppendSubBuilder (new CodeRenderBuilder (tagid, true, location));
						break;
#if NET_4_0
					case TagType.CodeRenderEncode:
						builder.AppendSubBuilder (new CodeRenderBuilder (tagid, true, location, true));
						break;
#endif
					case TagType.DataBinding:
						builder.AppendSubBuilder (new DataBindingBuilder (tagid, location));
						break;

					case TagType.Tag:
					case TagType.SelfClosing:
					case TagType.Close:
						if (generator != null)
							generator.TagParsed (location, tagtype, tagid, attributes);
						else
							goto default;
						break;
						
					default:
						string text = location.PlainText;
						if (text != null && text.Trim ().Length > 0)
							builder.AppendLiteralString (text);
						break;
				}
			}
コード例 #21
0
		void TagParsed (ILocation location, System.Web.Compilation.TagType tagtype, string tagid, TagAttributes attributes)
		{
			if (tagtype != System.Web.Compilation.TagType.Directive)
				throw new ParseException (location, "Unexpected tag");

			if (tagid == null || tagid.Length == 0 || String.Compare (tagid, DefaultDirectiveName, true, Helpers.InvariantCulture) == 0) {
				AddDefaultDirective (location, attributes);
			} else if (String.Compare (tagid, "Assembly", true, Helpers.InvariantCulture) == 0) {
				AddAssemblyDirective (location, attributes);
			} else {
				throw new ParseException (location, "Unexpected directive: " + tagid);
			}
		}
コード例 #22
0
ファイル: AspGenerator.cs プロジェクト: tgiphil/mono
		void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
		{
			bool tagIgnored;
			
			this.location = new Location (location);
			if (tparser != null)
				tparser.Location = location;

			if (text.Length != 0) {
				bool ignoreEmptyString = lastTag == TagType.CodeRender;
#if NET_4_0
				ignoreEmptyString |= lastTag == TagType.CodeRenderEncode;
#endif
				FlushText (ignoreEmptyString);
			}
			
			if (0 == String.Compare (tagid, "script", true, Helpers.InvariantCulture)) {
				bool in_script = (inScript || ignore_text);
				if (in_script) {
					if (ProcessScript (tagtype, attributes))
						return;
				} else
					if (ProcessScript (tagtype, attributes))
						return;
			}

			lastTag = tagtype;
			switch (tagtype) {
			case TagType.Directive:
				if (tagid.Length == 0)
					tagid = tparser.DefaultDirectiveName;

				tparser.AddDirective (tagid, attributes.GetDictionary (null));
				break;
			case TagType.Tag:
				if (ProcessTag (location, tagid, attributes, tagtype, out tagIgnored)) {
					if (!tagIgnored)
						useOtherTags = true;
					break;
				}

				if (useOtherTags) {
					stack.Builder.EnsureOtherTags ();
					stack.Builder.OtherTags.Add (tagid);
				}

				{
					string plainText = location.PlainText;
					if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.Tag))
						TextParsed (location, ChopOffTagStart (location, plainText, tagid));
				}
				break;
			case TagType.Close:
				bool notServer = (useOtherTags && TryRemoveTag (tagid, stack.Builder.OtherTags));
				if (!notServer && CloseControl (tagid))
					break;
				
				TextParsed (location, location.PlainText);
				break;
			case TagType.SelfClosing:
				int count = stack.Count;
				if (!ProcessTag (location, tagid, attributes, tagtype, out tagIgnored) && !tagIgnored) {
					string plainText = location.PlainText;
					if (!ProcessTagsInAttributes (location, tagid, attributes, TagType.SelfClosing))
						TextParsed (location, ChopOffTagStart (location, plainText, tagid));
				} else if (stack.Count != count) {
					CloseControl (tagid);
				}
				break;
			case TagType.DataBinding:
			case TagType.CodeRenderExpression:
			case TagType.CodeRender:
#if NET_4_0
			case TagType.CodeRenderEncode:
#endif
				if (isApplication)
					throw new ParseException (location, "Invalid content for application file.");
			
				ProcessCode (tagtype, tagid, location);
				break;
			case TagType.Include:
				if (isApplication)
					throw new ParseException (location, "Invalid content for application file.");
			
				string file = attributes ["virtual"] as string;
				bool isvirtual = (file != null);
				if (!isvirtual)
					file = attributes ["file"] as string;

				if (isvirtual) {
					bool parsed = false;
					VirtualPathProvider vpp = HostingEnvironment.VirtualPathProvider;

					if (vpp.FileExists (file)) {
						VirtualFile vf = vpp.GetFile (file);
						if (vf != null) {
							Parse (vf.Open (), file, true);
							parsed = true;
						}
					}
					
					if (!parsed)
						Parse (tparser.MapPath (file), true);
				} else {
					string includeFilePath = GetIncludeFilePath (tparser.ParserDir, file);
					CheckIfIncludeFileIsSecure (includeFilePath);
					tparser.PushIncludeDir (Path.GetDirectoryName (includeFilePath));
					try {
						Parse (includeFilePath, true);
					} finally {
						tparser.PopIncludeDir ();
					}
				}
				
				break;
			default:
				break;
			}
			//PrintLocation (location);
		}
コード例 #23
0
		void TagParsed (ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
		{
			this.location = new Location (location);
			if (tparser != null)
				tparser.Location = location;

			if (text.Length != 0)
				FlushText ();

			if (0 == String.Compare (tagid, "script", true)) {
				if (ProcessScript (tagtype, attributes))
					return;
			}

			switch (tagtype) {
			case TagType.Directive:
				if (tagid == "")
					tagid = tparser.DefaultDirectiveName;

				tparser.AddDirective (tagid, attributes.GetDictionary (null));
				break;
			case TagType.Tag:
				if (ProcessTag (tagid, attributes, tagtype)) {
					useOtherTags = true;
					break;
				}

				if (useOtherTags) {
					stack.Builder.EnsureOtherTags ();
					stack.Builder.OtherTags.Add (tagid);
				}

				TextParsed (location, location.PlainText);
				break;
			case TagType.Close:
				bool notServer = (useOtherTags && TryRemoveTag (tagid, stack.Builder.OtherTags));
				if (!notServer && CloseControl (tagid))
					break;
				
				TextParsed (location, location.PlainText);
				break;
			case TagType.SelfClosing:
				int count = stack.Count;
				if (!ProcessTag (tagid, attributes, tagtype)) {
					TextParsed (location, location.PlainText);
				} else if (stack.Count != count) {
					CloseControl (tagid);
				}
				break;
			case TagType.DataBinding:
				goto case TagType.CodeRender;
			case TagType.CodeRenderExpression:
				goto case TagType.CodeRender;
			case TagType.CodeRender:
				if (isApplication)
					throw new ParseException (location, "Invalid content for application file.");
			
				ProcessCode (tagtype, tagid, location);
				break;
			case TagType.Include:
				if (isApplication)
					throw new ParseException (location, "Invalid content for application file.");
			
				string file = attributes ["virtual"] as string;
				bool isvirtual = (file != null);
				if (!isvirtual)
					file = attributes ["file"] as string;

				if (isvirtual) {
					file = tparser.MapPath (file);
				} else {
					file = GetIncludeFilePath (tparser.BaseDir, file);
				}

				InitParser (file);
				DoParse ();
				break;
			default:
				break;
			}
			//PrintLocation (location);
		}