pub struct AstModule { /* private fields */ }
Expand description

A representation of a Starlark module abstract syntax tree.

Created with either parse or parse_file, and evaluated with eval_module.

The internal details (statements/expressions) are deliberately omitted, as they change more regularly. A few methods to obtain information about the AST are provided.

Implementations

Which symbols are exported by this module. These are the top-level assignments, including function definitions. Any symbols that start with _ are not exported.

Run a static linter over the module. If the complete set of global variables are known they can be passed as the globals argument, resulting in name-resolution lint errors. The precise checks run by the linter are not considered stable between versions.

Locations where statements occur, likely to be passed as the positions to before_stmt.

Parse a file stored on disk. For details see parse.

Parse a Starlark module to produce an AstModule, or an error if there are syntax errors. The filename is for error messages only, and does not have to be a valid file. The Dialect selects which Starlark constructs are valid.

Errors will be reported using the Diagnostic type. For example:

use starlark::syntax::{AstModule, Dialect};
use starlark::errors::Diagnostic;

let err: anyhow::Error = AstModule::parse("filename", "\n(unmatched".to_owned(), &Dialect::Standard).unwrap_err();
let err: Diagnostic = err.downcast::<Diagnostic>().unwrap();
assert_eq!(err.span.unwrap().to_string(), "filename:2:11");

Return the file names of all the load statements in the module. If the Dialect had enable_load set to false this will be an empty list.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Get an ARef pointing at this type.

Try and get an ARef pointing at this type. Returns an Err if the type Self is a RefCell which is already mutably borrowed. Read more

Return the underlying RefCell if Self is one, otherwise None.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Convert between two equal types.

Convert between references to two equal types.

Convert between mutable references to two equal types.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.