Skip to content

Commit bca3c9e

Browse files
authored
Merge pull request #128 from saona-raimundo/doc-comments
On wit sintax: formalizing documentation comments (second attempt)
2 parents 2e654dc + 1c67f77 commit bca3c9e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

WIT.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ comment ::= '//' character-that-isnt-a-newline*
5858
| '/*' any-unicode-character* '*/'
5959
```
6060

61+
There is a special type of comment called `documentation comment`. A
62+
`doc-comment` is either a line comment preceded with `///` whichends at the next
63+
newline (`\n`) character or it's a block comment which starts with `/**` and ends
64+
with `*/`. Note that block comments are allowed to be nested and their delimiters
65+
must be balanced
66+
67+
```wit
68+
doc-comment ::= '///' character-that-isnt-a-newline*
69+
| '/**' any-unicode-character* '*/'
70+
```
71+
6172
### Operators
6273

6374
There are some common operators in the lexical structure of `wit` used for

crates/parser/src/ast/resolve.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,13 @@ impl Resolver {
514514
}
515515
let mut docs = String::new();
516516
for doc in doc.docs.iter() {
517-
if let Some(doc) = doc.strip_prefix("//") {
517+
// Comments which are not doc-comments are silently ignored
518+
if let Some(doc) = doc.strip_prefix("///") {
518519
docs.push_str(doc.trim_start_matches('/').trim());
519520
docs.push('\n');
520-
} else {
521-
assert!(doc.starts_with("/*"));
521+
} else if let Some(doc) = doc.strip_prefix("/**") {
522522
assert!(doc.ends_with("*/"));
523-
for line in doc[2..doc.len() - 2].lines() {
523+
for line in doc[..doc.len() - 2].lines() {
524524
docs.push_str(line);
525525
docs.push('\n');
526526
}

0 commit comments

Comments
 (0)