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

[LANGUAGE] improved error productions for at #4663

Merged
merged 31 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2bd64b4
made changes in isValid , is_program_valid in hedy.py | exceptions.py…
akseron Oct 24, 2023
471b594
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 24, 2023
9e02a95
comments added
akseron Oct 29, 2023
1c5859e
resolve conflicts
akseron Oct 29, 2023
c2e95da
Merge branch 'error-productions' of https://github.com/hedyorg/hedy i…
akseron Oct 29, 2023
a09c191
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2023
85cb6b9
Update hedy.py
akseron Oct 30, 2023
8c98530
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 30, 2023
44373dc
mainly debugging print statements, misspelled at works but implementa…
akseron Oct 31, 2023
9db8e49
Merge branch 'error-productions' of https://github.com/hedyorg/hedy i…
akseron Oct 31, 2023
8f1e460
Update level3-Additions.lark
akseron Oct 31, 2023
0c1f3cb
Update level3-Additions.lark
akseron Oct 31, 2023
cad1c3a
removed print statements
akseron Oct 31, 2023
2bdb0d0
debugging var_access _at var_access
akseron Nov 6, 2023
9fdf152
improved error message for invalid index command
akseron Nov 6, 2023
3e344b8
unnecessary as handled in previous commit
akseron Nov 6, 2023
909e74a
added simple error messages for dutch and english
akseron Nov 7, 2023
070bdaa
added testing + pybabel compiled
akseron Nov 20, 2023
3c8212f
Merge branch 'main' into error-productions
Felienne Nov 21, 2023
e0fb5ba
reextract babel strings
Felienne Nov 21, 2023
b2f0175
Update exceptions.py
akseron Nov 21, 2023
03a3ab8
Update tests/test_level/test_level_04.py
Felienne Nov 21, 2023
341fe1b
Update test_level_04.py
akseron Nov 21, 2023
aa3f4d9
Update tests/test_level/test_level_04.py
Felienne Nov 21, 2023
fbbb17b
Merge branch 'main' into error-productions
Felienne Nov 21, 2023
ad02016
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2023
8910590
removed error messages
akseron Nov 21, 2023
4e30aef
break the code to make the test pass :)
Felienne Nov 21, 2023
82c8108
reverted to original spacing (unimportant)
akseron Nov 21, 2023
184aec6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2023
48ecb6f
remove old todo comment
Felienne Nov 21, 2023
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
1 change: 1 addition & 0 deletions content/error-messages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gettext('float')
gettext('list')
gettext('input')
gettext('Invalid At Command')
gettext('Misspelled At Command')
# Exceptions groups used in the Live Statistics Module. If you add a new Exception Group here,
# you should use the same name when you assign this exception group to a exception in that module
# in the exception_types dictionary
Expand Down
8 changes: 8 additions & 0 deletions exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def __init__(self, level, line_number, unquotedtext=None):
line_number=line_number)


class MisspelledAtCommand(HedyException):
def __init__(self, command, arg1, line_number):
super().__init__('Misspelled At Command',
command=command,
invalid_argument=arg1,
line_number=line_number)


class UnquotedAssignTextException(HedyException):
def __init__(self, text, line_number):
super().__init__('Unquoted Assignment', text=text, line_number=line_number)
Expand Down
2 changes: 1 addition & 1 deletion grammars/level3-Additions.lark
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
command:+= assign_list | add | remove > error_invalid
command:+= assign_list | add | remove > error_invalid
_print_argument: (_SPACE | (list_access textwithoutspaces?) | textwithoutspaces)*
ask: var _IS _ASK ((_SPACE | text_ask)*)?

