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
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.
The returned error may contain diagnostic information. For example:
use blueprint_starlark_syntax::codemap::FileSpan;
use blueprint_starlark_syntax::syntax::AstModule;
use blueprint_starlark_syntax::syntax::Dialect;
let err: blueprint_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");Sourcepub fn loads(&self) -> Vec<AstLoad<'_>>
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.
Sourcepub fn stmt_locations(&self) -> Vec<FileSpan>
pub fn stmt_locations(&self) -> Vec<FileSpan>
Locations where statements occur.
Sourcepub fn replace_binary_operators(&mut self, replace: &HashMap<String, String>)
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).
Sourcepub fn is_suppressed(&self, issue_short_name: &str, issue_span: Span) -> bool
pub fn is_suppressed(&self, issue_short_name: &str, issue_span: Span) -> bool
Check if a given Lint short_name and span is suppressed in this module