Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
theludovyc committed Oct 27, 2023
1 parent b08c5dc commit fed1430
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Test/TestParser/TestVariables/TestVariables.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ func test_variables():

assert_variable("a", TYPE_INT, 1)

assert_variable("b", TYPE_FLOAT, 2.5)
assert_variable("b", TYPE_FLOAT, 3.5)

assert_variable("c", TYPE_STRING, "Hello, world !")

assert_variable("d", TYPE_INT, Rakugo.get_variable("a"))
assert_variable("d", TYPE_INT, -1)

assert_variable("Sy.name", TYPE_STRING, "Sylvie")

assert_variable("Sy.life", TYPE_INT, 5)

assert_variable("e", TYPE_INT, Rakugo.get_variable("Sy.life"))

assert_variable("Sy.life", TYPE_INT, 10)

assert_eq(Rakugo.get_variable("f"), null)
9 changes: 7 additions & 2 deletions Test/TestParser/TestVariables/TestVariables.rk
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
a = 1
b = 2.5
c = "Hello, world !"
c = "Hello,"
d = a
character Sy "Sylvie"
Sy.life = 5
e = Sy.life
a /= 1
b += 1
c += " world !"
d -= 2
Sy.life *= 2
e = Sy.life
32 changes: 31 additions & 1 deletion addons/Rakugo/lib/systems/Executer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,37 @@ func do_execute_script(parameters:Dictionary):
else:
value = float(value)

Rakugo.set_variable(result["lvar_name"], value)
var assignment = result["assignment"]

var lvar_name = result["lvar_name"]

if assignment != "=":
var lvalue = Rakugo.get_variable(lvar_name)

if lvalue == null:
parameters["error"] = "Executer::do_execute_script::SET_VARIABLE, Rakugo does not knew a variable called: " + lvar_name
parameters["stop"] = true
break

match(assignment):
"+=":
value = lvalue + value

"-=":
value = lvalue - value

"*=":
value = lvalue * value

"/=":
value = lvalue / value

_:
parameters["error"] = "Executer::do_execute_script::SET_VARIABLE, the assignment operator is not implemented :" + assignment
parameters["stop"] = true
break

Rakugo.set_variable(lvar_name, value)
_:
var foo = func():
Rakugo.sg_custom_regex.emit(line[0], result)
Expand Down
4 changes: 3 additions & 1 deletion addons/Rakugo/lib/systems/Parser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var Regex := {
NUMERIC = "-?[0-9]\\.?[0-9]*",
STRING = "\".+?\"",
VARIABLE = "((?<char_tag>{NAME})\\.)?(?<var_name>{NAME})",
ASSIGNMENT = "(?<assignment>=|\\+=|\\-=|\\*=|\\/=)"
# MULTILINE_STRING = "\"\"\"(?<string>.*)\"\"\"",
}

Expand All @@ -65,7 +66,7 @@ var parser_regex :={
# jump label
JUMP = "^jump (?<label>{NAME})( if (?<expression>.+))?$",
# for setting Rakugo variables
SET_VARIABLE = "^(?<lvar_name>{VARIABLE}) = ((?<text>{STRING})|(?<number>{NUMERIC})|(?<rvar_name>{VARIABLE}))$",
SET_VARIABLE = "^(?<lvar_name>{VARIABLE})\\s*{ASSIGNMENT}\\s*((?<text>{STRING})|(?<number>{NUMERIC})|(?<rvar_name>{VARIABLE}))$",
# $ some_gd_script_code
# IN_LINE_GDSCRIPT = "^\\$.*",
# gdscript:
Expand Down Expand Up @@ -267,6 +268,7 @@ func parse_script(lines:PackedStringArray) -> Dictionary:
"SET_VARIABLE":
var dic_result := {
"lvar_name":result.get_string("lvar_name"),
"assignment":result.get_string("assignment"),
"rvar_name":result.get_string("rvar_name"),
"number":result.get_string("number"),
"text":treat_string(result.get_string("text"))
Expand Down

0 comments on commit fed1430

Please sign in to comment.