Skip to content

Commit

Permalink
Implementing doc-comments and discarding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
saona-raimundo committed Jan 7, 2022
1 parent 2e654dc commit 8f5fffd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions WIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ comment ::= '//' character-that-isnt-a-newline*
| '/*' any-unicode-character* '*/'
```

There is a special type of comment called `documentation comment`. A
`doc-comment` is either a line comment preceded with `///` whichends at the next
newline (`\n`) character or it's a block comment which starts with `/**` and ends
with `*/`. Note that block comments are allowed to be nested and their delimiters
must be balanced

```wit
doc-comment ::= '///' character-that-isnt-a-newline*
| '/**' any-unicode-character* '*/'
```

### Operators

There are some common operators in the lexical structure of `wit` used for
Expand Down
6 changes: 3 additions & 3 deletions crates/parser/src/ast/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,13 @@ impl Resolver {
}
let mut docs = String::new();
for doc in doc.docs.iter() {
if let Some(doc) = doc.strip_prefix("//") {
if let Some(doc) = doc.strip_prefix("///") {
docs.push_str(doc.trim_start_matches('/').trim());
docs.push('\n');
} else {
assert!(doc.starts_with("/*"));
assert!(doc.starts_with("/**"));
assert!(doc.ends_with("*/"));
for line in doc[2..doc.len() - 2].lines() {
for line in doc[3..doc.len() - 2].lines() {
docs.push_str(line);
docs.push('\n');
}
Expand Down

0 comments on commit 8f5fffd

Please sign in to comment.