Skip to content

Commit

Permalink
Merge pull request rakugoteam#261 from theludovyc/fix#257_use_quotes_…
Browse files Browse the repository at this point in the history
…in_strings

fix rakugoteam#257 use quotes in strings
  • Loading branch information
Jeremi360 authored Oct 21, 2023
2 parents 8b926f4 + ce165cf commit 5181a65
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Test/TestExecuter/TestSay/TestSay.rk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ character sy "Sylvie"
sy "Hello !"
"My name is <sy.name>"
years = 18
"I am <years>"
"I am <years>"
25 changes: 25 additions & 0 deletions Test/TestParser/TestAsk/TestAsk.gd
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,28 @@ func test_ask_all(params=use_parameters(test_ask_all_params)):
assert_eq(result["question"], "Hello ?")

assert_eq(result["default_answer"], "Bob")

func test_ask_quotes():
var rk_script = [
"answer=?gd \"Hello: \"quote\"?\" \"Bob: \"quote\"\""
]

var parsed_script = parser.parse_script(rk_script)

assert_false(parsed_script.is_empty())

var parsed_array = parsed_script["parse_array"]

assert_false(parsed_array.is_empty())

assert_true(parsed_array[0][0] == "ASK")

var result = parsed_array[0][1]

assert_eq(result["variable"], "answer")

assert_eq(result["character_tag"], "gd")

assert_eq(result["question"], "Hello: \"quote\"?")

assert_eq(result["default_answer"], "Bob: \"quote\"")
37 changes: 37 additions & 0 deletions Test/TestParser/TestSay/TestSay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,43 @@ func test_say_escape_characters():

assert_eq(result["text"], "first\nsecond\n\nthird")

assert_true(parsed_array[1][0] == "SAY")

result = parsed_array[1][1]

assert_eq(result["text"], "\ttabulation\t\ttabulations")

func test_say_quote():
var rk_script = [
"\"hello: \"quote\"\"",
"\"\"quote\" hello \"quote\"\"",
"\"hel\"quote\"lo\""
]

var parsed_script = parser.parse_script(rk_script)

assert_false(parsed_script.is_empty())

var parsed_array = parsed_script["parse_array"]

assert_false(parsed_array.is_empty())

assert_true(parsed_script.get("labels", [""]).is_empty())

assert_true(parsed_array[0][0] == "SAY")

var result = parsed_array[0][1]

assert_eq(result["text"], "hello: \"quote\"")

assert_true(parsed_array[1][0] == "SAY")

result = parsed_array[1][1]

assert_eq(result["text"], "\"quote\" hello \"quote\"")

assert_true(parsed_array[2][0] == "SAY")

result = parsed_array[2][1]

assert_eq(result["text"], "hel\"quote\"lo")
2 changes: 1 addition & 1 deletion addons/Rakugo/lib/systems/Parser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Tokens := {
var Regex := {
NAME = "[a-zA-Z][a-zA-Z_0-9]*",
NUMERIC = "-?[0-9]\\.?[0-9]*",
STRING = "\"[^\"]*\"",
STRING = "\".+?\"",
VARIABLE = "((?<char_tag>{NAME})\\.)?(?<var_name>{NAME})",
# MULTILINE_STRING = "\"\"\"(?<string>.*)\"\"\"",
}
Expand Down

0 comments on commit 5181a65

Please sign in to comment.