mirror of
https://github.com/vgstation-coders/vgstation13.git
synced 2025-12-09 16:14:13 +00:00
SDQL ARRAYS
HYPE HYPE Sorry no assoc, couldn't get it to work.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
--You can use operators other than ==, such as >, <=, != and etc..
|
||||
|
||||
--Lists can be done through [], so say UPDATE /mob SET client.color = [1, 0.75, ...].
|
||||
*/
|
||||
|
||||
/client/proc/SDQL2_query(var/query_text as message)
|
||||
@@ -26,7 +27,11 @@
|
||||
if(!query_text || length(query_text) < 1)
|
||||
return
|
||||
|
||||
//world << query_text
|
||||
var/query_log = "[key_name(src)] executed SDQL query: \"[query_text]\"."
|
||||
world.log << query_log
|
||||
message_admins(query_log)
|
||||
log_game(query_log)
|
||||
sleep(-1) // Incase the server crashes due to a huge query, we allow the server to log the above things (it might just delay it).
|
||||
|
||||
var/list/query_list = SDQL2_tokenize(query_text)
|
||||
|
||||
@@ -76,11 +81,6 @@
|
||||
if(SDQL_expression(d, query_tree["where"]))
|
||||
objs += d
|
||||
|
||||
var/query_log = "[key_name(src)] executed SDQL query: \"[query_text]\"."
|
||||
world.log << query_log
|
||||
message_admins(query_log)
|
||||
log_game(query_log)
|
||||
|
||||
switch(query_tree[1])
|
||||
if("call")
|
||||
var/list/call_list = query_tree["call"]
|
||||
@@ -301,7 +301,6 @@
|
||||
return result
|
||||
|
||||
/proc/SDQL_value(datum/object, list/expression, start = 1)
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/SDQL_value() called tick#: [world.time]")
|
||||
var/i = start
|
||||
var/val = null
|
||||
|
||||
@@ -335,6 +334,12 @@
|
||||
else if(copytext(expression[i], 1, 2) in list("'", "\""))
|
||||
val = copytext(expression[i], 2, length(expression[i]))
|
||||
|
||||
else if(expression[i] == "\[")
|
||||
var/list/expressions_list = expression[++i]
|
||||
val = list()
|
||||
for(var/list/expression_list in expressions_list)
|
||||
val += SDQL_expression(object, expression_list)
|
||||
|
||||
else
|
||||
val = SDQL_var(object, expression, i)
|
||||
i = expression.len
|
||||
@@ -342,9 +347,6 @@
|
||||
return list("val" = val, "i" = i)
|
||||
|
||||
/proc/SDQL_var(datum/object, list/expression, start = 1)
|
||||
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/SDQL_var() called tick#: [world.time]")
|
||||
|
||||
if(expression[start] in object.vars)
|
||||
|
||||
if(start < expression.len && expression[start + 1] == ".")
|
||||
@@ -361,7 +363,7 @@
|
||||
//writepanic("[__FILE__].[__LINE__] (no type)([usr ? usr.ckey : ""]) \\/proc/SDQL2_tokenize() called tick#: [world.time]")
|
||||
|
||||
var/list/whitespace = list(" ", "\n", "\t")
|
||||
var/list/single = list("(", ")", ",", "+", "-", ".")
|
||||
var/list/single = list("(", ")", ",", "+", "-", ".", "\[", "]")
|
||||
var/list/multi = list(
|
||||
"=" = list("", "="),
|
||||
"<" = list("", "=", ">"),
|
||||
|
||||
@@ -405,6 +405,39 @@
|
||||
|
||||
return i + 1
|
||||
|
||||
//array: '[' expression, expression, ... ']'
|
||||
/datum/SDQL_parser/proc/array(var/i, var/list/node)
|
||||
// Arrays get turned into this: list("[", list(exp_1a = exp_1b, ...), ...), "[" is to mark the next node as an array.
|
||||
if(copytext(token(i), 1, 2) != "\[")
|
||||
parse_error("Expected an array but found '[token(i)]'")
|
||||
return i + 1
|
||||
|
||||
node += token(i) // Add the "["
|
||||
|
||||
var/list/expression_list = list()
|
||||
|
||||
if(token(i + 1) != "]")
|
||||
var/list/temp_expression_list = list()
|
||||
|
||||
do
|
||||
i = expression(i + 1, temp_expression_list)
|
||||
|
||||
if(token(i) == ",")
|
||||
expression_list[++expression_list.len] = temp_expression_list
|
||||
|
||||
temp_expression_list = list()
|
||||
|
||||
while(token(i) && token(i) != "]")
|
||||
|
||||
expression_list[++expression_list.len] = temp_expression_list
|
||||
|
||||
else
|
||||
|
||||
i++
|
||||
|
||||
node[++node.len] = expression_list
|
||||
|
||||
return i + 1
|
||||
|
||||
//call_function: <function name> ['(' [arguments] ')']
|
||||
/datum/SDQL_parser/proc/call_function(i, list/node, list/arguments)
|
||||
@@ -412,6 +445,7 @@
|
||||
node += token(i++)
|
||||
if(token(i) != "(")
|
||||
parse_error("Expected ( but found '[token(i)]'")
|
||||
|
||||
else if(token(i + 1) != ")")
|
||||
var/list/temp_expression_list = list()
|
||||
do
|
||||
@@ -420,6 +454,7 @@
|
||||
arguments[++arguments.len] = temp_expression_list
|
||||
temp_expression_list = list()
|
||||
continue
|
||||
|
||||
while(token(i) && token(i) != ")")
|
||||
|
||||
arguments[++arguments.len] = temp_expression_list // The code this is copy pasted from won't be executed when it's the last param, this fixes that.
|
||||
@@ -539,6 +574,8 @@
|
||||
else if(copytext(token(i), 1, 2) in list("'", "\""))
|
||||
i = string(i, node)
|
||||
|
||||
else if(copytext(token(i), 1, 2) == "\[") // Start a list.
|
||||
i = array(i, node)
|
||||
else
|
||||
i = variable(i, node)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user