cairo_lang_parser::utils

Struct SimpleParserDatabase

Source
pub struct SimpleParserDatabase { /* private fields */ }
Expand description

A salsa database for parsing only.

Implementations§

Source§

impl SimpleParserDatabase

Source

pub fn parse_virtual( &self, content: impl ToString, ) -> Result<SyntaxNode, Diagnostics<ParserDiagnostic>>

Parses new file and returns its syntax root.

This is similar to Self::parse_virtual_with_diagnostics, but is more ergonomic in cases when exact diagnostics do not matter at the usage place. If the parser has emitted error diagnostics, this function will return an error. If no error diagnostics has been emitted, the syntax root will be returned.

Source

pub fn parse_virtual_with_diagnostics( &self, content: impl ToString, ) -> (SyntaxNode, Diagnostics<ParserDiagnostic>)

Parses new file and return its syntax root with diagnostics.

This function creates new virtual file with the given content and parses it. Diagnostics gathered by the parser are returned alongside the result.

Source

pub fn parse_token_stream( &self, token_stream: &dyn TokenStream, ) -> (SyntaxNode, Diagnostics<ParserDiagnostic>)

Parses a TokenStream (based on whole file) and returns its syntax root. It’s very similar to Self::parse_virtual_with_diagnostics, but instead of taking a content as a string, it takes a TokenStream.

Source

pub fn parse_token_stream_expr( &self, token_stream: &dyn TokenStream, ) -> (SyntaxNode, Diagnostics<ParserDiagnostic>)

Parses a TokenStream (based on a single expression). It’s very similar to the Self::parse_token_stream.

Trait Implementations§

Source§

impl Database for SimpleParserDatabase

Source§

fn salsa_event(&self, event_fn: Event)

This function is invoked at key points in the salsa runtime. It permits the database to be customized and to inject logging or other custom behavior.
Source§

fn unwind_if_cancelled(&self)

Starts unwinding the stack if the current revision is cancelled. Read more
Source§

fn salsa_runtime(&self) -> &Runtime

Gives access to the underlying salsa runtime. Read more
Source§

fn salsa_runtime_mut(&mut self) -> &mut Runtime

Gives access to the underlying salsa runtime. Read more
Source§

impl DatabaseOps for SimpleParserDatabase

Source§

fn ops_database(&self) -> &dyn Database

Upcast this type to a dyn Database.
Source§

fn ops_salsa_runtime(&self) -> &Runtime

Gives access to the underlying salsa runtime.
Source§

fn ops_salsa_runtime_mut(&mut self) -> &mut Runtime

Gives access to the underlying salsa runtime.
Source§

