cgag / loc

Count lines of code quickly.
MIT License
2.31k stars 126 forks source link

Incorrect counts when multi-line pattern has the single-line pattern as a prefix. #25

Closed jswrenn closed 7 years ago

jswrenn commented 7 years ago

For example, broken.lua:

--[[ This
     is
     a
     multi-line
     comment,
     not
     code. ]]

Expected output:

---------------------------------------------------------------------------------
 Language              Files        Lines        Blank      Comment         Code
---------------------------------------------------------------------------------
 Lua                       1            7            0            7           0

Actual output:

---------------------------------------------------------------------------------
 Language              Files        Lines        Blank      Comment         Code
---------------------------------------------------------------------------------
 Lua                       1            7            0            1            6

This occurs because the opening character sequence of a multi-line comment has the character sequence of a single-line comment as its prefix:

    Lua => SM("--", "--[[", "]]"),

I ran into this bug while adding the comment patterns for a language which uses # for single-line comments, and #| and |# for multi-line comments.

cgag commented 7 years ago

Oh, very interesting. Good catch. I may have to rethink some things.