Exemplo n.º 1
0
 void OnTagParsed(TagType tagtype, string id, TagAttributes attributes)
 {
     if (TagParsed != null)
     {
         TagParsed(this, tagtype, id, attributes);
     }
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
        public override ParsingObject CreateChildParsingObject(ILocation location, string tagid, TagAttributes attributes)
        {
            switch (mode)
            {
            case ParseChildrenMode.DefaultProperty:
                //oops, we didn't need to tokenise this.
                innerText += location.PlainText;
                //how do we get end tag?
                throw new NotImplementedException("Inner default properties that look like tags have not been implemented yet.");

            case ParseChildrenMode.DefaultEncodedProperty:
                innerText += System.Web.HttpUtility.HtmlDecode(location.PlainText);
                //how do we get end tag?
                throw new NotImplementedException("Inner default properties that look like tags have not been implemented yet.");

            case ParseChildrenMode.Controls:
                //html tags
                if (tagid.IndexOf(':') == -1)
                {
                    return(new HtmlParsingObject(location.PlainText, tagid, this));
                }
                goto case ParseChildrenMode.DefaultCollectionProperty;

            case ParseChildrenMode.DefaultCollectionProperty:
                string[] str = tagid.Split(':');
                if (str.Length != 2)
                {
                    throw new ParseException(location, "Server tag name is not of form prefix:name");
                }

                Type tagType = WebFormReferenceManager.GetObjectType(str[0], str[1]);
                if (tagType == null)
                {
                    throw new ParseException(location, "The tag " + tagid + "has not been registered");
                }

                return(new ServerObjectParsingObject(tagType, attributes.GetDictionary(null), tagid, this));

            case ParseChildrenMode.Properties:
                throw new NotImplementedException("Multiple child properties have not yet been implemented.");
            }
            throw new ParseException(location, "Unexpected state encountered: ");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a ParsingObject as a child of this one, and returns it.
        /// </summary>
        public virtual ParsingObject CreateChildParsingObject(ILocation location, string tagid, TagAttributes attributes)
        {
            string[] str = tagid.Split(':');

            //html tags
            //TODO: check for valid tags?
            if (str.Length == 1)
            {
                if (attributes.IsRunAtServer() && (0 == string.Compare("form", tagid)))
                {
                    return(new ServerFormParsingObject(location.PlainText, tagid, this));
                }
                return(new HtmlParsingObject(location.PlainText, tagid, this));
            }

            //fall through to server tags
            if (str.Length != 2)
            {
                throw new ParseException(location, "Server tag name is not of form prefix:name");
            }

            Type tagType = WebFormReferenceManager.GetObjectType(str[0], str[1]);

            if (tagType == null)
            {
                throw new ParseException(location, "The tag " + tagid + "has not been registered");
            }

            return(new ServerObjectParsingObject(tagType, attributes.GetDictionary(null), tagid, this));
        }
Exemplo n.º 6
0
        /*TODO: if only we could get the controlbuilder to build the control like in .NET 2's builder.BuildObject ()
         * ControlBuilder builder = ControlBuilder.CreateBuilderFromType (null, b, tagType, str[1], (string) attributes["ID"], attributes.GetDictionary (null), currentLocation.BeginLine, currentLocation.Filename);
         *
         * if (builder == null)
         *      throw new ParseException (currentLocation, "Could not create builder for type " + tagType);
         * builder.SetServiceProvider (host);
         * Control c = builder.BuildObject ();
         */

        void ProcessDirective(string tagid, TagAttributes attributes)
        {
            string placeholder = document.AddDirective(tagid, attributes.GetDictionary(null));

            openObject.AddText(placeholder);
        }
Exemplo n.º 7
0
        void TagParsed(ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
        {
            switch (tagtype)
            {
            case TagType.Close:
                if (openObject == null)
                {
                    throw new ParseException(location, "There are more closing tags than opening tags");
                }

                if (0 != string.Compare(openObject.TagID, tagid))
                {
                    throw new ParseException(location, "Closing tag " + tagid + " does not match opening tag " + openObject.TagID);
                }
                openObject = openObject.CloseObject(location.PlainText);
                break;

            case TagType.CodeRender:
                throw new NotImplementedException("Code render expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.CodeRenderExpression:
                throw new NotImplementedException("Code render expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.DataBinding:
                throw new NotImplementedException("Data binding expressions have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.Directive:
                ProcessDirective(tagid, attributes);
                break;

            case TagType.Include:
                throw new NotImplementedException("Server-side includes have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.ServerComment:
                throw new NotImplementedException("Server comments have not yet been implemented: " + location.PlainText);

            //break;
            case TagType.Tag:
                //TODO: don't do this for XHTML
                if ((string.Compare(tagid, "br", true) == 0) ||
                    (string.Compare(tagid, "hr", true) == 0))
                {
                    goto case TagType.SelfClosing;
                }

                openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                break;

            case TagType.SelfClosing:
                if (openObject == null)
                {
                    throw new Exception("Root tag cannot be self-closing");
                }

                openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                openObject = openObject.CloseObject(string.Empty);
                break;

            case TagType.Text:
                throw new NotImplementedException("Text tagtypes have not yet been implemented: " + location.PlainText);
                //break;
            }
        }
Exemplo n.º 8
0
        void TagParsed(ILocation location, TagType tagtype, string tagid, TagAttributes attributes)
        {
            switch (tagtype)
            {
                case TagType.Close:
                    if (openObject == null)
                        throw new ParseException (location, "There are more closing tags than opening tags");

                    if (0 != string.Compare (openObject.TagID, tagid))
                        throw new ParseException (location, "Closing tag " + tagid + " does not match opening tag " + openObject.TagID);
                    openObject = openObject.CloseObject (location.PlainText);
                    break;
                case TagType.CodeRender:
                    throw new NotImplementedException ("Code render expressions have not yet been implemented: " + location.PlainText);
                    //break;
                case TagType.CodeRenderExpression:
                    throw new NotImplementedException ("Code render expressions have not yet been implemented: " + location.PlainText);
                    //break;
                case TagType.DataBinding:
                    throw new NotImplementedException("Data binding expressions have not yet been implemented: " + location.PlainText);
                    //break;
                case TagType.Directive:
                    ProcessDirective (tagid, attributes);
                    break;
                case TagType.Include:
                    throw new NotImplementedException ("Server-side includes have not yet been implemented: " + location.PlainText);
                    //break;
                case TagType.ServerComment:
                    throw new NotImplementedException ("Server comments have not yet been implemented: " + location.PlainText);
                    //break;
                case TagType.Tag:
                    //TODO: don't do this for XHTML
                    if ((string.Compare (tagid, "br", true) == 0)
                        || (string.Compare (tagid, "hr", true) == 0))
                        goto case TagType.SelfClosing;

                    openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                    break;
                case TagType.SelfClosing:
                    if (openObject == null)
                        throw new Exception ("Root tag cannot be self-closing");

                    openObject = openObject.CreateChildParsingObject(location, tagid, attributes);
                    openObject = openObject.CloseObject(string.Empty);
                    break;
                case TagType.Text:
                    throw new NotImplementedException("Text tagtypes have not yet been implemented: " + location.PlainText);
                    //break;
            }
        }
Exemplo n.º 9
0
        /*TODO: if only we could get the controlbuilder to build the control like in .NET 2's builder.BuildObject ()
        ControlBuilder builder = ControlBuilder.CreateBuilderFromType (null, b, tagType, str[1], (string) attributes["ID"], attributes.GetDictionary (null), currentLocation.BeginLine, currentLocation.Filename);

        if (builder == null)
            throw new ParseException (currentLocation, "Could not create builder for type " + tagType);
        builder.SetServiceProvider (host);
        Control c = builder.BuildObject ();
        */
        void ProcessDirective(string tagid, TagAttributes attributes)
        {
            string placeholder = document.AddDirective (tagid, attributes.GetDictionary (null));
            openObject.AddText (placeholder);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a ParsingObject as a child of this one, and returns it.
        /// </summary>
        public virtual ParsingObject CreateChildParsingObject(ILocation location, string tagid, TagAttributes attributes)
        {
            string[] str = tagid.Split(':');

            //html tags
            //TODO: check for valid tags?
            if (str.Length == 1)
            {
                if (attributes.IsRunAtServer () && (0 == string.Compare ("form", tagid)))
                    return new ServerFormParsingObject (location.PlainText, tagid, this);
                return new HtmlParsingObject (location.PlainText, tagid, this);
            }

            //fall through to server tags
            if (str.Length != 2)
                throw new ParseException (location, "Server tag name is not of form prefix:name");

            Type tagType = WebFormReferenceManager.GetObjectType(str[0], str[1]);
            if (tagType == null)
                throw new ParseException(location, "The tag " + tagid + "has not been registered");

            return new ServerObjectParsingObject (tagType, attributes.GetDictionary(null), tagid, this);
        }
Exemplo n.º 11
0
 void OnTagParsed(TagType tagtype, string id, TagAttributes attributes)
 {
     if (TagParsed != null)
         TagParsed (this, tagtype, id, attributes);
 }
Exemplo n.º 12
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;
            }
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
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;
        }
Exemplo n.º 15
0
        public override ParsingObject CreateChildParsingObject(ILocation location, string tagid, TagAttributes attributes)
        {
            switch (mode) {
                case ParseChildrenMode.DefaultProperty:
                    //oops, we didn't need to tokenise this.
                    innerText += location.PlainText;
                    //how do we get end tag?
                    throw new NotImplementedException ("Inner default properties that look like tags have not been implemented yet.");
                case ParseChildrenMode.DefaultEncodedProperty:
                    innerText += System.Web.HttpUtility.HtmlDecode (location.PlainText);
                    //how do we get end tag?
                    throw new NotImplementedException ("Inner default properties that look like tags have not been implemented yet.");
                case ParseChildrenMode.Controls:
                    //html tags
                    if (tagid.IndexOf(':') == -1)
                        return new HtmlParsingObject (location.PlainText, tagid, this);
                    goto case ParseChildrenMode.DefaultCollectionProperty;
                case ParseChildrenMode.DefaultCollectionProperty:
                    string[] str = tagid.Split(':');
                    if (str.Length != 2)
                        throw new ParseException (location, "Server tag name is not of form prefix:name");

                    Type tagType = WebFormReferenceManager.GetObjectType(str[0], str[1]);
                    if (tagType == null)
                        throw new ParseException(location, "The tag " + tagid + "has not been registered");

                    return new ServerObjectParsingObject (tagType, attributes.GetDictionary(null), tagid, this);
                case ParseChildrenMode.Properties:
                    throw new NotImplementedException ("Multiple child properties have not yet been implemented.");
            }
            throw new ParseException (location, "Unexpected state encountered: ");
        }
Exemplo n.º 16
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;
            }
        }