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.63k stars 1.02k forks source link

Request for language support, four variants: PEG, peg.js, peggy, tspeg #661

Closed StoneCypher closed 2 years ago

StoneCypher commented 2 years ago

Main language

Expression
  = head:Term tail:(_ ("+" / "-") _ Term)* {
      return tail.reduce(function(result, element) {
        if (element[1] === "+") { return result + element[3]; }
        if (element[1] === "-") { return result - element[3]; }
      }, head);
    }

Term
  = head:Factor tail:(_ ("*" / "/") _ Factor)* {
      return tail.reduce(function(result, element) {
        if (element[1] === "*") { return result * element[3]; }
        if (element[1] === "/") { return result / element[3]; }
      }, head);
    }

Factor
  = "(" _ expr:Expression _ ")" { return expr; }
  / Integer

Integer "integer"
  = _ [0-9]+ { return parseInt(text(), 10); }

_ "whitespace"
  = [ \t\n\r]*

Variant language 1

Variant language 2

Variant language 3

AlDanial commented 2 years ago

Please give 04dcf36 a quick try before I release 1.94.

StoneCypher commented 2 years ago

The four languages I'm involved with look good to me

Really surprising to see perl there - I thought this was written in perl?

StoneCypher commented 2 years ago

Notably, the part of the SDP parser you took, while valid, isn't normative PEG; the "normal" part is in the cut off part past the truncation

If you want a short example you're probably better off with the arithmetic example from this issue

StoneCypher commented 2 years ago

The part in the actual code examples is fine though

StoneCypher commented 2 years ago

As far as giving it a try, I don't actually know how to install CLOC without using the npm wrapper I've been using

Do I pop it from CPAN? If so, how, please? I'm not a perl person

AlDanial commented 2 years ago

To run cloc using its Perl source code on Windows instead of the .exe, you'll need to install a Perl interpreter for Windows. I use Strawberry Perl. Then you can do, for example, C:> perl cloc my_source_dir

Regarding the SDP parser fragments I copied for testing, the stuff I extracted doesn't need to be real PEG code, just something representative of what PEG might look like.

StoneCypher commented 2 years ago

Appears to work

StoneCypher commented 2 years ago

Confirmed working in my stack. Thank you

image