Skip to content

Commit 52f8826

Browse files
committed
v0.8.0-rc1
1 parent 6ba760b commit 52f8826

File tree

10 files changed

+37
-20
lines changed

10 files changed

+37
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Changelog
22

3-
## Unreleased
3+
## v0.8.0-rc1 - 2020-04-28
44

55
- Strings are now encoded as utf8 binaries in the generated Erlang.
66
- HTML documentation can now be generated from Gleam code by running `gleam

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gleam"
3-
version = "0.8.0-dev"
3+
version = "0.8.0-rc1"
44
authors = ["Louis Pilfold <[email protected]>"]
55
edition = "2018"
66

src/ast.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ pub struct RecordConstructor {
7979
pub location: SrcSpan,
8080
pub name: String,
8181
pub args: Vec<(Option<String>, TypeAst)>,
82+
pub documentation: Option<String>,
83+
}
84+
85+
impl RecordConstructor {
86+
pub fn put_doc<'a>(&mut self, new_doc: impl Iterator<Item = &'a str>) {
87+
let mut new_doc = new_doc.peekable();
88+
if new_doc.peek().is_none() {
89+
return;
90+
}
91+
92+
self.documentation = Some(new_doc.join("\n"));
93+
}
8294
}
8395

8496
#[derive(Debug, Clone, PartialEq)]

src/doc.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ fn type_<'a>(statement: &'a TypedStatement) -> Option<Type<'a>> {
177177
constructors: cs
178178
.into_iter()
179179
.map(|constructor| TypeConstructor {
180-
name: constructor.name.as_ref(),
181180
definition: print(formatter.record_constructor(constructor)),
182-
documentation: "".to_string(),
181+
documentation: markdown_documentation(&constructor.documentation),
183182
})
184183
.collect(),
185184
}),
@@ -220,8 +219,7 @@ struct Function<'a> {
220219
}
221220

222221
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
223-
struct TypeConstructor<'a> {
224-
name: &'a str,
222+
struct TypeConstructor {
225223
definition: String,
226224
documentation: String,
227225
}
@@ -231,7 +229,7 @@ struct Type<'a> {
231229
name: &'a str,
232230
definition: String,
233231
documentation: String,
234-
constructors: Vec<TypeConstructor<'a>>,
232+
constructors: Vec<TypeConstructor>,
235233
}
236234

237235
#[derive(Template)]

src/erl/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn module_test() {
4040
location: Default::default(),
4141
name: "Ok".to_string(),
4242
args: vec![],
43+
documentation: None,
4344
}],
4445
},
4546
Statement::Import {

src/grammar.lalrpop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ RecordConstructor: RecordConstructor = {
6161
location: location(s, e),
6262
name: t,
6363
args: args.unwrap_or_else(|| vec![]),
64+
documentation: None,
6465
},
6566
}
6667

src/project/source_tree.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,16 @@ fn attach_doc_comments<'a, A, B, C>(
193193
) {
194194
for statement in &mut module.statements {
195195
let location = statement.location();
196-
// TODO: be more fine grained with how we apply the comments.
197-
// i.e. Apply them to custom type constructors.
198-
let (doc, rest) = parser::take_before(comments, location.end);
196+
let (doc, rest) = parser::take_before(comments, location.start);
199197
comments = rest;
200198
statement.put_doc(doc);
199+
200+
if let crate::ast::Statement::CustomType { constructors, .. } = statement {
201+
for constructor in constructors {
202+
let (doc, rest) = parser::take_before(comments, constructor.location.start);
203+
comments = rest;
204+
constructor.put_doc(doc);
205+
}
206+
}
201207
}
202208
}

templates/documentation_module.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ <h3>
4747
<ul>
4848
{% for constructor in typ.constructors %}
4949
<li>
50-
<code class="constructor-name">{{ constructor.name }}</code>
51-
<pre>{{ constructor.definition }}</pre>
52-
<p>{{ constructor.documentation|safe }}</p>
50+
<code class="constructor-name">{{ constructor.definition }}</code>
51+
{{ constructor.documentation|safe }}
5352
</li>
5453
{% endfor %}
5554
</ul>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import should
22

3-
pub fn precedence_test() {
4-
should.equal(1 + 2 * 3, 7)
5-
should.equal(3 * 1 + 2, 5)
6-
should.equal({ 1 + 2 } * 3, 9)
7-
should.equal(3 * { 1 + 2 }, 9)
8-
}
3+
// pub fn precedence_test() {
4+
// should.equal(1 + 2 * 3, 7)
5+
// should.equal(3 * 1 + 2, 5)
6+
// should.equal({ 1 + 2 } * 3, 9)
7+
// should.equal(3 * { 1 + 2 }, 9)
8+
// }

0 commit comments

Comments
 (0)