-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Real set variable #240
Real set variable #240
Changes from 7 commits
3e80317
4e41eb6
7b60521
25f4a51
ed6f6c3
8ec3f0e
4eac92c
4112646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
a = 1 | ||
b = 2.5 | ||
a = 1 + 1 | ||
b = 5/2 | ||
c = "Hello, world !" | ||
d = a | ||
character Sy "Sylvie" | ||
Sy.life = 5 | ||
e = Sy.life | ||
e = Sy.life | ||
f = 2 | ||
f += 2 | ||
f *= 2 | ||
f /= 2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ var Regex := { | |
NUMERIC = "-?[0-9]\\.?[0-9]*", | ||
STRING = "\".*\"", | ||
VARIABLE = "((?<char_tag>{NAME})\\.)?(?<var_name>{NAME})", | ||
ASSIGNMENT = "(=|\\+=|\\-=|\\*=|\\/=|\\%=)", | ||
# MULTILINE_STRING = "\"\"\"(?<string>.*)\"\"\"", | ||
} | ||
|
||
|
@@ -65,13 +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}))$", | ||
# $ some_gd_script_code | ||
# IN_LINE_GDSCRIPT = "^\\$.*", | ||
# gdscript: | ||
# GDSCRIPT_BLOCK = "^gdscript:", | ||
# TRANSLATION = "\\[TR:(?<tr>.*?)]\\", | ||
# CONDITION = "(if|elif) (?<condition>.*)", | ||
SET_VARIABLE = "^(?<rvar_name>{VARIABLE})\\s*(?<operator>{ASSIGNMENT})\\s*(?<expression>.+)$", | ||
} | ||
|
||
var other_regex :={ | ||
|
@@ -107,7 +102,9 @@ func _init(): | |
|
||
for key in other_regex: | ||
add_regex(key, other_regex[key], other_cache, "Parser, _init, failed " + key) | ||
|
||
|
||
# prints("SET_VARIABLE", regex_cache["SET_VARIABLE"]. get_pattern()) | ||
|
||
add_regex("VARIABLE", Regex["VARIABLE"], other_cache, "Parser, _init, failed VARIABLE") | ||
|
||
func count_indent(s:String) -> int: | ||
|
@@ -124,19 +121,42 @@ func count_indent(s:String) -> int: | |
|
||
return ret | ||
|
||
func get_vars_in_expression(str_expression:String): | ||
var sub_results = other_cache["VARIABLE"].search_all(str_expression) | ||
var vars = [] | ||
|
||
# Expression does not like '.' | ||
var vars_expression = [] | ||
|
||
for sub_result in sub_results: | ||
var sub_result_str = sub_result.strings[0] | ||
|
||
if !vars.has(sub_result_str): | ||
vars.push_back(sub_result_str) | ||
|
||
var var_name_expr = sub_result.get_string("char_tag") | ||
|
||
if !var_name_expr.is_empty(): | ||
var_name_expr += "_" + sub_result.get_string("var_name") | ||
|
||
str_expression = str_expression.replace(sub_result_str, var_name_expr) | ||
else: | ||
var_name_expr = sub_result.get_string("var_name") | ||
|
||
if !vars_expression.has(var_name_expr): | ||
vars_expression.push_back(var_name_expr) | ||
|
||
return [vars_expression, vars] | ||
|
||
func parse_script(lines:PackedStringArray) -> Dictionary: | ||
if lines.is_empty(): | ||
push_error("Parser, parse_script : lines is empty !") | ||
return {} | ||
|
||
var parse_array:Array | ||
|
||
var labels:Dictionary | ||
|
||
var indent_count:int | ||
|
||
var menu_choices | ||
|
||
var current_menu_result | ||
|
||
state = State.Normal | ||
|
@@ -203,42 +223,33 @@ func parse_script(lines:PackedStringArray) -> Dictionary: | |
if str_expression.is_empty(): | ||
parse_array.push_back([key, result]) | ||
break | ||
|
||
var vars = get_vars_in_expression(str_expression) | ||
var expression = Expression.new() | ||
if expression.parse(str_expression, vars[0]) != OK: | ||
push_error("Parser: Error on line: " + str(i+1) + ", " + expression.get_error_text()) | ||
return {} | ||
|
||
var sub_results = other_cache["VARIABLE"].search_all(str_expression) | ||
|
||
var vars = [] | ||
|
||
# Expression does not like '.' | ||
var vars_expression = [] | ||
|
||
for sub_result in sub_results: | ||
var sub_result_str = sub_result.strings[0] | ||
|
||
if !vars.has(sub_result_str): | ||
vars.push_back(sub_result_str) | ||
|
||
var var_name_expr = sub_result.get_string("char_tag") | ||
|
||
if !var_name_expr.is_empty(): | ||
var_name_expr += "_" + sub_result.get_string("var_name") | ||
parse_array.push_back([key, result, expression, vars[1]]) | ||
|
||
str_expression = str_expression.replace(sub_result_str, var_name_expr) | ||
else: | ||
var_name_expr = sub_result.get_string("var_name") | ||
|
||
if !vars_expression.has(var_name_expr): | ||
vars_expression.push_back(var_name_expr) | ||
"SET_VARIABLE": | ||
var str_expression:String = result.get_string("expression") | ||
|
||
if str_expression.is_empty(): | ||
parse_array.push_back([key, result]) | ||
break | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If your str_expression is empty why you do not send an error ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I last touch this code over a month ago, so maybe I was to change into something and forgot. |
||
|
||
var vars = get_vars_in_expression(str_expression) | ||
var expression = Expression.new() | ||
|
||
if expression.parse(str_expression, vars_expression) != OK: | ||
if expression.parse(str_expression, vars[0]) != OK: | ||
push_error("Parser: Error on line: " + str(i+1) + ", " + expression.get_error_text()) | ||
return {} | ||
|
||
parse_array.push_back([key, result, expression, vars]) | ||
parse_array.push_back([key, result, expression, vars[1]]) | ||
|
||
_: | ||
parse_array.push_back([key, result]) | ||
|
||
break | ||
|
||
if (not have_find_key): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rakugo.get_variable return null if variable is not found. So you do not need to use has_variable before get_variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I made this if this way as Rakugo would crash when
get_variable()
returns null - we program it this way,push_error()
stops program no matter what is next.Rakugo-Dialogue-System/addons/Rakugo/Rakugo.gd
Lines 74 to 85 in d11e1fe