예제 #1
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.Doctype)
            {
                context.Transition(States.Doctype, token);

                return;
            }

            if (token.Type == TokenType.BeginComment)
            {
                context.Transition(States.Comment, token);

                return;
            }

            if (token.Type == TokenType.EndDoc)
            {
                context.Transition(States.End, token);

                return;
            }

            throw new Exception("Hmm, looks like you started declaring something cool then decided not to: " + token.Type);
        }
예제 #2
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (!GotTagName)
            {
                if (token.Type == TokenType.TagName)
                {
                    TagName    = token.Value;
                    GotTagName = true;

                    return;
                }

                throw new Exception("I was expecting a Tag Name, but I got: " + token.Type);
            }

            if (token.Type == TokenType.EndTag)
            {
                context.TreeBuilder.CompleteCurrentElement(TagName);
                context.Transition(States.Start, token);

                return;
            }

            throw new Exception("Are you not going to end your tags properly, with a '>', because, whatever: " + token.Type);
        }
예제 #3
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.AttributeName)
            {
                context.Transition(States.Attributes, token);

                return;
            }

            if (token.Type == TokenType.EndTag)
            {
                context.Transition(States.Start, token);

                return;
            }

            if (token.Type == TokenType.SelfCloseTag)
            {
                context.TreeBuilder.CompleteCurrentElement();
                context.Transition(States.Start, token);

                return;
            }

            throw new Exception("I'm sitting here thinking you were going to define a tag, but instead you're doing this: " + token.Type);
        }
예제 #4
0
        public bool Load(TextReader htmlData)
        {
            if (htmlData == null)
            {
                ParseError = "HTML data is NULL";

                return(false);
            }

            if (htmlData.Peek() < 0)
            {
                DocRoot = new ElementNode("root");

                return(true);
            }

            Lexer        = new HtmlLexerGizmo(ProcessToken);
            StateMachine = new HtmlStateMachineGizmo();
            bool ok = true;

            try
            {
                Lexer.Gimme(htmlData);
            }
            catch (Exception ex)
            {
                ok         = false;
                ParseError = ex.Message;
            }

            DocRoot = StateMachine.TreeBuilder.Root;

            return(ok);
        }
예제 #5
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.TagName)
            {
                context.Transition(States.Name, token);

                return;
            }

            throw new Exception("I expected to get a Tag Name, but instead I got " + token.Type);
        }
예제 #6
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.MarkupDecl)
            {
                context.Transition(States.Declaration, token);

                return;
            }

            if (token.Type == TokenType.OpenTag)
            {
                context.Transition(States.Element, token);

                return;
            }

            if (token.Type == TokenType.Text)
            {
                context.TreeBuilder.AddChildText(token.Value);

                return;
            }

            if (token.Type == TokenType.CloseTag)
            {
                context.Transition(States.TagDone, token);

                return;
            }

            if (token.Type == TokenType.Code)
            {
                context.Transition(States.Code, token);

                return;
            }

            if (token.Type == TokenType.EndDoc)
            {
                context.Transition(States.End, token);

                return;
            }

            throw new Exception("I was expecting either a Markup Delcaration or Open Tag, but I got: " + token.Type);
        }
예제 #7
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.EndComment)
            {
                context.Transition(States.Start, token);

                return;
            }

            if (token.Type == TokenType.EndDoc)
            {
                context.Transition(States.End, token);

                return;
            }

            throw new Exception("You were making a comment, some profound statement about life or whatever, but then got distracted by fart videos? " + token.Type);
        }
예제 #8
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.EndTag)
            {
                context.Transition(States.Start, token);

                return;
            }

            if (token.Type == TokenType.EndDoc)
            {
                context.Transition(States.End, token);

                return;
            }

            throw new Exception("Well, you started declaring a Doctype then decided not to? " + token.Type);
        }
예제 #9
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.BeginDoc)
            {
                context.TreeBuilder.CreateRoot();
                context.Transition(States.Start, token);

                return;
            }

            if (token.Type == TokenType.EndDoc)
            {
                context.Transition(States.End, token);

                return;
            }

            throw new Exception("Unexpected token: " + token.Type);
        }
예제 #10
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.Code)
            {
                context.TreeBuilder.AddChildText(token.Value);

                return;
            }

            if (token.Type == TokenType.EndCode)
            {
                context.TreeBuilder.CompleteCurrentElement("script");
                context.Transition(States.Start, token);

                return;
            }

            throw new Exception("I was waiting for some Code stuff, but got this crap: " + token.Type);
        }
예제 #11
0
        public override void Accept(Token token, HtmlStateMachineGizmo context)
        {
            if (token.Type == TokenType.AttributeName)
            {
                Name = token.Value;
                context.TreeBuilder.AddAttribute(Name, string.Empty);

                return;
            }

            if (token.Type == TokenType.AttributeValue)
            {
                if (Name.Length == 0)
                {
                    throw new Exception("I think you should try assigning a name to Attribute before giving me a value: " + token.Value);
                }

                context.TreeBuilder.AddAttribute(Name, token.Value);
                Name = string.Empty;

                return;
            }

            if (token.Type == TokenType.EndTag)
            {
                context.Transition(States.Start, token);

                return;
            }

            if (token.Type == TokenType.SelfCloseTag)
            {
                context.TreeBuilder.CompleteCurrentElement();
                context.Transition(States.Start, token);

                return;
            }

            throw new Exception("I was thinking I'd get some Attribute stuff and eventually an End Tag, but instead I got this: " + token.Type);
        }
예제 #12
0
 public override void Accept(Token token, HtmlStateMachineGizmo context)
 {
     throw new Exception("This is the end of the document, you're supposed to be done, yet you keep trying to feed me tokens?? WTF?");
 }
예제 #13
0
 public override void Enter(Token token, HtmlStateMachineGizmo context)
 {
 }
예제 #14
0
 public override void Enter(Token token, HtmlStateMachineGizmo context)
 {
     context.TreeBuilder.AddChildText(token.Value);
 }
예제 #15
0
 public override void Enter(Token token, HtmlStateMachineGizmo context)
 {
     GotTagName = false;
     TagName    = string.Empty;
 }
예제 #16
0
 public override void Enter(Token token, HtmlStateMachineGizmo context)
 {
     Name = token.Value;
     context.TreeBuilder.AddAttribute(Name, string.Empty);
 }