Skip to content

Commit

Permalink
v0.8.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Apr 28, 2020
1 parent 6ba760b commit 52f8826
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## v0.8.0-rc1 - 2020-04-28

- Strings are now encoded as utf8 binaries in the generated Erlang.
- HTML documentation can now be generated from Gleam code by running `gleam
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gleam"
version = "0.8.0-dev"
version = "0.8.0-rc1"
authors = ["Louis Pilfold <[email protected]>"]
edition = "2018"

Expand Down
12 changes: 12 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ pub struct RecordConstructor {
pub location: SrcSpan,
pub name: String,
pub args: Vec<(Option<String>, TypeAst)>,
pub documentation: Option<String>,
}

impl RecordConstructor {
pub fn put_doc<'a>(&mut self, new_doc: impl Iterator<Item = &'a str>) {
let mut new_doc = new_doc.peekable();
if new_doc.peek().is_none() {
return;
}

self.documentation = Some(new_doc.join("\n"));
}
}

#[derive(Debug, Clone, PartialEq)]
Expand Down
8 changes: 3 additions & 5 deletions src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ fn type_<'a>(statement: &'a TypedStatement) -> Option<Type<'a>> {
constructors: cs
.into_iter()
.map(|constructor| TypeConstructor {
name: constructor.name.as_ref(),
definition: print(formatter.record_constructor(constructor)),
documentation: "".to_string(),
documentation: markdown_documentation(&constructor.documentation),
})
.collect(),
}),
Expand Down Expand Up @@ -220,8 +219,7 @@ struct Function<'a> {
}

#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
struct TypeConstructor<'a> {
name: &'a str,
struct TypeConstructor {
definition: String,
documentation: String,
}
Expand All @@ -231,7 +229,7 @@ struct Type<'a> {
name: &'a str,
definition: String,
documentation: String,
constructors: Vec<TypeConstructor<'a>>,
constructors: Vec<TypeConstructor>,
}

#[derive(Template)]
Expand Down
1 change: 1 addition & 0 deletions src/erl/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn module_test() {
location: Default::default(),
name: "Ok".to_string(),
args: vec![],
documentation: None,
}],
},
Statement::Import {
Expand Down
1 change: 1 addition & 0 deletions src/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ RecordConstructor: RecordConstructor = {
location: location(s, e),
name: t,
args: args.unwrap_or_else(|| vec![]),
documentation: None,
},
}

Expand Down
12 changes: 9 additions & 3 deletions src/project/source_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ fn attach_doc_comments<'a, A, B, C>(
) {
for statement in &mut module.statements {
let location = statement.location();
// TODO: be more fine grained with how we apply the comments.
// i.e. Apply them to custom type constructors.
let (doc, rest) = parser::take_before(comments, location.end);
let (doc, rest) = parser::take_before(comments, location.start);
comments = rest;
statement.put_doc(doc);

if let crate::ast::Statement::CustomType { constructors, .. } = statement {
for constructor in constructors {
let (doc, rest) = parser::take_before(comments, constructor.location.start);
comments = rest;
constructor.put_doc(doc);
}
}
}
}
5 changes: 2 additions & 3 deletions templates/documentation_module.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ <h3>
<ul>
{% for constructor in typ.constructors %}
<li>
<code class="constructor-name">{{ constructor.name }}</code>
<pre>{{ constructor.definition }}</pre>
<p>{{ constructor.documentation|safe }}</p>
<code class="constructor-name">{{ constructor.definition }}</code>
{{ constructor.documentation|safe }}
</li>
{% endfor %}
</ul>
Expand Down
12 changes: 6 additions & 6 deletions test/core_language/test/binary_operators_test.gleam
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import should

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

0 comments on commit 52f8826

Please sign in to comment.