Skip to content
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

🪲 Add support for more quotes #5791

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions grammars/keywords-zun.lark
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related to the quotes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file caused translation tests to fail (when the cache is switched off locally). I will investigate why there is no failure on GitHub, but I suspect it is caching.

This file was deleted.

5 changes: 1 addition & 4 deletions grammars/level4-Additions.lark
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ list_access: var_access _AT (INT | random | var_access)
// anything can be parsed except for a newline, a space and a list separator
textwithoutspaces: /([^\n،,,、 ]+)/ -> text




quoted_text: (/'((?:[^\\']|\\.)*)'/ | /"((?:[^\\"]|\\.)*)"/ | /‘((?:[^\\‘]|\\.)*)’/ | /“((?:[^\\”]|\\.)*)”/ | /«((?:[^\\»]|\\.)*)»/ | /„((?:[^\\“]|\\.)*)“/ ) -> text //text can be between single or double quotes, but quotes may be escaped with \
quoted_text: (/'((?:[^\\']|\\.)*)'/ | /"((?:[^\\"]|\\.)*)"/ | /‘((?:[^\\‘]|\\.)*)’/ | /“((?:[^\\”]|\\.)*)”/ | /„((?:[^\\“”]|\\.)*)[“”]/ | /”((?:[^\\”]|\\.)*)”/ | /«((?:[^\\»]|\\.)*)»/ | /《((?:[^\\》]|\\.)*)》/ | /「((?:[^\\」]|\\.)*)」/ ) -> text //text can be between single or double quotes, but quotes may be escaped with \


18 changes: 11 additions & 7 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,12 +1429,16 @@ def process_characters_needing_escape(value):


supported_quotes = {
"'": "'", # single straight quotation marks
'"': '"', # double straight quotation marks
'‘': '’', # single curved quotation marks
"“": "”", # double curved quotation marks or English quotes
"„": "“", # inward double curved quotation marks or German quotes
"«": "»", # guillemets or double angular marks or French quotes
"'": ["'"], # single straight quotation marks
'"': ['"'], # double straight quotation marks
'‘': ['’'], # single curved quotation marks
"“": ["”"], # double curved quotation marks or English quotes
"„": ["“", # inward double curved quotation marks or German quotes
"”"], # rightward double curved quotation marks or Polish quotes
'”': ['”'], # rightward double curved quotation marks or Swedish/Finish quotes
"«": ["»"], # guillemets or double angular marks or French quotes
"《": ["》"], # Korean quotes
"「": ["」"], # Japanese quotes
}


Expand All @@ -1452,7 +1456,7 @@ def find_unquoted_segments(s):
used_quote = c
result += segment
segment = c
elif used_quote and c == supported_quotes[used_quote]:
elif used_quote and c in supported_quotes[used_quote]:
# if this is a valid closing quote, then empty the buffer as it holds a correctly quoted segment
used_quote = None
segment = ''
Expand Down
1 change: 0 additions & 1 deletion hedy_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
'iba': 'en',
'peo': 'fa',
'enm': 'en',
'zun': 'en'
}

# For the non-existing language manually overwrite the display language to make sure it is displayed correctly
Expand Down
4 changes: 2 additions & 2 deletions hedy_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warnings
from os import path
from functools import cache
from hedy_translation import keywords_to_dict
import hedy_translation

"""
Because of the gradual nature of Hedy, the grammar of every level is just slightly different than the grammar of the
Expand Down Expand Up @@ -271,7 +271,7 @@ def expand_keyword_not_followed_by_space(**kwargs):

def get_translated_keyword(keyword, lang):
def get_keyword_value_from_lang(keyword_, lang_):
keywords = keywords_to_dict(lang_)
keywords = hedy_translation.keywords_to_dict(lang_)
if keyword_ in keywords:
return [k for k in keywords[keyword_] if k]
else:
Expand Down
36 changes: 36 additions & 0 deletions tests/test_level/test_level_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ def test_print_french_quoted_text(self):
max_level=11,
expected=expected)

def test_print_polish_quoted_text(self):
code = "print „bonjour tous le monde!”"
expected = "print(f'bonjour tous le monde!')"

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

def test_print_swedish_quoted_text(self):
code = "print ”bonjour tous le monde!”"
expected = "print(f'bonjour tous le monde!')"

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

def test_print_korean_quoted_text(self):
code = "print 《bonjour tous le monde!》"
expected = "print(f'bonjour tous le monde!')"

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

def test_print_japanese_quoted_text(self):
code = "print 「bonjour tous le monde!」"
expected = "print(f'bonjour tous le monde!')"

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

def test_print_chinese_quoted_text(self):
code = "print “逃离鬼屋!”"
expected = "print(f'逃离鬼屋!')"
Expand Down
Loading