radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
23 stars 2 forks source link

fix: the most annoying bug of all time #115

Closed angelcaru closed 5 months ago

angelcaru commented 5 months ago

Closes #112

Almas-Ali commented 5 months ago

What do you think about this issue here?

$ python3.11 radon.py -s stdlib/Argparser.rn 

Traceback (most recent call last):
  File <stdin>, line 1, in <program>
  File <stdin>, line 1, in require
Runtime Error: Failed to finish executing script "***/radon/stdlib/Argparser.rn"
Invalid Syntax: Expected '}'
File ***/radon/stdlib/Argparser.rn, line 10

        this.options[option] = {"description": description, "is_flag": is_flag}
                    ^
require("stdlib/Argparser.rn")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Almas-Ali commented 5 months ago

Still exist.

>>> some 234

Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
some 234
     ^^^
Almas-Ali commented 5 months ago

And finally, we also need this huge list to be meaningful.

>>> to
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
to
^^
>>> step
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
step
^^^^
>>> [
Invalid Syntax: Expected ']', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '(', '[', '{' or 'not'
File <stdin>, line 1
[
 ^
>>> ]
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
]
^
angelcaru commented 5 months ago

Still exist.

>>> some 234

Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
some 234
     ^^^

Yeah, but the error message actually makes sense in this context

angelcaru commented 5 months ago

And finally, we also need this huge list to be meaningful.

>>> to
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
to
^^
>>> step
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
step
^^^^
>>> [
Invalid Syntax: Expected ']', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '(', '[', '{' or 'not'
File <stdin>, line 1
[
 ^
>>> ]
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
]
^

But it is meaningful! It's all of the possible tokens that start an expression. Admittedly, it could probably be rephrased as "expected expression" (that way it also never gets out of date). Will look into doing that

Almas-Ali commented 5 months ago

And finally, we also need this huge list to be meaningful.

>>> to
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
to
^^
>>> step
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
step
^^^^
>>> [
Invalid Syntax: Expected ']', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '(', '[', '{' or 'not'
File <stdin>, line 1
[
 ^
>>> ]
Invalid Syntax: Expected 'return', 'continue', 'break', 'if', 'for', 'while', 'fun', int, float, identifier, '+', '-', '%', '(', '[', '{', or 'not'
File <stdin>, line 1
]
^

But it is meaningful! It's all of the possible tokens that start an expression. Admittedly, it could probably be rephrased as "expected expression" (that way it also never gets out of date). Will look into doing that

This looks total mess. As a user, I would expect 1 or 2 as suggestion. In some cases noting. Even Python doesn't shows like that. What is your opinion?

angelcaru commented 5 months ago

What is your opinion?

I'm currently in the process of rewriting all of those error messages to something like "expected expression"

Almas-Ali commented 5 months ago

There are more assert's exist.

angelcaru commented 5 months ago

But those I believe are actually unreachable. If you can reproduce them, I'll remove them

Almas-Ali commented 5 months ago

But those I believe are actually unreachable. If you can reproduce them, I'll remove them

Well lets see! 😃

angelcaru commented 5 months ago

I mean they're literally checking for a keyword at the start of a function that is only called when that keyword is found

Almas-Ali commented 5 months ago

Found a new one!

>>> 298345=
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
298345=
      ^
>>> dsjhfg=
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
dsjhfg=
      ^
>>> p=class
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
p=class
 ^
>>> some while
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
some while
     ^^^^^
Almas-Ali commented 5 months ago

Found a new one!

>>> 298345=
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
298345=
      ^
>>> dsjhfg=
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
dsjhfg=
      ^
>>> some while
Invalid Syntax: Token cannot appear after previous tokens
File <stdin>, line 1
some while
     ^^^^^

Still these exist.

angelcaru commented 5 months ago

Yeah but those are actually appropiate for the situation

Almas-Ali commented 5 months ago

I took some example from Python.

>>> 234545=
  File "<stdin>", line 1
    234545=
    ^^^^^^
SyntaxError: cannot assign to literal
>>> some while
  File "<stdin>", line 1
    some while
         ^^^^^
SyntaxError: invalid syntax
Almas-Ali commented 5 months ago

It looks fine now!

angelcaru commented 5 months ago
>>> some while
  File "<stdin>", line 1
    some while
         ^^^^^
SyntaxError: invalid syntax

I'm pretty sure "Expected EOF" is more descriptive than "invalid syntax"

Almas-Ali commented 5 months ago

New complain in static

>>> static
Invalid Syntax: Expected 'fun'
File <stdin>, line 1
static
      ^
>>> static jdfg =2
2
Almas-Ali commented 5 months ago
>>> if {
... }
Invalid Syntax: Expected '{'
File <stdin>, line 2

}
 ^

>>> for i=3 to {
... }
Invalid Syntax: Expected '{'
File <stdin>, line 2

}
 ^
angelcaru commented 5 months ago
>>> if {
... }
Invalid Syntax: Expected '{'
File <stdin>, line 2

}
 ^

>>> for i=3 to {
... }
Invalid Syntax: Expected '{'
File <stdin>, line 2

}
 ^

That's actually "reasonable" (however funny it may be). It thinks you're using a HashMap as the if condition (or loop end point), so it parses that part correctly and fails when you don't provide a { for the body

Almas-Ali commented 5 months ago

I don't think there will be any major error related to "errors/exception" will be exist after this PR.

angelcaru commented 5 months ago

At least not syntax errors

Almas-Ali commented 5 months ago

I hope so.