pub struct ElmModule {
pub header: Spanned<ModuleHeader>,
pub module_documentation: Option<Spanned<String>>,
pub imports: Vec<Spanned<Import>>,
pub declarations: Vec<Spanned<Declaration>>,
pub comments: Vec<Spanned<Comment>>,
}Expand description
The root AST node representing a complete Elm source file.
Corresponds to:
ModuleinAST/Source.hsFileinElm.Syntax.File
Fields§
§header: Spanned<ModuleHeader>The module header declaration.
module_documentation: Option<Spanned<String>>Module-level documentation comment (appears after the header, before imports).
In Elm, a {-| ... -} comment immediately after the module ... exposing (...)
header is the module’s documentation. It is distinct from comments attached
to individual declarations.
imports: Vec<Spanned<Import>>Import declarations, in source order.
declarations: Vec<Spanned<Declaration>>Top-level declarations, in source order.
comments: Vec<Spanned<Comment>>Comments that are not attached to any declaration.
These are collected separately to allow round-trip fidelity when printing the AST back to source.
Implementations§
Source§impl ElmModule
impl ElmModule
Sourcepub fn leading_comments(&self, decl_index: usize) -> Vec<&Spanned<Comment>>
pub fn leading_comments(&self, decl_index: usize) -> Vec<&Spanned<Comment>>
Get comments that appear immediately before a declaration.
A comment is considered “leading” if it appears between the end of the previous declaration (or the last import, or the module header) and the start of this declaration.
Note: only comments that were captured during parsing are available.
For complete comment extraction, use extract_comments on the
original token stream.
Sourcepub fn trailing_comment(&self, decl_index: usize) -> Option<&Spanned<Comment>>
pub fn trailing_comment(&self, decl_index: usize) -> Option<&Spanned<Comment>>
Get comments that appear on the same line as the end of a declaration (trailing line comments).
Sourcepub fn module_comments(&self) -> Vec<&Spanned<Comment>>
pub fn module_comments(&self) -> Vec<&Spanned<Comment>>
Get all comments that appear before any declarations (module-level header comments, after imports).