Expand Down
7 changes: 5 additions & 2 deletions grammars/level4-Additions.lark
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// redefining it entirely since it has many order-depending rules (e.g ask_no_quotes should be after ask and before assign)
command: clear | print | ask | turtle | assign_list | add | remove | sleep | error_ask_no_quotes| assign | error_invalid_space | error_print_no_quotes | error_text_no_print |error_invalid | empty_line
command: clear | print | ask | turtle | assign_list | add | remove | sleep | error_list_access | error_ask_no_quotes| assign | error_invalid_space | error_print_no_quotes | error_text_no_print |error_invalid | empty_line

print: _PRINT (_print_argument)? -> print
error_print_no_quotes: _PRINT text -> error_print_nq
Expand All @@ -8,15 +8,18 @@ error_print_no_quotes: _PRINT text -> error_print_nq
ask: var _IS _ASK (_print_argument)?
error_ask_no_quotes: var _IS _ASK text -> error_print_nq

error_list_access: var_access _SPACE textwithoutspaces _SPACE random

list_access: var_access _AT (INT | random | var_access)
_print_argument: (_SPACE | list_access | quoted_text | var_access_print)*
_print_argument: (_SPACE | list_access | error_list_access | quoted_text | var_access_print)*

error_text_no_print: quoted_text

// literal strings must be single-quoted in ask and print commands
// 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 \


19 changes: 13 additions & 6 deletions hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,11 @@ def error_print_nq(self, meta, args):
return False, InvalidInfo("print without quotes", arguments=[
text], line=meta.line, column=meta.column), meta

def error_invalid(self, meta, args):
# TODO: this will not work for misspelling 'at', needs to be improved!
def error_list_access(self, meta, args):
error = InvalidInfo('misspelled "at" command', arguments=[str(args[1][1])], line=meta.line)
return False, error, meta

def error_invalid(self, meta, args):
error = InvalidInfo('invalid command', command=args[0][1], arguments=[
[a[1] for a in args[1:]]], line=meta.line, column=meta.column)
return False, error, meta
Expand Down Expand Up @@ -1353,16 +1355,19 @@ def is_var_candidate(arg) -> bool:
# all good? return for further processing
return args
else:
# TODO: check whether this is really never raised??
# return first name with issue
first_unquoted_var = unquoted_args[0]
raise exceptions.UndefinedVarException(name=first_unquoted_var, line_number=var_access_linenumber)
for index, a in enumerate(unquoted_args):
current_arg = unquoted_in_lookup[index]
if current_arg is None:
first_unquoted_var = a
raise exceptions.UndefinedVarException(name=first_unquoted_var, line_number=var_access_linenumber)

# static methods

@staticmethod
def check_if_error_skipped(tree):
return hasattr(IsValid, tree.data)

# static methods
@staticmethod
def is_quoted(s):
opening_quotes = ['‘', "'", '"', "“", "«"]
Expand Down Expand Up @@ -3281,6 +3286,8 @@ def is_program_valid(program_root, input_string, level, lang):
unquotedtext = invalid_info.arguments[0]
raise exceptions.UnquotedTextException(
level=level, unquotedtext=unquotedtext, line_number=invalid_info.line)
elif invalid_info.error_type == 'misspelled "at" command':
raise exceptions.MisspelledAtCommand(command='at', arg1=invalid_info.arguments[0], line_number=line)
elif invalid_info.error_type == 'unsupported number':
raise exceptions.UnsupportedFloatException(value=''.join(invalid_info.arguments))
elif invalid_info.error_type == 'lonely text':
Expand Down
33 changes: 26 additions & 7 deletions messages.pot
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Translations template for PROJECT.
# Copyright (C) 2023 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-11-21 09:17+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.11.0\n"

msgid "Access Before Assign"
msgstr ""

Expand Down Expand Up @@ -46,6 +65,9 @@ msgstr ""
msgid "Missing Inner Command"
msgstr ""

msgid "Misspelled At Command"
msgstr ""

msgid "No Indentation"
msgstr ""

Expand Down Expand Up @@ -421,9 +443,6 @@ msgstr ""
msgid "disabled"
msgstr ""

msgid "disabled_button_locked"
msgstr ""

