Hello, Rustaceans! I’m having two major problems.
- I only have half an idea what I am doing.
- I’ve picked a massive project to work on.
I’m fairly new to Rust. I’ve read the official book, and written enough to feel comfortable with the language. Past that, I do have several years of programming experience. However, that’s through school, so nothing professional, large scale, or necessarily well structured.
With that level of experience, naturally my instinct was to jump in the deep end.
The following is completely valid code:
<<set $foo to 10>> <<set $bar = 15>> <script> console.log("Passage loaded!"); </script> <div> <<if $foo > $bar>> <div class="was-true"> $foo ''>'' $bar </div> <<else>> <div class="was-false"> $foo ''<'' $bar </div> <</if>> </div>
Ignoring a smattering of
<br>, after being interpreted it roughly outputs:
<script> console.log("Passage loaded!"); </script> <div> <div class="was-false"> 10 <strong><</strong> 15 </div> </div>
As far as I can tell, all of this means that I have no off the shelf solution I can use.
Due to the overall complexity and a want for quality error handling, I’m cautious about using a parser generator or lexer generator like nom or logos. At the same time it might not be as simple as stringing together libraries to handle the individual parts.
A library like html5ever wouldn’t be able to handle the macro syntax, and extending it to handle SugarCube is basically rewriting the entire core of the parser. I could do a pass beforehand that escapes anything HTML can’t handle. However, that still needs some level of parsing, and is going to perform poorly.
I haven’t looked too deeply at CSS at this point, but it may be the only place I can just grab a library and run.
Have I forgotten to take some aspect into consideration? Is there a silver bullet I missed? Am I being too picky? If I am writing all of this by hand, how to heck to I properly do string handling with potentially arbitrary file encodings? Is it as simple as dropping in encoding_rs, or is there some complexity hidden there?
Past those questions, I’m open to any tips on being a better programmer in general.