AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.75k stars 1.02k forks source link

Add language support for Typst #746

Closed TheLukeGuy closed 1 year ago

TheLukeGuy commented 1 year ago

This is a request for language support for Typst.

Thanks! :)

LingkKang commented 1 year ago

I just thought about it last night!

But I found that typ is not an exclusive extension for Typst. GitHub Linguist have some discussion on it: https://github.com/github-linguist/linguist/issues/6358#issuecomment-1493706282 and they finally use some pattern matching like pattern: '^#(import|show|let|set)' to tell the file type.

I'm not sure is this applicable to cloc.

LingkKang commented 1 year ago

As a temporary workaround, put the following cloc definition under a text file such as typst-def.txt

Typst
    filter rm_comments_in_strings " /* */
    filter rm_comments_in_strings " // 
    filter call_regexp_common C++
    extension typ
    3rd_gen_scale 1.00

And instruct cloc to recognise Typst locally:

cloc --read-lang-def=typst-def.txt .

The result should be fine with Typst.