removing each

This commit is contained in:
Mike Nolan 2024-09-01 22:19:22 -05:00
commit 1c9707b5b8
11 changed files with 5528 additions and 0 deletions

12
file.twss Normal file
View File

@ -0,0 +1,12 @@
<!--tws
d = list();
d.add(5);
d.add(6);
d.add("Demi Lovato");
each(d)
{
print item;
print "\n";
}
-->

8
main.twss Normal file
View File

@ -0,0 +1,8 @@
<!--tws
print 37 + 1 + 4;
-->
John
<!--tws
print "Demi Lovato\n";
print "John";
-->

36
templater.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "tesseswebserver.hpp"
TESSESWEBSERVER_STATIC_DECLARATION
using namespace Tesses::WebServer;
using namespace Tesses::WebServer::ScriptEngine;
int main(int argc,char** argv)
{
RootEnvironment* rEnv = new RootEnvironment();
rEnv->print = [](ScriptType arg)-> void {
std::cout << ConvertToString(arg);
};
BytecodeCompiler bcc(ScriptParser::Parse("file.twss"));
bcc.Compile();
auto rf = bcc.file->rootFunction;
rf->env = rEnv;
rf->isRoot=true;
for(auto f : bcc.file->functions)
{
auto rf2 = f.second;
rf2->env = rEnv;
rf2->isRoot=false;
rEnv->SetValue(f.first,ObjectType(f.second));
}
rf->Execute(rEnv,{});
}

4242
tessesscriptengine.hpp Normal file

File diff suppressed because it is too large Load Diff

41
tesseswebserver.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "tesseswebserver.hpp"
TESSESWEBSERVER_STATIC_DECLARATION
using namespace Tesses::WebServer;
using namespace Tesses::WebServer::ScriptEngine;
class DummyServer : public IServer
{
public:
bool Handle(ServerContext* ctx)
{
std::string resp = {};
for(auto param : ctx->queryParams.GetAll())
{
resp.append(param.first);
resp.append(": ");
resp.append(param.second);
resp.append("\r\n");
}
ctx->SetContentType("text/plain")->SendText(resp);
return true;
}
};
int main(int argc,char** argv)
{
HttpServerListener::Init();
IServer* myServer = new DummyServer();
HttpServerListener::Listen(myServer,3000);
}

1142
tesseswebserver.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
#pragma once
#define USE_SCRIPT_ENGINE
#define USE_MBEDTLS
#define USE_CURL
#define USE_SQLITE3
#define USE_JANSSON

View File

@ -0,0 +1,8 @@
<!--tws
t = post("text");
if(t != null)
{
todos.add(t);
}
redirect("/");
-->

3
wwwroot/deinit.twss Normal file
View File

@ -0,0 +1,3 @@
<!--tws
free(todos);
-->

26
wwwroot/index.twss Normal file
View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDo List</title>
</head>
<body>
<h1>ToDo List</h1>
<form method="POST" action="./cgi-bin/add-todo.twss">
<input type="text" name="text" placeholder="ToDo Text">
<input type="submit" value="Add">
</form>
<ul>
<!--tws
each(global todos) {
-->
<li><!--tws print htmlencode(item); --></li>
<!--tws
}
-->
</ul>
</body>
</html>

3
wwwroot/init.twss Normal file
View File

@ -0,0 +1,3 @@
<!--tws
todos = list();
-->