Module rstml::recoverable

source ·
Expand description

Recoverable parser helper module. Contains trait and types that are using during implementation of parsing with recovery after semantic errors.

Recoverable parser is a type of parsing technique when parser don’t give up after getting invalid token, and instead continue to parse code to provide more info about TokenStream to IDE or user.

Instead of failing after first unclosed tag, or invalid block, recoverable parser will try to check if there any other syntax or semantic errors.

Example:

  <div hello={world.} /> // dot after world is invalid syn::Expr
  <>
      <div>"1"</x> // incorrect closed tag
      <div>"2"</div>
      <div>"3"</div>
      <div {"some-attribute-from-rust-block"}/>
  </>
  <bar> // unclosed tag

If this example was parsed by regular parser, it will fail with “invalid expression error” and no output. User will see only one error, and IDE cannot produce any completion in case of invalid expression.

But recoverable parser differ (see Parser::parse_recoverable), it will return array of errors and array of Node. Errors should be emitted, and value should be handled as no errors was found. In result, user will see all errors, and IDE can provide completion even if some part of token stream was unexpected.

Structs§

Enums§

Traits§