fn fmt_index(&self, input: DatabaseKeyIndex, fmt: &mut Formatter<'_>) -> Result

Formats a database key index in a human readable fashion.
Source§

fn maybe_changed_after( &self, input: DatabaseKeyIndex, revision: Revision, ) -> bool

True if the computed value for input may have changed since revision.
Source§

fn cycle_recovery_strategy( &self, input: DatabaseKeyIndex, ) -> CycleRecoveryStrategy

Find the CycleRecoveryStrategy for a given input.
Source§

fn for_each_query(&self, op: &mut dyn FnMut(&dyn QueryStorageMassOps))

Executes the callback for each kind of query.
Source§

impl DatabaseStorageTypes for SimpleParserDatabase

Source§

type DatabaseStorage = __SalsaDatabaseStorage

Defines the “storage type”, where all the query data is kept. This type is defined by the database_storage macro.
Source§

impl Default for SimpleParserDatabase

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl ExternalFiles for SimpleParserDatabase

Source§

fn ext_as_virtual(&self, external_id: InternId) -> VirtualFile

Returns the virtual file matching the external id.
Source§

fn try_ext_as_virtual(&self, _external_id: InternId) -> Option<VirtualFile>

Returns the virtual file matching the external id if found.
Source§

impl HasQueryGroup<FilesDatabase> for SimpleParserDatabase

Source§

fn group_storage(&self) -> &<FilesDatabase as QueryGroup>::GroupStorage

Access the group storage struct from the database.
Source§

fn group_storage_mut( &mut self, ) -> (&<FilesDatabase as QueryGroup>::GroupStorage, &mut Runtime)

Access the group storage struct from the database. Also returns a ref to the Runtime, since otherwise the database is borrowed and one cannot get access to it.
Source§

impl HasQueryGroup<ParserDatabase> for SimpleParserDatabase

Source§

fn group_storage(&self) -> &<ParserDatabase as QueryGroup>::GroupStorage

Access the group storage struct from the database.
Source§

fn group_storage_mut( &mut self, ) -> (&<ParserDatabase as QueryGroup>::GroupStorage, &mut Runtime)

Access the group storage struct from the database. Also returns a ref to the Runtime, since otherwise the database is borrowed and one cannot get access to it.
Source§

impl HasQueryGroup<SyntaxDatabase> for SimpleParserDatabase

Source§

fn group_storage(&self) -> &<SyntaxDatabase as QueryGroup>::GroupStorage

Access the group storage struct from the database.
Source§

fn group_storage_mut( &mut self, ) -> (&<SyntaxDatabase as QueryGroup>::GroupStorage, &mut Runtime)

Access the group storage struct from the database. Also returns a ref to the Runtime, since otherwise the database is borrowed and one cannot get access to it.
Source§

impl Upcast<dyn FilesGroup> for SimpleParserDatabase

Source§

fn upcast(&self) -> &(dyn FilesGroup + 'static)

Source§

impl Upcast<dyn SyntaxGroup> for SimpleParserDatabase

Source§

fn upcast(&self) -> &(dyn SyntaxGroup + 'static)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<DB> FilesGroup for DB
where DB: ExternalFiles + Database + HasQueryGroup<FilesDatabase>,

Source§

fn intern_crate(&self, crt: CrateLongId) -> CrateId

Source§

fn lookup_intern_crate(&self, key: CrateId) -> CrateLongId

Source§

fn intern_file(&self, file: FileLongId) -> FileId

Source§

fn lookup_intern_file(&self, key: FileId) -> FileLongId

Source§

fn intern_flag(&self, flag: FlagLongId) -> FlagId

Source§

fn lookup_intern_flag(&self, key: FlagId) -> FlagLongId

Source§

fn crate_configs(&self) -> Arc<OrderedHashMap<CrateId, CrateConfiguration>>

Main input of the project. Lists all the crates configurations.
Source§

fn set_crate_configs( &mut self, value__: Arc<OrderedHashMap<CrateId, CrateConfiguration>>, )

Set the value of the crate_configs input. Read more
Source§

fn set_crate_configs_with_durability( &mut self, value__: Arc<OrderedHashMap<CrateId, CrateConfiguration>>, durability__: Durability, )

Set the value of the crate_configs input with a specific durability instead of the default of Durability::LOW. You can use Durability::MAX to promise that its value will never change again. Read more
Source§

fn file_overrides(&self) -> Arc<OrderedHashMap<FileId, Arc<str>>>

Overrides for file content. Mostly used by language server and tests. TODO(spapini): Currently, when this input changes, all the file_content() queries will be invalidated. Change this mechanism to hold file_overrides on the db struct outside salsa mechanism, and invalidate manually.
Source§

fn set_file_overrides(&mut self, value__: Arc<OrderedHashMap<FileId, Arc<str>>>)

Set the value of the file_overrides input. Read more
Source§

fn set_file_overrides_with_durability( &mut self, value__: Arc<OrderedHashMap<FileId, Arc<str>>>, durability__: Durability, )

Set the value of the file_overrides input with a specific durability instead of the default of Durability::LOW. You can use Durability::MAX to promise that its value will never change again. Read more
Source§

fn flags(&self) -> Arc<OrderedHashMap<FlagId, Arc<Flag>>>

The compilation flags.
Source§

fn set_flags(&mut self, value__: Arc<OrderedHashMap<FlagId, Arc<Flag>>>)

Set the value of the flags input. Read more
Source§

fn set_flags_with_durability( &mut self, value__: Arc<OrderedHashMap<FlagId, Arc<Flag>>>, durability__: Durability, )

Set the value of the flags input with a specific durability instead of the default of Durability::LOW. You can use Durability::MAX to promise that its value will never change again. Read more
Source§

fn cfg_set(&self) -> Arc<CfgSet>

The #[cfg(...)] options.
Source§

fn set_cfg_set(&mut self, value__: Arc<CfgSet>)

Set the value of the cfg_set input. Read more
Source§

fn set_cfg_set_with_durability( &mut self, value__: Arc<CfgSet>, durability__: Durability, )

Set the value of the cfg_set input with a specific durability instead of the default of Durability::LOW. You can use Durability::MAX to promise that its value will never change again. Read more
Source§

fn crates(&self) -> Vec<CrateId>

List of crates in the project.
Source§

fn crate_config(&self, crate_id: CrateId) -> Option<CrateConfiguration>

Configuration of the crate.
Source§

fn priv_raw_file_content(&self, file_id: FileId) -> Option<Arc<str>>

Query for raw file contents. Private.
Source§

fn file_content(&self, file_id: FileId) -> Option<Arc<str>>

Query for the file contents. This takes overrides into consideration.
Source§

fn file_summary(&self, file_id: FileId) -> Option<Arc<FileSummary>>

Source§

fn get_flag(&self, id: FlagId) -> Option<Arc<Flag>>

Query to get a compilation flag by its ID.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<DB> ParserGroup for DB
where DB: SyntaxGroup + Upcast<dyn SyntaxGroup> + FilesGroup + Database + HasQueryGroup<ParserDatabase>,

Source§

fn priv_file_syntax_data(&self, file_id: FileId) -> SyntaxData

Should only be used internally. Parses a file and returns the result and the generated ParserDiagnostic.
Source§

fn file_syntax(&self, file_id: FileId) -> Result<SyntaxNode, DiagnosticAdded>

Parses a file and returns its SyntaxNode.
Source§

fn file_module_syntax( &self, file_id: FileId, ) -> Result<SyntaxFile, DiagnosticAdded>

Parses a file and returns its AST as a root SyntaxFile.
Source§

fn file_expr_syntax(&self, file_id: FileId) -> Result<Expr, DiagnosticAdded>

Parses a file and returns its AST as an expression.
Source§

fn file_syntax_diagnostics( &self, file_id: FileId, ) -> Diagnostics<ParserDiagnostic>

Returns the parser diagnostics for this file.
Source§

impl<DB> SyntaxGroup for DB
where DB: FilesGroup + Upcast<dyn FilesGroup> + Database + HasQueryGroup<SyntaxDatabase>,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T
where T: ?Sized,

Source§

fn upcast(&self) -> &T

Source§

impl<T> UpcastMut<T> for T
where T: ?Sized,

Source§

fn upcast_mut(&mut self) -> &mut T

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more