Skip to content

Commit

Permalink
add Just lang
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Jul 15, 2024
1 parent fb0c623 commit fb8f0f7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
34 changes: 25 additions & 9 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,33 @@ scannerloop:
line = trimBOM(line)
}

singleloop:
for _, singleComment := range language.lineComments {
if strings.HasPrefix(line, singleComment) {
// check if single comment is a prefix of multi comment
for _, ml := range language.multiLines {
if ml[0] != "" && strings.HasPrefix(line, ml[0]) {
break singleloop
if len(language.regexLineComments) > 0 {
singleloopRegex:
for _, singleCommentRegex := range language.regexLineComments {
if singleCommentRegex.MatchString(line) {
// check if single comment is a prefix of multi comment
for _, ml := range language.multiLines {
if ml[0] != "" && strings.HasPrefix(line, ml[0]) {
break singleloopRegex
}
}
onComment(clocFile, opts, len(inComments) > 0, line, lineOrg)
continue scannerloop
}
}
} else {
singleloop:
for _, singleComment := range language.lineComments {
if strings.HasPrefix(line, singleComment) {
// check if single comment is a prefix of multi comment
for _, ml := range language.multiLines {
if ml[0] != "" && strings.HasPrefix(line, ml[0]) {
break singleloop
}
}
onComment(clocFile, opts, len(inComments) > 0, line, lineOrg)
continue scannerloop
}
onComment(clocFile, opts, len(inComments) > 0, line, lineOrg)
continue scannerloop
}
}

Expand Down
4 changes: 4 additions & 0 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ var Exts = map[string]string{
"janet": "Janet",
"json": "JSON",
"jsx": "JSX",
"just": "Just",
"kak": "KakouneScript",
"kk": "Koka",
"kt": "Kotlin",
Expand Down Expand Up @@ -431,6 +432,8 @@ func getFileType(path string, opts *ClocOptions) (ext string, ok bool) {
}

switch strings.ToLower(base) {
case "justfile":
return "just", true
case "makefile":
return "makefile", true
case "nukefile":
Expand Down Expand Up @@ -600,6 +603,7 @@ func NewDefinedLanguages() *DefinedLanguages {
"JavaScript": NewLanguage("JavaScript", []string{"//"}, [][]string{{"/*", "*/"}}),
"Julia": NewLanguage("Julia", []string{"#"}, [][]string{{"#:=", ":=#"}}),
"Jupyter Notebook": NewLanguage("Jupyter Notebook", []string{"#"}, [][]string{{"", ""}}),
"Just": NewLanguage("Just", []string{"#"}, [][]string{{"", ""}}).WithRegexLineComments([]string{`^#[^!].*`}),
"JSON": NewLanguage("JSON", []string{}, [][]string{{"", ""}}),
"JSX": NewLanguage("JSX", []string{"//"}, [][]string{{"/*", "*/"}}),
"KakouneScript": NewLanguage("KakouneScript", []string{"#"}, [][]string{{"", ""}}),
Expand Down
9 changes: 7 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,15 @@ func getAllFiles(paths []string, languages *DefinedLanguages, opts *ClocOptions)
}

if _, ok := result[targetExt]; !ok {
result[targetExt] = NewLanguage(
definedLang := NewLanguage(
languages.Langs[targetExt].Name,
languages.Langs[targetExt].lineComments,
languages.Langs[targetExt].multiLines)
languages.Langs[targetExt].multiLines,
)
if len(languages.Langs[targetExt].regexLineComments) > 0 {
definedLang.regexLineComments = languages.Langs[targetExt].regexLineComments
}
result[targetExt] = definedLang
}
result[targetExt].Files = append(result[targetExt].Files, path)
}
Expand Down

0 comments on commit fb8f0f7

Please sign in to comment.