-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port parsing doc comments from 0.4.0.
- Loading branch information
1 parent
6421c1d
commit 6a44383
Showing
7 changed files
with
347 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ast | ||
|
||
type DocCommentContract struct { | ||
name string | ||
body string | ||
} | ||
|
||
type DocComment struct { | ||
body string | ||
contracts []*DocCommentContract | ||
} | ||
|
||
// Creates a doc comment with the given body. | ||
func NewDocComment(body string) *DocComment { | ||
return &DocComment{ | ||
body: body, | ||
contracts: []*DocCommentContract{}, | ||
} | ||
} | ||
|
||
// Creates a contract with the given name and body. | ||
// It is expected that the name begins with '@'. | ||
func NewDocCommentContract(name string, body string) *DocCommentContract { | ||
return &DocCommentContract{ | ||
name, | ||
body, | ||
} | ||
} | ||
|
||
// Add contracts to the given doc comment. | ||
func (d *DocComment) AddContracts(contracts []*DocCommentContract) { | ||
d.contracts = append(d.contracts, contracts...) | ||
} | ||
|
||
func (d *DocComment) GetBody() string { | ||
return d.body | ||
} | ||
|
||
// Return a string displaying the body and contracts as markdown. | ||
func (d *DocComment) DisplayBodyWithContracts() string { | ||
out := d.body | ||
|
||
for _, c := range d.contracts { | ||
out += "\n\n**" + c.name + "**" | ||
if c.body != "" { | ||
out += " " + c.body | ||
} | ||
} | ||
|
||
return out | ||
} |
Oops, something went wrong.