add in as an operator
This commit is contained in:
51
final_test.ar
Normal file
51
final_test.ar
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
let __makeFile(name, type, data) = do
|
||||
let save(path) = do
|
||||
let file = file.write(path)
|
||||
file.buffer(data)
|
||||
file.close()
|
||||
File.save = save
|
||||
|
||||
let __multipart(req, res) = do
|
||||
let boundary = buffer().from(req.headers.splitN("boundary=", 2))
|
||||
let newLineSplit = buffer().from("\r\n\r\n")
|
||||
let parts = req.buffer.body.split(boundary)
|
||||
if (true) do
|
||||
let str = parts.to("string")
|
||||
if (str == "" || str=="--" || str=="--\r\n") do
|
||||
str = null
|
||||
let headers = []
|
||||
let lines = parts.splitN(newLineSplit, 2)
|
||||
let headerLines = lines.to("string").split("\r\n")
|
||||
if (true) do
|
||||
let header = headerLines.splitN(": ", 2)
|
||||
if (header.length != 2) do
|
||||
headers = header
|
||||
if (lines.length != 2) do
|
||||
let body = lines
|
||||
if (i != parts.length-1) do
|
||||
body = body.slice(0, body.length-4)
|
||||
if ("content-disposition" in headers) do
|
||||
let disposition = headers.split("; ")
|
||||
if (disposition == "form-data") do
|
||||
let name = json.parse(disposition.splitN("=", 2))
|
||||
if (disposition.length >= 3) do
|
||||
let filename = json.parse(disposition.splitN("=", 2))
|
||||
req.files = __makeFile(filename, headers, body)
|
||||
else do
|
||||
req.formdata = body.to("string")
|
||||
res.next()
|
||||
|
||||
|
||||
let formdata(req, res) = do
|
||||
req.formdata = {}
|
||||
req.files = {}
|
||||
|
||||
if (req.method != "POST") return res.next()
|
||||
if ("content-type" not in req.headers) return res.next()
|
||||
let loweredContentType = req.headers["content-type"].lower()
|
||||
if (loweredContentType.startswith("multipart/form-data")) return __multipart(req, res)
|
||||
else if (loweredContentType.startswith("application/x-www-form-urlencoded")) req.formdata = url.decodeURLQuery(req.buffer.body.to("string"))
|
||||
else if (loweredContentType.startswith("application/json")) req.formdata = json.parse(req.buffer.body.to("string"))
|
||||
else req.files.file = __makeFile("file", req.headers["content-type"], req.buffer.body)
|
||||
res.next()
|
||||
@@ -30,6 +30,7 @@ int yywrap(void * unused_param) {
|
||||
"^=" { return TOKEN_ASSIGN_CARET; }
|
||||
|
||||
"not"[ \t]+"in" { return TOKEN_NOT_IN; }
|
||||
"in" { return TOKEN_IN; }
|
||||
"&&" { return TOKEN_AND; }
|
||||
"||" { return TOKEN_OR; }
|
||||
"<=" { return TOKEN_LE; }
|
||||
@@ -65,7 +66,6 @@ int yywrap(void * unused_param) {
|
||||
"null" { return TOKEN_NULL; }
|
||||
"delete" { return TOKEN_DELETE; }
|
||||
"not" { return TOKEN_NOT; }
|
||||
"in" { return TOKEN_IN; }
|
||||
"try" { return TOKEN_TRY; }
|
||||
"catch" { return TOKEN_CATCH; }
|
||||
|
||||
@@ -86,11 +86,11 @@ int yywrap(void * unused_param) {
|
||||
return TOKEN_STRING;
|
||||
}
|
||||
|
||||
\-?((([0-9]+(\.[0-9]+)?)|(\.[0-9]+))(e((\-|\+)?([0-9]+(\.[0-9]+)?)))?) {
|
||||
((([0-9]+(\.[0-9]+)?)|(\.[0-9]+))(e((\-|\+)?([0-9]+(\.[0-9]+)?)))?) {
|
||||
return TOKEN_NUMBER;
|
||||
}
|
||||
|
||||
\n { return TOKEN_NEW_LINE; }
|
||||
"\n" { return TOKEN_NEW_LINE; }
|
||||
|
||||
[ \t]+ {
|
||||
GET_STATE
|
||||
|
||||
@@ -34,7 +34,8 @@ typedef enum {
|
||||
TOKEN_GE, // >=
|
||||
TOKEN_EQ, // ==
|
||||
TOKEN_NE, // !=
|
||||
TOKEN_NOT_IN, // not in (Usually treated like a comparison)
|
||||
TOKEN_NOT_IN, // not in
|
||||
TOKEN_IN, // in
|
||||
TOKEN_AND, // &&
|
||||
TOKEN_OR, // ||
|
||||
|
||||
@@ -57,7 +58,6 @@ typedef enum {
|
||||
TOKEN_NULL,
|
||||
TOKEN_DELETE,
|
||||
TOKEN_NOT,
|
||||
TOKEN_IN,
|
||||
TOKEN_TRY,
|
||||
TOKEN_CATCH,
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ ParsedValue *parse_assign(char *file, DArray *tokens, ParsedValue *assign_to,
|
||||
Token *token = darray_get(tokens, *index);
|
||||
switch (assign_to->type) {
|
||||
case AST_IDENTIFIER:
|
||||
case AST_ASSIGN:
|
||||
case AST_ACCESS:
|
||||
break;
|
||||
case AST_CALL:;
|
||||
ParsedCall *call = assign_to->data;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#define SWITCH_OPERATIONS case TOKEN_AND:\
|
||||
case TOKEN_OR:\
|
||||
case TOKEN_NOT_IN:\
|
||||
case TOKEN_IN:\
|
||||
case TOKEN_LE:\
|
||||
case TOKEN_GE:\
|
||||
case TOKEN_LT:\
|
||||
|
||||
Reference in New Issue
Block a user