Skip to content

Commit

Permalink
[LANGUAGE] Allow for ela geminada (·) in var names (hedyorg#4187)
Browse files Browse the repository at this point in the history
Fixes hedyorg#4190

This is a redo of hedyorg#4172 in which I accidentally pushed more changes.

Note that there we must revert the content fix mentioned in hedyorg#4190 because there so work now.
  • Loading branch information
Felienne authored Mar 30, 2023
1 parent f55fe85 commit c1f2005
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def print(self, meta, args):
else:
# this regex splits words from non-letter characters, such that name! becomes [name, !]
res = regex.findall(
r"[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]+|[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]+", a)
r"[·\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}]+|[^·\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]+", a)
args_new.append(''.join([self.process_variable_for_fstring(x, meta.line) for x in res]))
exception = self.make_catch_exception(args)
argument_string = ' '.join(args_new)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_level/test_level_02.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,19 @@ def test_assign(self):

self.multi_level_tester(code=code, expected=expected, max_level=11)

def test_assign_catalan_var_name(self):
code = textwrap.dedent("""\
print És hora una nit de Netflix
pel·lícula is Sonic the Hedgehog 2
print Veurem una pel·lícula""")

expected = textwrap.dedent("""\
print(f'És hora una nit de Netflix')
pel·lícula = 'Sonic the Hedgehog 2'
print(f'Veurem una {pel·lícula}')""")

self.multi_level_tester(code=code, expected=expected, max_level=3)

def test_assign_integer(self):
code = "naam is 14"
expected = "naam = '14'"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_level/test_level_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ def test_ask_without_quotes_gives_error_from_grammar(self):
exception=hedy.exceptions.UnquotedTextException
)

def test_assign_catalan_var_name(self):
code = textwrap.dedent("""\
pel·lícula is Sonic the Hedgehog 2
print 'Veurem una ' pel·lícula""")

expected = textwrap.dedent("""\
pel·lícula = 'Sonic the Hedgehog 2'
print(f'Veurem una {pel·lícula}')""")

self.multi_level_tester(code=code, expected=expected, max_level=11)

def test_place_holder_no_space(self):
# same as print for level 4
code = "print _Escape from the haunted house!_"
Expand Down

0 comments on commit c1f2005

Please sign in to comment.