mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
reference TypeAnnotation from ast as ast::TypeAnnotation so that the name TypeAnnotation can be reused in roc_load::docs
This commit is contained in:
parent
e168fb201d
commit
406860f121
2 changed files with 28 additions and 28 deletions
|
@ -1,8 +1,8 @@
|
||||||
use crate::docs::DocTypeAnnotation::{Apply, BoundVariable, TagUnion};
|
use crate::docs::TypeAnnotation::{Apply, BoundVariable, TagUnion};
|
||||||
use inlinable_string::InlinableString;
|
use inlinable_string::InlinableString;
|
||||||
use roc_module::ident::ModuleName;
|
use roc_module::ident::ModuleName;
|
||||||
use roc_module::symbol::IdentIds;
|
use roc_module::symbol::IdentIds;
|
||||||
use roc_parse::ast::{Def, Tag, TypeAnnotation};
|
use roc_parse::ast;
|
||||||
use roc_region::all::Located;
|
use roc_region::all::Located;
|
||||||
|
|
||||||
// Documentation generation requirements
|
// Documentation generation requirements
|
||||||
|
@ -26,33 +26,33 @@ pub struct ModuleDocumentation {
|
||||||
pub struct DocEntry {
|
pub struct DocEntry {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub type_vars: Vec<String>,
|
pub type_vars: Vec<String>,
|
||||||
pub type_annotation: Option<DocTypeAnnotation>,
|
pub type_annotation: Option<TypeAnnotation>,
|
||||||
pub docs: Option<String>,
|
pub docs: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum DocTypeAnnotation {
|
pub enum TypeAnnotation {
|
||||||
TagUnion {
|
TagUnion {
|
||||||
tags: Vec<DocTag>,
|
tags: Vec<Tag>,
|
||||||
extension: Option<Box<DocTypeAnnotation>>,
|
extension: Option<Box<TypeAnnotation>>,
|
||||||
},
|
},
|
||||||
BoundVariable(String),
|
BoundVariable(String),
|
||||||
Apply {
|
Apply {
|
||||||
name: String,
|
name: String,
|
||||||
parts: Vec<DocTypeAnnotation>,
|
parts: Vec<TypeAnnotation>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DocTag {
|
pub struct Tag {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub values: Vec<DocTypeAnnotation>,
|
pub values: Vec<TypeAnnotation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_module_docs<'a>(
|
pub fn generate_module_docs<'a>(
|
||||||
module_name: ModuleName,
|
module_name: ModuleName,
|
||||||
exposed_ident_ids: &'a IdentIds,
|
exposed_ident_ids: &'a IdentIds,
|
||||||
parsed_defs: &'a [Located<Def<'a>>],
|
parsed_defs: &'a [Located<ast::Def<'a>>],
|
||||||
) -> ModuleDocumentation {
|
) -> ModuleDocumentation {
|
||||||
let (entries, _) =
|
let (entries, _) =
|
||||||
parsed_defs
|
parsed_defs
|
||||||
|
@ -72,7 +72,7 @@ fn generate_module_doc<'a>(
|
||||||
exposed_ident_ids: &'a IdentIds,
|
exposed_ident_ids: &'a IdentIds,
|
||||||
mut acc: Vec<DocEntry>,
|
mut acc: Vec<DocEntry>,
|
||||||
before_comments_or_new_lines: Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
before_comments_or_new_lines: Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
||||||
def: &'a Def<'a>,
|
def: &'a ast::Def<'a>,
|
||||||
) -> (
|
) -> (
|
||||||
Vec<DocEntry>,
|
Vec<DocEntry>,
|
||||||
Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
Option<&'a [roc_parse::ast::CommentOrNewline<'a>]>,
|
||||||
|
@ -162,14 +162,14 @@ fn generate_module_doc<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
fn type_to_docs(type_annotation: ast::TypeAnnotation) -> Option<TypeAnnotation> {
|
||||||
match type_annotation {
|
match type_annotation {
|
||||||
TypeAnnotation::TagUnion {
|
ast::TypeAnnotation::TagUnion {
|
||||||
tags,
|
tags,
|
||||||
ext,
|
ext,
|
||||||
final_comments: _,
|
final_comments: _,
|
||||||
} => {
|
} => {
|
||||||
let mut tags_to_render: Vec<DocTag> = Vec::new();
|
let mut tags_to_render: Vec<Tag> = Vec::new();
|
||||||
|
|
||||||
let mut any_tags_are_private = false;
|
let mut any_tags_are_private = false;
|
||||||
|
|
||||||
|
@ -204,8 +204,8 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeAnnotation::BoundVariable(var_name) => Some(BoundVariable(var_name.to_string())),
|
ast::TypeAnnotation::BoundVariable(var_name) => Some(BoundVariable(var_name.to_string())),
|
||||||
TypeAnnotation::Apply(module_name, type_name, type_ann_parts) => {
|
ast::TypeAnnotation::Apply(module_name, type_name, type_ann_parts) => {
|
||||||
let mut name = String::new();
|
let mut name = String::new();
|
||||||
|
|
||||||
if !module_name.is_empty() {
|
if !module_name.is_empty() {
|
||||||
|
@ -215,7 +215,7 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
||||||
|
|
||||||
name.push_str(type_name);
|
name.push_str(type_name);
|
||||||
|
|
||||||
let mut parts: Vec<DocTypeAnnotation> = Vec::new();
|
let mut parts: Vec<TypeAnnotation> = Vec::new();
|
||||||
|
|
||||||
for type_ann_part in type_ann_parts {
|
for type_ann_part in type_ann_parts {
|
||||||
if let Some(part) = type_to_docs(type_ann_part.value) {
|
if let Some(part) = type_to_docs(type_ann_part.value) {
|
||||||
|
@ -235,9 +235,9 @@ fn type_to_docs(type_annotation: TypeAnnotation) -> Option<DocTypeAnnotation> {
|
||||||
|
|
||||||
// The Option here represents if it is private. Private tags
|
// The Option here represents if it is private. Private tags
|
||||||
// evaluate to `None`.
|
// evaluate to `None`.
|
||||||
fn tag_to_doc(tag: Tag) -> Option<DocTag> {
|
fn tag_to_doc(tag: ast::Tag) -> Option<Tag> {
|
||||||
match tag {
|
match tag {
|
||||||
Tag::Global { name, args } => Some(DocTag {
|
ast::Tag::Global { name, args } => Some(Tag {
|
||||||
name: name.value.to_string(),
|
name: name.value.to_string(),
|
||||||
values: {
|
values: {
|
||||||
let mut type_vars = Vec::new();
|
let mut type_vars = Vec::new();
|
||||||
|
@ -257,10 +257,10 @@ fn tag_to_doc(tag: Tag) -> Option<DocTag> {
|
||||||
type_vars
|
type_vars
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
Tag::Private { .. } => None,
|
ast::Tag::Private { .. } => None,
|
||||||
Tag::SpaceBefore(&sub_tag, _) => tag_to_doc(sub_tag),
|
ast::Tag::SpaceBefore(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||||
Tag::SpaceAfter(&sub_tag, _) => tag_to_doc(sub_tag),
|
ast::Tag::SpaceAfter(&sub_tag, _) => tag_to_doc(sub_tag),
|
||||||
Tag::Malformed(_) => None,
|
ast::Tag::Malformed(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
extern crate pulldown_cmark;
|
extern crate pulldown_cmark;
|
||||||
use roc_builtins::std::StdLib;
|
use roc_builtins::std::StdLib;
|
||||||
use roc_can::builtins::builtin_defs_map;
|
use roc_can::builtins::builtin_defs_map;
|
||||||
use roc_load::docs::DocTypeAnnotation;
|
|
||||||
use roc_load::docs::ModuleDocumentation;
|
use roc_load::docs::ModuleDocumentation;
|
||||||
|
use roc_load::docs::TypeAnnotation;
|
||||||
use roc_load::file::LoadingProblem;
|
use roc_load::file::LoadingProblem;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -291,9 +291,9 @@ fn indent(buf: &mut String, times: usize) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &DocTypeAnnotation) {
|
fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &TypeAnnotation) {
|
||||||
match type_ann {
|
match type_ann {
|
||||||
DocTypeAnnotation::TagUnion { tags, extension } => {
|
TypeAnnotation::TagUnion { tags, extension } => {
|
||||||
buf.push_str("<br>");
|
buf.push_str("<br>");
|
||||||
|
|
||||||
let tag_union_indent = indent_level + 1;
|
let tag_union_indent = indent_level + 1;
|
||||||
|
@ -336,10 +336,10 @@ fn type_annotation_to_html(indent_level: usize, buf: &mut String, type_ann: &Doc
|
||||||
type_annotation_to_html(indent_level, buf, ext);
|
type_annotation_to_html(indent_level, buf, ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DocTypeAnnotation::BoundVariable(var_name) => {
|
TypeAnnotation::BoundVariable(var_name) => {
|
||||||
buf.push_str(var_name);
|
buf.push_str(var_name);
|
||||||
}
|
}
|
||||||
DocTypeAnnotation::Apply { name, parts } => {
|
TypeAnnotation::Apply { name, parts } => {
|
||||||
if parts.is_empty() {
|
if parts.is_empty() {
|
||||||
buf.push_str(name);
|
buf.push_str(name);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue