Thursday | 21 NOV 2024
[ previous ]
[ next ]

The Template Language - Variables

Title:
Date: 2023-06-16

I've now added support for setting variables and to print them out. The PRINT statement will output to the screen during the compilation process. Not useful in a templating language but this is quickly moving out of the realm of templates and into something else.

I think I'm building something you could easily shoot yourself in the foot with.

I'm also happy at how easily I added these 2 things, it means that I'm probably on the {right track} [Inshallah] for how I designed the RENDER and EVALUATE functions.

My belief that I'm on the right path has been shaken. I implemented the FOR loop logic and that seems to have added some complexity that I wasn't expecting. I need to build up a block when the FOR keyword is reached but I had written my logic such that parsing was on a line by line basis.

This meant I had to do some processing and saving of tokens and then checking if it was block oriented keyword or if it was a line keyword. Line keywords would go straight to my parsing whereas the block keyword would trigger a loop to eat as many characters as possible until the block is finished.

The logic to figure out the blocks is also not straightforward, I need to scann until I reach a double curly brace. I would then launch my scanner to scan a BASIC line. I then need tokenize this line. Then I can check if it is the ending piece of my block. If it is then I can close the block. However if it isn't the ending piece then I would need to add this scanned line into my block so that I could continue building the block up.

It's much less code than my previous attempts but this still doesn't feel right and I think there is a {elegant solution} [I also need to make sure I abuse the postfix stuff as I think extraction and substring operations could have been made much simpler if I made them operations rather than coding them up.] just waiting.