mirror of
https://github.com/FuelLabs/sway.git
synced 2025-08-22 11:25:11 +00:00

## Description Adds module level docs & previews to `forc doc`. [Screencast from 2023-02-20 20-30-24.webm](https://user-images.githubusercontent.com/57543709/220232486-7ec0742a-59ef-41c9-a459-3c8c9b7d42c7.webm) ## Checklist - [x] I have linked to any relevant issues. Closes #4095 - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
61 lines
1.2 KiB
Rust
61 lines
1.2 KiB
Rust
mod attribute;
|
|
mod brackets;
|
|
mod dependency;
|
|
mod expr;
|
|
mod generics;
|
|
mod item;
|
|
mod keywords;
|
|
mod literal;
|
|
mod module;
|
|
mod parse;
|
|
mod parser;
|
|
mod path;
|
|
mod pattern;
|
|
mod priv_prelude;
|
|
mod punctuated;
|
|
mod token;
|
|
mod ty;
|
|
mod where_clause;
|
|
|
|
use crate::priv_prelude::*;
|
|
pub use crate::{
|
|
keywords::RESERVED_KEYWORDS,
|
|
parse::Parse,
|
|
parser::Parser,
|
|
token::{lex, lex_commented},
|
|
};
|
|
|
|
use sway_ast::{
|
|
attribute::Annotated,
|
|
token::{DocComment, DocStyle},
|
|
Module, ModuleKind,
|
|
};
|
|
use sway_error::handler::{ErrorEmitted, Handler};
|
|
|
|
use std::{path::PathBuf, sync::Arc};
|
|
|
|
pub fn parse_file(
|
|
handler: &Handler,
|
|
src: Arc<str>,
|
|
path: Option<Arc<PathBuf>>,
|
|
) -> Result<Annotated<Module>, ErrorEmitted> {
|
|
let ts = lex(handler, &src, 0, src.len(), path)?;
|
|
Parser::new(handler, &ts).parse_to_end().map(|(m, _)| m)
|
|
}
|
|
|
|
pub fn parse_module_kind(
|
|
handler: &Handler,
|
|
src: Arc<str>,
|
|
path: Option<Arc<PathBuf>>,
|
|
) -> Result<ModuleKind, ErrorEmitted> {
|
|
let ts = lex(handler, &src, 0, src.len(), path)?;
|
|
let mut parser = Parser::new(handler, &ts);
|
|
while let Some(DocComment {
|
|
doc_style: DocStyle::Inner,
|
|
..
|
|
}) = parser.peek()
|
|
{
|
|
parser.parse::<DocComment>()?;
|
|
}
|
|
parser.parse()
|
|
}
|