Module recoverable

Module 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§

Recoverable
Adaptor to provide a syn::parse::Parse interface to ParseRecoverable types. Returns error if any error was set in RecoverableContext during parsing. Use Default implementation of RecoveryConfig.
RecoverableContext
Context that is provided in ParseRecoverable interface. Used to save Diagnostic messages or syn::Result.
RecoveryConfig
Config of parser. Used to extend parsing functionality by user needs.

Enums§

ParsingResult
Result of parsing.

Traits§

ParseRecoverable
Parsing interface for recoverable TokenStream parsing, analog to syn::parse::Parse but with ability to skip unexpected tokens, and more diagnostic messages.