Struct starlark::syntax::AstModule

source ·
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 Evaluator::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§

source§

impl AstModule

source

pub fn parse_file(path: &Path, dialect: &Dialect) -> Result<AstModule, Error>

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

source

pub fn parse( filename: &str, content: String, dialect: &Dialect ) -> Result<AstModule, Error>

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.

The returned error may contain diagnostic information. For example:

use starlark_syntax::codemap::FileSpan;
use starlark_syntax::syntax::AstModule;
use starlark_syntax::syntax::Dialect;

let err: starlark_syntax::Error =
    AstModule::parse("filename", "\n(unmatched".to_owned(), &Dialect::Standard).unwrap_err();
let span: &FileSpan = err.span().unwrap();
assert_eq!(span.to_string(), "filename:2:11");
source

pub fn loads(&self) -> Vec<AstLoad<'_>>

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.

source

pub fn file_span(&self, x: Span) -> FileSpan

Look up a Span contained in this module to a FileSpan.

source

pub fn stmt_locations(&self) -> Vec<FileSpan>

Locations where statements occur.

source

pub fn replace_binary_operators(&mut self, replace: &HashMap<String, String>)

Function to help people who want to write deeper AST transformations in Starlark. Likely to break type checking and LSP support to some extent.

Replacement must be a map from operator name (e.g. + or ==) to a function name (e.g. my_plus or my_equals).

Trait Implementations§

source§

impl AstModuleFields for AstModule

source§

impl AstModuleFindCallName for AstModule

source§

fn find_function_call_with_name(&self, name: &str) -> Option<Span>

Find the location of a top level function call that has a kwarg “name”, and a string value matching name. Read more
source§

impl AstModuleLint for AstModule

source§

fn lint(&self, globals: Option<&HashSet<String>>) -> Vec<Lint>

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.
source§

impl AstModuleTypecheck for AstModule

source§

fn typecheck( self, globals: &Globals, loads: &HashMap<String, Interface> ) -> (Vec<Error>, TypeMap, Interface, Vec<Approximation>)

Typecheck a module.
source§

impl Debug for AstModule

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToAst for T

source§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

source§

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

§

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>,

§

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.