-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,4 +54,3 @@ jobs: | |
message: ${{ needs.prepare.outputs.out }} | ||
arg: 42 | ||
env: env | ||
os-env: os-env |
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,54 @@ | ||
package comments | ||
|
||
import ( | ||
"go/ast" | ||
"go/token" | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
var ( | ||
docRequired = regexp.MustCompile("^//goaction:required$") | ||
docSkip = regexp.MustCompile("^//goaction:skip$") | ||
docDefault = regexp.MustCompile("^//goaction:default (.*)$") | ||
docDesc = regexp.MustCompile("^//goaction:description (.*)$") | ||
) | ||
|
||
// Comments holds information from doc string. | ||
type Comments struct { | ||
Required Bool | ||
Skip Bool | ||
Default String | ||
Desc String | ||
} | ||
|
||
type Bool struct { | ||
token.Pos | ||
Value bool | ||
} | ||
|
||
type String struct { | ||
token.Pos | ||
Value string | ||
} | ||
|
||
// parseComment searches for a special doc is a comment group. | ||
func (d *Comments) Parse(doc *ast.CommentGroup) { | ||
if doc == nil { | ||
return | ||
} | ||
for _, comment := range doc.List { | ||
txt := comment.Text | ||
pos := comment.Slash | ||
switch { | ||
case docRequired.MatchString(txt): | ||
d.Required = Bool{Value: true, Pos: pos} | ||
case docSkip.MatchString(txt): | ||
d.Skip = Bool{Value: true, Pos: pos} | ||
case docDefault.MatchString(txt): | ||
d.Default = String{Value: docDefault.FindStringSubmatch(txt)[1], Pos: pos} | ||
case docDesc.MatchString(txt): | ||
d.Desc = String{Value: strconv.Quote(docDesc.FindStringSubmatch(txt)[1]), Pos: pos} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.