From fb0c623a3b43586adf82d18e45d28e5491b8a14a Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Mon, 15 Jul 2024 15:33:21 +0900 Subject: [PATCH] single line comment with regex --- language.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/language.go b/language.go index a4410cb..4cfff1d 100644 --- a/language.go +++ b/language.go @@ -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. @@ -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 {