mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-13 09:49:11 +03:00
Merge branch 'trunk' into leak-refcount
This commit is contained in:
commit
5c825209eb
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -579,6 +579,9 @@ dependencies = [
|
||||
"fs_extra",
|
||||
"handlebars",
|
||||
"pulldown-cmark",
|
||||
"roc_builtins",
|
||||
"roc_collections",
|
||||
"roc_load",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
|
@ -1,5 +1,5 @@
|
||||
interface Bool
|
||||
exposes [ not, isEq, isNe ]
|
||||
interface Bool2
|
||||
exposes [ not, and, or, xor, isEq, isNotEq ]
|
||||
imports []
|
||||
|
||||
## Returns #False when given #True, and vice versa.
|
||||
@ -76,7 +76,9 @@ xor : Bool, Bool -> Bool
|
||||
##
|
||||
## Note that `isEq` takes `'val` instead of `val`, which means `isEq` does not
|
||||
## accept arguments whose types contain functions.
|
||||
isEq : 'val, 'val -> Bool
|
||||
# TODO: removed `'` from signature because parser does not support it yet
|
||||
# Original signature: `isEq : 'val, 'val -> Bool`
|
||||
isEq : val, val -> Bool
|
||||
|
||||
## Calls #eq on the given values, then calls #not on the result.
|
||||
##
|
||||
@ -84,4 +86,6 @@ isEq : 'val, 'val -> Bool
|
||||
##
|
||||
## Note that `isNotEq` takes `'val` instead of `val`, which means `isNotEq` does not
|
||||
## accept arguments whose types contain functions.
|
||||
isNotEq : 'val, 'val -> Bool
|
||||
# TODO: removed `'` from signature because parser does not support it yet
|
||||
# Original signature: `isNotEq : 'val, 'val -> Bool`
|
||||
isNotEq : val, val -> Bool
|
||||
|
@ -1,5 +1,5 @@
|
||||
interface List
|
||||
exposes [ List, map, fold ]
|
||||
interface List2
|
||||
exposes [ List, single, empty, repeat, range, reverse, sort, map, mapWithIndex, mapOrCancel, mapOks, update, updater, allOks, append, prepend, concat, join, joinMap, oks, zip, zipMap, keepIf, dropIf, first, last, get, max, min, put, drop, append, prepend, dropLast, dropFirst, takeFirst, takeLast, split, sublist, walk, walkBackwards, walkUntil, walkBackwardsUntil, len, isEmpty, contains, all, any ]
|
||||
imports []
|
||||
|
||||
## Types
|
||||
|
@ -1,16 +1,16 @@
|
||||
interface Map
|
||||
exposes [ Map, isEmpty ]
|
||||
interface Map2
|
||||
exposes [ isEmpty, map ]
|
||||
imports []
|
||||
|
||||
isEmpty : Map * * -> Bool
|
||||
|
||||
## Convert each key and value in the #Map to something new, by calling a conversion
|
||||
## function on each of them. Then return a new #Map of the converted keys and values.
|
||||
##
|
||||
##
|
||||
## >>> Map.map {{ 3.14 => "pi", 1.0 => "one" }} \{ key, value } -> { key:
|
||||
##
|
||||
##
|
||||
## >>> Map.map {[ "", "a", "bc" ]} Str.isEmpty
|
||||
##
|
||||
##
|
||||
## `map` functions like this are common in Roc, and they all work similarly.
|
||||
## See for example #Result.map, #List.map, and #Set.map.
|
||||
map : List before, (before -> after) -> List after
|
||||
|
@ -1,4 +1,4 @@
|
||||
interface Num
|
||||
interface Num2
|
||||
exposes [ Num, neg, abs, add, sub, mul, isOdd, isEven, isPositive, isNegative, isZero ]
|
||||
imports []
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
interface Set
|
||||
exposes [ Set, map, isEmpty ]
|
||||
interface Set2
|
||||
exposes [ empty, isEmpty, len, add, drop, map ]
|
||||
imports []
|
||||
|
||||
|
||||
@ -12,10 +12,14 @@ isEmpty : Set * -> Bool
|
||||
|
||||
len : Set * -> Len
|
||||
|
||||
add : Set 'elem, 'elem -> Set 'elem
|
||||
# TODO: removed `'` from signature because parser does not support it yet
|
||||
# Original signature: `add : Set 'elem, 'elem -> Set 'elem`
|
||||
add : Set elem, elem -> Set elem
|
||||
|
||||
## Drops the given element from the set.
|
||||
drop : Set 'elem, 'elem -> Set 'elem
|
||||
# TODO: removed `'` from signature because parser does not support it yet
|
||||
# Original signature: `drop : Set 'elem, 'elem -> Set 'elem`
|
||||
drop : Set elem, elem -> Set elem
|
||||
|
||||
## Convert each element in the set to something new, by calling a conversion
|
||||
## function on each of them. Then return a new set of the converted values.
|
||||
@ -26,4 +30,6 @@ drop : Set 'elem, 'elem -> Set 'elem
|
||||
##
|
||||
## `map` functions like this are common in Roc, and they all work similarly.
|
||||
## See for example #Result.map, #List.map, and #Map.map.
|
||||
map : Set 'elem, ('before -> 'after) -> Set 'after
|
||||
# TODO: removed `'` from signature because parser does not support it yet
|
||||
# Original signature: `map : Set 'elem, ('before -> 'after) -> Set 'after`
|
||||
map : Set elem, (before -> after) -> Set after
|
||||
|
@ -1,4 +1,6 @@
|
||||
interface Str exposes [ Str, isEmpty, join ] imports []
|
||||
interface Str2
|
||||
exposes [ Str2, decimal, split, isEmpty, startsWith, endsWith, contains, anyGraphemes, allGraphemes, join, joinWith, padGraphemesStart, padGraphemesEnd, graphemes, reverseGraphemes, isCaseInsensitiveEq, isCaseInsensitiveNeq, walkGraphemes, isCapitalized, isAllUppercase, isAllLowercase, toUtf8, toUtf16, toUtf32, walkUtf8, walkUtf16, walkUtf32, walkRevUtf8, walkRevUtf16, walkRevUtf32 ]
|
||||
imports []
|
||||
## Types
|
||||
|
||||
## Dealing with text is a deep topic, so by design, Roc's `Str` module sticks
|
||||
@ -98,7 +100,7 @@ interface Str exposes [ Str, isEmpty, join ] imports []
|
||||
|
||||
## A [Unicode](https://unicode.org) text value.
|
||||
##
|
||||
Str : [ @Str ]
|
||||
Str2 : [ @Str ]
|
||||
|
||||
## Convert
|
||||
|
||||
|
1660
compiler/load/src/docs.rs
Normal file
1660
compiler/load/src/docs.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -10,4 +10,5 @@
|
||||
// and encouraging shortcuts here creates bad incentives. I would rather temporarily
|
||||
// re-enable this when working on performance optimizations than have it block PRs.
|
||||
#![allow(clippy::large_enum_variant)]
|
||||
pub mod docs;
|
||||
pub mod file;
|
||||
|
1
docs/.gitignore
vendored
Normal file
1
docs/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
@ -13,3 +13,6 @@ serde_json = "1.0.39"
|
||||
serde_derive = "1.0.75"
|
||||
fs_extra = "1.2.0"
|
||||
pulldown-cmark = { version = "0.8", default-features = false }
|
||||
roc_load = { path = "../compiler/load" }
|
||||
roc_builtins = { path = "../compiler/builtins" }
|
||||
roc_collections = { path = "../compiler/collections" }
|
||||
|
186
docs/src/main.rs
186
docs/src/main.rs
@ -7,27 +7,9 @@ extern crate pulldown_cmark;
|
||||
extern crate serde_json;
|
||||
use std::error::Error;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Package {
|
||||
name: String,
|
||||
version: String,
|
||||
docs: String,
|
||||
modules: Vec<Module>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct Module {
|
||||
name: String,
|
||||
docs: String,
|
||||
entries: Vec<ModuleEntry>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct ModuleEntry {
|
||||
name: String,
|
||||
docs: String,
|
||||
}
|
||||
extern crate roc_load;
|
||||
use roc_collections::all::MutMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Template {
|
||||
@ -39,6 +21,12 @@ pub struct Template {
|
||||
module_links: Vec<TemplateLink>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Clone)]
|
||||
pub struct ModuleEntry {
|
||||
name: String,
|
||||
docs: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct TemplateLink {
|
||||
name: String,
|
||||
@ -53,132 +41,49 @@ pub struct TemplateLinkEntry {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let package = Package {
|
||||
let std_lib = roc_builtins::std::standard_stdlib();
|
||||
let subs_by_module = MutMap::default();
|
||||
let src_dir = Path::new("../compiler/builtins/docs");
|
||||
let files = vec![
|
||||
PathBuf::from(r"../compiler/builtins/docs/Bool.roc"),
|
||||
PathBuf::from(r"../compiler/builtins/docs/Map.roc"),
|
||||
// Not working
|
||||
// PathBuf::from(r"../compiler/builtins/docs/List.roc"),
|
||||
// Not working
|
||||
// PathBuf::from(r"../compiler/builtins/docs/Num.roc"),
|
||||
PathBuf::from(r"../compiler/builtins/docs/Set.roc"),
|
||||
PathBuf::from(r"../compiler/builtins/docs/Str.roc"),
|
||||
];
|
||||
|
||||
let mut modules_docs = vec![];
|
||||
|
||||
// Load each file is files vector
|
||||
for filename in files {
|
||||
let loaded = roc_load::docs::load(filename, &std_lib, src_dir, subs_by_module.clone())
|
||||
.expect("TODO gracefully handle load failing");
|
||||
modules_docs.push(loaded.module_docs);
|
||||
}
|
||||
|
||||
let package = roc_load::docs::Documentation {
|
||||
name: "roc/builtins".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
docs: "Package introduction or README.".to_string(),
|
||||
modules: vec![
|
||||
Module {
|
||||
name: "Str".to_string(),
|
||||
docs: "Module introduction".to_string(),
|
||||
entries: vec![
|
||||
ModuleEntry {
|
||||
name: "Str".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "isEmpty".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "append".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "prepend".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "concat".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "join".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "split".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "countGraphemes".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "foldGraphemes".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
],
|
||||
},
|
||||
Module {
|
||||
name: "Bool".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![
|
||||
ModuleEntry {
|
||||
name: "isEq".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "isNeq".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
],
|
||||
},
|
||||
Module {
|
||||
name: "Num".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![
|
||||
ModuleEntry {
|
||||
name: "add".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "sub".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
ModuleEntry {
|
||||
name: "mul".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example."
|
||||
.to_string(),
|
||||
},
|
||||
],
|
||||
},
|
||||
Module {
|
||||
name: "List".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![],
|
||||
},
|
||||
Module {
|
||||
name: "Set".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![],
|
||||
},
|
||||
Module {
|
||||
name: "Map".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![],
|
||||
},
|
||||
Module {
|
||||
name: "Result".to_string(),
|
||||
docs: "Hello world, this is a **complicated** *very simple* example.".to_string(),
|
||||
entries: vec![],
|
||||
},
|
||||
],
|
||||
modules: modules_docs,
|
||||
};
|
||||
|
||||
// Make sure the directories exists
|
||||
// Remove old build folder
|
||||
fs::remove_dir_all("./build")?;
|
||||
|
||||
// Make sure the output directories exists
|
||||
fs::create_dir_all(format!("./build/{}/{}", package.name, package.version))?;
|
||||
|
||||
// Register handlebar template
|
||||
// Register handlebars template
|
||||
let mut handlebars = handlebars::Handlebars::new();
|
||||
assert!(handlebars
|
||||
.register_template_file("page", "./src/templates/page.hbs")
|
||||
.is_ok());
|
||||
|
||||
let markdown_options = pulldown_cmark::Options::empty();
|
||||
let markdown_options = pulldown_cmark::Options::all();
|
||||
|
||||
// Write each package's module docs
|
||||
for module in &package.modules {
|
||||
@ -198,11 +103,12 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.into_iter()
|
||||
.map(|entry| {
|
||||
// Convert entry docs from markdown to html
|
||||
let entry_docs_parser =
|
||||
pulldown_cmark::Parser::new_ext(&entry.docs, markdown_options);
|
||||
let mut entry_docs_html: String =
|
||||
String::with_capacity(entry.docs.len() * 3 / 2);
|
||||
pulldown_cmark::html::push_html(&mut entry_docs_html, entry_docs_parser);
|
||||
let mut entry_docs_html: String = String::new();
|
||||
if let Some(docs) = entry.docs {
|
||||
let entry_docs_parser =
|
||||
pulldown_cmark::Parser::new_ext(&docs, markdown_options);
|
||||
pulldown_cmark::html::push_html(&mut entry_docs_html, entry_docs_parser);
|
||||
}
|
||||
|
||||
ModuleEntry {
|
||||
name: entry.name.clone(),
|
||||
|
Loading…
Reference in New Issue
Block a user