msgid "disabled_button_quiz"
msgstr ""

Expand All @@ -445,9 +464,6 @@ msgstr ""
msgid "duplicate"
msgstr ""

msgid "duplicate_tag"
msgstr ""

msgid "echo_and_ask_mismatch_exception"
msgstr ""

Expand Down Expand Up @@ -1267,6 +1283,9 @@ msgstr ""
msgid "retrieve_class_error"
msgstr ""

msgid "retrieve_tag_error"
msgstr ""

msgid "role"
msgstr ""

Expand Down Expand Up @@ -1441,7 +1460,7 @@ msgstr ""
msgid "surname"
msgstr ""

msgid "tag_deleted"
msgid "tag_in_adventure"
msgstr ""

msgid "tag_input_placeholder"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_level/test_level_03.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def test_list_access_misspelled_at_gives_error(self):
print dieren ad random""")

self.multi_level_tester(
max_level=11,
max_level=3,
code=code,
extra_check_function=lambda c: c.exception.arguments['line_number'] == 2,
exception=hedy.exceptions.InvalidArgumentTypeException
Expand Down
13 changes: 13 additions & 0 deletions tests/test_level/test_level_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,19 @@ def test_print_list_access_index_var(self):
extra_check_function=check_in_list
)

def test_list_access_misspelled_at_gives_error(self):
code = textwrap.dedent("""\
dieren is Hond, Kat, Kangoeroe, Kaketoe
print dieren ad random""")

self.multi_level_tester(
max_level=5,
skip_faulty=False,
code=code,
extra_check_function=lambda c: c.exception.arguments['line_number'] == 2,
exception=hedy.exceptions.MisspelledAtCommand
)

def test_ask_list_access_index(self):
code = textwrap.dedent("""\
colors is orange, blue, green
Expand Down
48 changes: 39 additions & 9 deletions translations/ar/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# Arabic translations for PROJECT.
# Copyright (C) 2023 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-11-21 09:17+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ar\n"
"Language-Team: ar <[email protected]>\n"
"Plural-Forms: nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : "
"n%100>=3 && n%100<=10 ? 3 : n%100>=0 && n%100<=2 ? 4 : 5);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.11.0\n"

#, fuzzy
msgid "Access Before Assign"
msgstr ""
Expand Down Expand Up @@ -85,6 +107,9 @@ msgstr ""
"يبدو أنك نسيت استخدام أمر برمجي مع الجملة {command} التي استعملتها في "
"السطر رقم {line_number}."

msgid "Misspelled At Command"
msgstr ""

msgid "No Indentation"
msgstr ""
"لقد استخدمت عدداً غير كافي من الفراغات كإزاحة في السطر رقم {line_number}."
Expand Down Expand Up @@ -546,10 +571,6 @@ msgstr "Disable"
msgid "disabled"
msgstr "Disabled"

#, fuzzy
msgid "disabled_button_locked"
msgstr "Your teacher hasn't unlocked this level yet"

#, fuzzy
msgid "disabled_button_quiz"
msgstr "Your quiz score is below the threshold, try again!"
Expand Down Expand Up @@ -577,9 +598,6 @@ msgstr "Do you want to download the login credentials after the accounts creatio
msgid "duplicate"
msgstr "Duplicate"

msgid "duplicate_tag"
msgstr "لديك بالفعل علامة بنفس هذا الإسم."

#, fuzzy
msgid "echo_and_ask_mismatch_exception"
msgstr "Echo and ask mismatch"
Expand Down Expand Up @@ -1557,6 +1575,9 @@ msgstr "لا يسمح لك بعرض هذه المغامرة!"
msgid "retrieve_class_error"
msgstr "يمكن للمعلمين فقط استرجاع الصفوف"

msgid "retrieve_tag_error"
msgstr ""

msgid "role"
msgstr "منصب"

Expand Down Expand Up @@ -1747,8 +1768,8 @@ msgstr "اشترك في النشرة الإخبارية"
msgid "surname"
msgstr "الاسم الأول"

