pub struct Document<N: TreeNode = SyntaxNode>(/* private fields */);Expand description
Represents a single WDL document.
See Document::ast for getting a version-specific Abstract Syntax Tree.
Implementations§
Source§impl Document
impl Document
Sourcepub fn parse(source: &str) -> (Self, Vec<Diagnostic>)
pub fn parse(source: &str) -> (Self, Vec<Diagnostic>)
Parses a document from the given source.
A document and its AST elements are trivially cloned.
§Example
let (document, diagnostics) = Document::parse("version 1.1");
assert!(diagnostics.is_empty());
assert_eq!(
document
.version_statement()
.expect("should have version statement")
.version()
.text(),
"1.1"
);
match document.ast() {
Ast::V1(ast) => {
assert_eq!(ast.items().count(), 0);
}
Ast::Unsupported => panic!("should be a V1 AST"),
}Source§impl<N: TreeNode> Document<N>
impl<N: TreeNode> Document<N>
Sourcepub fn version_statement(&self) -> Option<VersionStatement<N>>
pub fn version_statement(&self) -> Option<VersionStatement<N>>
Gets the version statement of the document.
This can be used to determine the version of the document that was parsed.
A return value of None signifies a missing version statement.
Sourcepub fn ast_with_version_fallback(
&self,
fallback_version: Option<SupportedVersion>,
) -> Ast<N>
pub fn ast_with_version_fallback( &self, fallback_version: Option<SupportedVersion>, ) -> Ast<N>
Gets the AST representation of the document, falling back to the specified WDL version if the document’s version statement contains an unrecognized version.
A fallback version of None does not have any fallback behavior, and is
equivalent to calling Document::ast().
It is the caller’s responsibility to ensure that falling back to the given version does not introduce unwanted behavior. For applications where correctness is essential, the caller should only provide a version that is known to be compatible with the version declared in the document.