Thursday | 31 OCT 2024
[ previous ]
[ next ]

The Template Language - FOR

Title:
Date: 2023-06-17

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.

I've now switched to using my render routine to generate my blog's main page. This has gone pretty well as there is no conditional logic and so I can get away with just using the FOR loop and variable resolution. This was gratifying, to see my blog main page getting generated. I need to write a routine to generate the index page of all my posts and then I want to also write a routine generate my blog posts as well. This would get rid of all the string munging that I do currently and replace it with my own custom template engine.