diff --git a/grammars/keywords-zun.lark b/grammars/keywords-zun.lark deleted file mode 100644 index 2f844c60471..00000000000 --- a/grammars/keywords-zun.lark +++ /dev/null @@ -1,54 +0,0 @@ -_DEFINE: ("define" | "define") _SPACE? -_CALL: ("call" | "call") _SPACE? -_WITH: ("with" | "with") _SPACE? -_DEF: ("def" | "def") _SPACE? -_RETURN: ("return" | "return") _SPACE? -_PRINT: ("print" | "print") _SPACE? -_PLAY: ("play" | "play") _SPACE -_ASK: ("ask" | "ask") -_ECHO: ("echo" | "echo") _SPACE? -_FORWARD: ("forward" | "forward") _SPACE? -_TURN: ("turn" | "turn") _SPACE? -left: ("left" | "left") _SPACE? -right: ("right" | "right") _SPACE? -black: ("black" | "black") _SPACE? -blue: ("blue" | "blue") _SPACE? -brown: ("brown" | "brown") _SPACE? -gray: ("gray" | "gray") _SPACE? -green: ("green" | "green") _SPACE? -orange: ("orange" | "orange") _SPACE? -pink: ("pink" | "pink") _SPACE? -purple: ("purple" | "purple") _SPACE? -red: ("red" | "red") _SPACE? -white: ("white" | "white") _SPACE? -yellow: ("yellow" | "yellow") _SPACE? -_IS: _SPACE ("is" | "is") _SPACE -_STANDALONE_IS: ("is" | "is") -_SLEEP: ("sleep" | "sleep") _SPACE? -_ADD_LIST: ("add" | "add") _SPACE -_TO_LIST: _SPACE? ("to" | "to") _SPACE -_REMOVE: ("remove" | "remove") _SPACE -_FROM: _SPACE? ("from" | "from") _SPACE -_AT: _SPACE ("at" | "at") _SPACE -random: ("random" | "random") _SPACE? -_IN: _SPACE ("in" | "in") _SPACE -_NOT_IN: _SPACE ("not in" | "not in") _SPACE -_IF: ("if" | "if") _SPACE -_ELSE: "else" | "else" -_AND: _SPACE? ("and" | "and") _SPACE -_REPEAT: ("repeat" | "repeat") _SPACE -_TIMES: _SPACE ("times" | "times") -_FOR: ("for" | "for") _SPACE -_RANGE: ("range" | "range") _SPACE? -_TO: _SPACE ("to" | "to") _SPACE -_STEP: "step" | "step" -_ELIF: _SPACE? ("elif" | "elif") _SPACE -_INPUT: ("input" | "input") -_OR: _SPACE? ("or" | "or") _SPACE -_WHILE: ("while" | "while") _SPACE -_LENGTH: "length" | "length" -_COLOR : ("color" | "color") _SPACE? -_PRESSED: ("pressed" | "pressed") _SPACE? -clear: ("clear" | "clear") _SPACE? -TRUE: ("true" | "True" | "true" | "True") _SPACE? -FALSE: ("false" | "False" | "false" | "False") _SPACE? diff --git a/grammars/level4-Additions.lark b/grammars/level4-Additions.lark index d115554f41b..a716ff75a82 100644 --- a/grammars/level4-Additions.lark +++ b/grammars/level4-Additions.lark @@ -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 \ diff --git a/hedy.py b/hedy.py index b2f602d72d4..ecc01781122 100644 --- a/hedy.py +++ b/hedy.py @@ -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 } @@ -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 = '' diff --git a/hedy_grammar.py b/hedy_grammar.py index e7012e7295e..2d38018f420 100644 --- a/hedy_grammar.py +++ b/hedy_grammar.py @@ -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 @@ -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: diff --git a/tests/test_level/test_level_04.py b/tests/test_level/test_level_04.py index 788ca00fc68..a63c61fb912 100644 --- a/tests/test_level/test_level_04.py +++ b/tests/test_level/test_level_04.py @@ -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'逃离鬼屋!')"