I am creating a web server, and since I can't use typical backend languages, I created my own. With JUST this code, I can compile it, but since the code is embedded into the HTML file, I need to isolate it. A simple code block would look like
<j%:
db store "ethan" as $_GET:demo
print $_GET:demo
:j%>
and I know how to parse the data inside of the beginning ( <j%: ) and end ( :j%> ) elements, since that engine works, I just need to know how to isolate the code inside of that block if it were in a file like this
<j%:
db store "ethan" as $_GET:demo
print $_GET:demo
:j%>
<b>OMG BOI</b>
<p>Output: <j$_GET:demo/j> </p>
<p>Again: <j$_GET:demo/j> </p>
<hr>
<h1>GET Form</h1>
<form method="GET" action="index.html">
<input type="text" name="demo">
<input type="submit">
</form>
<hr>
<h1>POST Form</h1>
<form method="POST" action="index.html">
<input type="text" name="demo">
<input type="submit">
</form>
Jan Vladimir Mostert
Idea Incubator
Assuming your language doesn't allow nesting tags inside other tags, using REGEX to search and replace should work in this scenario.
Java has a Pattern and Matcher class which you could use to compile a pattern and then use the Matcher to loop through all the matches and replace them with content.
This SO example actually does a great job explaining it:
stackoverflow.com/questions/9605716/java-regular-…
If your language allows nesting tags (example would be an if tag inside a loop tag inside another if tag), then it gets a bit messy, you'll need to start building parse trees and recursively do regex matches and store results in a map that simulates the scopes you're trying to create with the nested tags. It's a less trivial exercise, but also doable with REGEX.