Okay, everybody, we're going to make a string token now in this lecture.
So very first thing we're going to do, go above read next token and we're going to say static struct
token token, make string.
Okay, guys.
And this function is going to accept two arguments a start the limiter and an end the limiter.
So what is a start?
The limiter and an end the limiter.
Well, hello world.
What's start the limiter?
It's these double quote character.
What's our end de limiter?
It's the Double Quote character.
That's what they are.
So we're going to create a buffer
and we're just going to go Char C equals next C and we're going to make a for loop.
Okay.
So we're not going to initialize anything in this for loop, hence why there's a semicolon.
The condition will be that if the character hasn't reached the end of limiter yet and it hasn't reached
end of file, then we'll read the next character.
So now we're going to say if C equals two back slashes, then we need to handle an escape.
But that's not going to be done in this lecture because it's kind of separate.
Right.
So what do I mean by an escape?
Hello, world backslash n that's an escape.
Yeah.
So we're making new lines.
So this is what this is for capturing that, right?
So we're just going to continue when we see that and then we're going to buffer right into buffer character
C and now we're going to say buffer write buffer 000 for our null Terminator.
And now we're going to go return token create struct token type equals token type string.
Asphalt equals buffer pointer buff.
So that creates a string token with the string value equals equaling the buffer pointer, which is where
we've written the string to.
So that makes sense.
So we go through all of the string until we find any file or the end delimiter.
We attach a null terminator and then we create a string token with the s val equaling the buffer of
where our string has been read into.
So now we scroll down and just by here we're going to say case and we're just going to put the quotes
and then we're going to say Break.
Token equals token make string.
And the start.
The limiter is going to be the double quotes and the end.
The limiter is going to be the double quotes.
Okay, so just go back to token, make string, because there is something that we left out just by
here we're going to say assert next C equals start the limiter because we need to pop off that, that,
that quote.
Right, because otherwise that quote is going to go into the buffer and we don't want that.
Right.
So we want to read it and we want to make sure it's actually the start, the limiter.
So just scroll up and we're going to include assert and basically the program will will exit if the
assertion fails and it'll tell us what went wrong.
So that's quite useful for debugging, right.
So now let's open up the terminal and we're going to go make clean, make just go to test at C and we're
going to create a string.
Hello.
And we're just going to do main and it says everything compiled fine.
We're going to write a number and now another string,
everything compile fine.
So yes, so that is parsing of strings.
So you can see it's not too bad and that works quite well.
We still haven't created the escapes.
So you're unable to do things like Hello World Backslash n we will implement the escapes, but it's
the wrong time in the course to do so.
So we now have string tokens.