From the course: Vanilla JavaScript: Building on the Document Object Model (DOM)

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Parsing comments

Parsing comments

- Now that we have a basic parsing loop implemented, we need to start recognizing different types of HTML markup. And the simplest type of markup to recognize is the HTML comments. So let's start there. Let's go back to our browser briefly. And in our HTML sample, you can see we have a comment right here at the very beginning, and it consists of this opening tag syntax here, which is a less than bang dash dash. And it's ended with dash dash greater than 10. And there are some more complicated rules about comments, but we're not going to mess with them. We're just going to stick with this. So let's go back to our code and in our parsing loop here, we're going to just add an if statement. So what we can do is if we find this opening token, so we're going to use the lexer consume a match so remember consume match looks for a token, and then it will actually discard that token if it finds it, but it'll return true. So we will…

Contents