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

Classify parser errors and use them #320

Merged
merged 37 commits into from
Jun 9, 2023

Conversation

GreasySlug
Copy link
Member

@GreasySlug GreasySlug commented Dec 31, 2022

Currently, many of the errors in the parser use simple_syntax_error( or skip_and_throw_syntax_err).
This causes almost all errors to generate invalid syntax error, making them difficult to understand.
This lets you know how invalid syntax is.

In addition, add doc comment.

Changes proposed in this PR:

Define specify error

Use following errors

Internal error(parser bug)

It is a high possibility of the parser bug if it coccus

  • parser_bug
  • feature_error
  • unexpected_none
  • failed_to_analyze_block
  • unexpected_token_error

Invalid/unintended syntax error

Some sentences are written in Parser
They are not listed here

syntax error of parsing

  • simple_syntax_error
    invalid syntax
  • syntax_error
    invalid syntax
  • invalid_chunk_error
    semicolon or newline should be added
    invalid syntax
  • invalid_to_convert
    failed to convert from to to
  • invalid_definition_of_last_block
    cannot define a variable at the end of a block
  • invalid_token_error
    expect: ...
    but found: ...
    invalid syntax
  • invalid_seq_elems_error
    invalid sequential elements declaration
  • invalid_record_element_err
    only var or def can be used in record
    different record type element declarations
  • invalid_data_pack_definition
    expect: record
    but found: ...
    contents of data class are different
  • expect_keyword_error
    keyword is not specified
  • invalid_non_default_parameter
    := should be added
    non-default argument follows default argument
  • invalid_type_tuple_specified_error
    cannot declare type specified by Tuple type element
  • expect_type_specified
    please specify the type
    invalid type specification
  • unclosed_error
    add the bracket
    type is not closed with the bracket
  • expect_method_error
    expect: method
    but found: ...
    Class methods should be defined
  • expect_accessor
    expect accessor
    invalid syntax
  • invalid_acc_chain
    expect: method, NatLit, attr, array

Minor adjustment

  • When next_expr()/line() are used, put log!()

@mtshiba

@GreasySlug GreasySlug force-pushed the feature/parser-err branch 2 times, most recently from f174826 to 67dece9 Compare January 2, 2023 10:48
@GreasySlug
Copy link
Member Author

GreasySlug commented Jan 7, 2023

Could you please check the translation again when this PR is ready from the draft?
@C-BJ

It's fine about 2 failing checks
I'll fix them

@C-BJ
Copy link
Member

C-BJ commented Jan 7, 2023

OK

@GreasySlug
Copy link
Member Author

GreasySlug commented Jan 7, 2023

对不起,这个PR仍在进行中
我建议你先不要翻译它,因为我正在做破坏性的修改
能否请你在这份PR从草稿中准备好后再检查一下翻译
如果你想知道,到目前为止,你的翻译并没有引起任何冲突,所以这不是一个问题
@C-BJ

@C-BJ
Copy link
Member

C-BJ commented Jan 7, 2023

oh, sorry. I read it wrong.

@GreasySlug GreasySlug force-pushed the feature/parser-err branch 2 times, most recently from b0e5218 to 12b74d7 Compare January 14, 2023 07:11
@GreasySlug GreasySlug force-pushed the feature/parser-err branch 5 times, most recently from 19fe017 to caf166c Compare January 22, 2023 05:48
@GreasySlug GreasySlug force-pushed the feature/parser-err branch 2 times, most recently from b79e686 to e5c62b5 Compare January 27, 2023 03:27
@GreasySlug GreasySlug changed the title [WIP] Classify parser errors and use them Classify parser errors and use them Jan 27, 2023
@GreasySlug
Copy link
Member Author

GreasySlug commented Jan 27, 2023

70% of the work has been done

  • Refine the error messages a bit more
  • to have the translation checked

crates/erg_parser/error.rs Show resolved Hide resolved
crates/erg_parser/error.rs Outdated Show resolved Hide resolved
crates/erg_parser/error.rs Outdated Show resolved Hide resolved
@mtshiba
Copy link
Member

mtshiba commented Feb 13, 2023

The parser seems to erase class attributes.

C = Class {x = Int;}
C.
    x = 1 # no-linebreak
$ cargo r -- --mode parse test.er
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `target\debug\erg.exe --mode parse test.er`
C =
    ::Class:
        {::x =
    ::Int; }

$

@GreasySlug GreasySlug force-pushed the feature/parser-err branch 3 times, most recently from 2004433 to b605216 Compare February 14, 2023 12:02
@GreasySlug
Copy link
Member Author

Please ask me to review the translation again when it is finished @GreasySlug

I have finished writing the error messages, so if there are any translation errors or good translations in the Chinese ones please correct them, @C-BJ

@mtshiba mtshiba force-pushed the main branch 2 times, most recently from 67d834a to 68a27f8 Compare June 2, 2023 14:46
crates/erg_parser/parse.rs Outdated Show resolved Hide resolved
crates/erg_parser/parse.rs Outdated Show resolved Hide resolved
crates/erg_parser/parse.rs Outdated Show resolved Hide resolved
crates/erg_parser/parse.rs Outdated Show resolved Hide resolved
crates/erg_parser/parse.rs Outdated Show resolved Hide resolved
@GreasySlug GreasySlug merged commit 57e5a50 into erg-lang:main Jun 9, 2023
8 checks passed
@mtshiba
Copy link
Member

mtshiba commented Jun 9, 2023

Congrats & thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants