erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Fix invalid expect block and support for multi-line errors #253

Closed GreasySlug closed 7 months ago

GreasySlug commented 1 year ago

Fixes #58 and #248.

Each line of the REPL is now evaluated by the Parser::eval() (Parser and Lex are not modified)

Changes proposed in this PR:

@mtshiba

GreasySlug commented 1 year ago

Currently it is implemented only in dummy.rs. Is it necessary to implement run() other than dummy.rs?

mtshiba commented 1 year ago

A method should be added to Runnable trait as a required method to determine if the next line should be followed. The name should be something like .expect_nextline(src). And each struct should implement it. So no need to implement run.

GreasySlug commented 1 year ago

I fixed conflict.

GreasySlug commented 1 year ago

multi-line-error

However, not evaluated until only a newline is entered after the block is expected Invalid syntax can be entered during this time

e.g.

>>> while True, do!: 
...   ->
...     =>
...       ->
... 

Furthermore, another approach is needed to evaluate during the block Each row is now evaluated by Parser Changed to use instance.eval() to initialize lines and display errors when Parser results in an error

>>> while True, do: 
...    ->
Error[#0000]: File <stdin>, line 2, 

2 |    ->
  :    --

invalid syntax

Error[#0390]: File <stdin>, line 2,

2 |    ->
  :      -

failed to parse a block
GreasySlug commented 1 year ago

I fixed #281 then I found some bugs. so I need more time to test and fix them

mtshiba commented 7 months ago

When REPL detects an error, it refers to the previous source information.

スクリーンショット 2024-02-28 20 07 50
GreasySlug commented 7 months ago

I addressed the issue occurring during single-line errors.

Additionally, I added error handling for cases where newline are expected, such as with do!:, do:, to ensure evaluation in the REPL.

error

mtshiba commented 7 months ago

REPL references previous source information when dealing with multiple lines of code.

スクリーンショット 2024-02-29 13 30 07 スクリーンショット 2024-02-29 13 31 46
GreasySlug commented 7 months ago
mtshiba commented 7 months ago

Thank you!