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
sourceimpl AstModule
impl AstModule
sourcepub fn lint(&self, globals: Option<&[&str]>) -> Vec<Lint>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn lint(&self, globals: Option<&[&str]>) -> Vec<Lint>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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.
sourceimpl AstModule
impl AstModule
sourcepub fn parse_file(path: &Path, dialect: &Dialect) -> Result<Self>
pub fn parse_file(path: &Path, dialect: &Dialect) -> Result<Self>
Parse a file stored on disk. For details see parse
.
sourcepub fn parse(filename: &str, content: String, dialect: &Dialect) -> Result<Self>
pub fn parse(filename: &str, content: String, dialect: &Dialect) -> Result<Self>
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");
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for AstModule
impl Send for AstModule
impl Sync for AstModule
impl Unpin for AstModule
impl UnwindSafe for AstModule
Blanket Implementations
sourceimpl<T> AsARef<T> for T where
T: ?Sized,
impl<T> AsARef<T> for T where
T: ?Sized,
sourcefn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
fn try_as_aref(this: &T) -> Result<ARef<'_, T>, BorrowError>
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more