Skip to content

Commit

Permalink
single line comment with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jul 15, 2024
1 parent bb0cab6 commit fb0c623
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ type ClocLanguage struct {

// Language is a type used to definitions and store statistics for one programming language.
type Language struct {
Name string
lineComments []string
multiLines [][]string
Files []string
Code int32
Comments int32
Blanks int32
Total int32
Name string
lineComments []string
regexLineComments []*regexp.Regexp
multiLines [][]string
Files []string
Code int32
Comments int32
Blanks int32
Total int32
}

// Languages is an array representation of Language.
Expand Down Expand Up @@ -459,6 +460,15 @@ func NewLanguage(name string, lineComments []string, multiLines [][]string) *Lan
}
}

func (l *Language) WithRegexLineComments(regexLineComments []string) *Language {
var regexLineCommentsCompiled []*regexp.Regexp
for _, r := range regexLineComments {
regexLineCommentsCompiled = append(regexLineCommentsCompiled, regexp.MustCompile(r))
}
l.regexLineComments = regexLineCommentsCompiled
return l
}

func lang2exts(lang string) (exts string) {
var es []string
for ext, l := range Exts {
Expand Down

0 comments on commit fb0c623

Please sign in to comment.