msgid "tag_deleted"
msgstr "لقد تم حذف العلامة"
msgid "tag_in_adventure"
msgstr ""

msgid "tag_input_placeholder"
msgstr "اكتب علامة جديدة"
Expand Down Expand Up @@ -2181,3 +2202,12 @@ msgstr "Your program"
#~ msgid "title_class statistics"
#~ msgstr "احصائياتي"

#~ msgid "disabled_button_locked"
#~ msgstr "Your teacher hasn't unlocked this level yet"

#~ msgid "duplicate_tag"
#~ msgstr "لديك بالفعل علامة بنفس هذا الإسم."

#~ msgid "tag_deleted"
#~ msgstr "لقد تم حذف العلامة"

44 changes: 32 additions & 12 deletions translations/bg/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@

msgid ""
msgstr "Project-Id-Version: PACKAGE VERSION\nReport-Msgid-Bugs-To: \nPOT-Creation-Date: 2023-11-02 08:48+0200\nPO-Revision-Date: 2023-11-14 20:05+0000\nLast-Translator: Prefill add-on <[email protected]>\nLanguage-Team: LANGUAGE <[email protected]>\nLanguage: bg\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\nPlural-Forms: nplurals=2; plural=n != 1;\nX-Generator: Weblate 5.2-dev\n"
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-11-21 09:17+0100\n"
"PO-Revision-Date: 2023-11-14 20:05+0000\n"
"Last-Translator: Prefill add-on <[email protected]>\n"
"Language: bg\n"
"Language-Team: bg <[email protected]>\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.11.0\n"

#, fuzzy
msgid "Access Before Assign"
Expand Down Expand Up @@ -94,6 +107,9 @@ msgstr ""
"It looks like you forgot to use a command with the {command} statement "
"you used on line {line_number}."

msgid "Misspelled At Command"
msgstr ""

#, fuzzy
msgid "No Indentation"
msgstr ""
Expand Down Expand Up @@ -624,10 +640,6 @@ msgstr "Disable"
msgid "disabled"
msgstr "Disabled"

#, fuzzy
msgid "disabled_button_locked"
msgstr "Your teacher hasn't unlocked this level yet"

#, fuzzy
msgid "disabled_button_quiz"
msgstr "Your quiz score is below the threshold, try again!"
Expand Down Expand Up @@ -655,10 +667,6 @@ msgstr "Do you want to download the login credentials after the accounts creatio
msgid "duplicate"
msgstr "Duplicate"

#, fuzzy
msgid "duplicate_tag"
msgstr "You already have a tag with this name."

#, fuzzy
msgid "echo_and_ask_mismatch_exception"
msgstr "Echo and ask mismatch"
Expand Down Expand Up @@ -1765,6 +1773,9 @@ msgstr "You're not allowed to view this adventure!"
msgid "retrieve_class_error"
msgstr "Only teachers can retrieve classes"

msgid "retrieve_tag_error"
msgstr ""

#, fuzzy
msgid "role"
msgstr "Role"
Expand Down Expand Up @@ -1992,9 +2003,8 @@ msgstr "Абонирай се за нашия журнал"
msgid "surname"
msgstr "Потребителско име"

#, fuzzy
msgid "tag_deleted"
msgstr "This tag was successfully deleted."
msgid "tag_in_adventure"
msgstr ""

#, fuzzy
msgid "tag_input_placeholder"
Expand Down Expand Up @@ -2447,3 +2457,13 @@ msgstr "Your program"

#~ msgid "title_class statistics"
#~ msgstr "My statistics"

#~ msgid "disabled_button_locked"
#~ msgstr "Your teacher hasn't unlocked this level yet"

#~ msgid "duplicate_tag"
#~ msgstr "You already have a tag with this name."

#~ msgid "tag_deleted"
#~ msgstr "This tag was successfully deleted."

Loading
Loading