Skip to content

Commit

Permalink
add support for Pkl, #877
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed Dec 26, 2024
1 parent a880db2 commit fce9df6
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 24 deletions.
29 changes: 17 additions & 12 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -9229,15 +9229,16 @@ sub set_constants { # {{{1
'sp' => 'SparForte' ,
'sol' => 'Solidity' ,
'p4' => 'P4' ,
'pwn' => 'Pawn' ,
'pawn' => 'Pawn' ,
'ses' => 'Patran Command Language' ,
'pcl' => 'Patran Command Language' ,
'pwn' => 'Pawn' ,
'pawn' => 'Pawn' ,
'pek' => 'Pek' ,
'peg' => 'PEG' ,
'pegjs' => 'peg.js' ,
'peggy' => 'peggy' ,
'pest' => 'Pest' ,
'pkl' => 'Pkl' ,
'prisma' => 'Prisma Schema' ,
'tspeg' => 'tspeg' ,
'jspeg' => 'tspeg' ,
Expand Down Expand Up @@ -10611,16 +10612,16 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Pawn' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Patran Command Language'=> [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_matches' , '^\s*\$#' ],
[ 'call_regexp_common' , 'C' ],
],
'Pawn' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Perl' => [ [ 'remove_below' , '^__(END|DATA)__'],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_below_above' , '^=head1', '^=cut' ],
Expand Down Expand Up @@ -10650,6 +10651,14 @@ sub set_constants { # {{{1
[ 'remove_inline' , '//.*$' ],
],
'Perl/Prolog' => [ [ 'die' , ], ], # never called
'Pig Latin' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
[ 'call_regexp_common' , 'C' ],
],
'Pkl' => [
[ 'call_regexp_common' , 'C++' ],
],
'PL/I' => [
[ 'call_regexp_common' , 'C' ],
],
Expand All @@ -10660,11 +10669,6 @@ sub set_constants { # {{{1
[ 'remove_between_general', "/'", "'/" ],
[ 'remove_matches' , "^\\s*'" ],
],
'Pig Latin' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
[ 'call_regexp_common' , 'C' ],
],
'Prisma Schema' => [
[ 'remove_matches' , '^\s*//' ],
],
Expand Down Expand Up @@ -11768,6 +11772,7 @@ sub set_constants { # {{{1
'Pest' => 2.00,
'tspeg' => 3.00,
'Pig Latin' => 1.00,
'Pkl' => 3.00,
'PL/I' => 1.38,
'PL/M' => 1.13,
'PlantUML' => 2.00,
Expand Down
5 changes: 5 additions & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ my @Tests = (
'ref' => '../tests/outputs/script1-hadoop.pig.yaml',
'args' => '../tests/inputs/script1-hadoop.pig',
},
{
'name' => 'Pkl',
'ref' => '../tests/outputs/fib_class.pkl.yaml',
'args' => '../tests/inputs/fib_class.pkl',
},
{
'name' => 'PL/I',
'ref' => '../tests/outputs/hello.pl1.yaml',
Expand Down
29 changes: 17 additions & 12 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -9219,15 +9219,16 @@ sub set_constants { # {{{1
'sp' => 'SparForte' ,
'sol' => 'Solidity' ,
'p4' => 'P4' ,
'pwn' => 'Pawn' ,
'pawn' => 'Pawn' ,
'ses' => 'Patran Command Language' ,
'pcl' => 'Patran Command Language' ,
'pwn' => 'Pawn' ,
'pawn' => 'Pawn' ,
'pek' => 'Pek' ,
'peg' => 'PEG' ,
'pegjs' => 'peg.js' ,
'peggy' => 'peggy' ,
'pest' => 'Pest' ,
'pkl' => 'Pkl' ,
'prisma' => 'Prisma Schema' ,
'tspeg' => 'tspeg' ,
'jspeg' => 'tspeg' ,
Expand Down Expand Up @@ -10601,16 +10602,16 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Pawn' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Patran Command Language'=> [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_matches' , '^\s*\$#' ],
[ 'call_regexp_common' , 'C' ],
],
'Pawn' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Perl' => [ [ 'remove_below' , '^__(END|DATA)__'],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_below_above' , '^=head1', '^=cut' ],
Expand Down Expand Up @@ -10640,6 +10641,14 @@ sub set_constants { # {{{1
[ 'remove_inline' , '//.*$' ],
],
'Perl/Prolog' => [ [ 'die' , ], ], # never called
'Pig Latin' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
[ 'call_regexp_common' , 'C' ],
],
'Pkl' => [
[ 'call_regexp_common' , 'C++' ],
],
'PL/I' => [
[ 'call_regexp_common' , 'C' ],
],
Expand All @@ -10650,11 +10659,6 @@ sub set_constants { # {{{1
[ 'remove_between_general', "/'", "'/" ],
[ 'remove_matches' , "^\\s*'" ],
],
'Pig Latin' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
[ 'call_regexp_common' , 'C' ],
],
'Prisma Schema' => [
[ 'remove_matches' , '^\s*//' ],
],
Expand Down Expand Up @@ -11758,6 +11762,7 @@ sub set_constants { # {{{1
'Pest' => 2.00,
'tspeg' => 3.00,
'Pig Latin' => 1.00,
'Pkl' => 3.00,
'PL/I' => 1.38,
'PL/M' => 1.13,
'PlantUML' => 2.00,
Expand Down
25 changes: 25 additions & 0 deletions tests/inputs/fib_class.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
https://raw.githubusercontent.com/apple/pkl/refs/heads/main/bench/src/jmh/resources/org/pkl/core/fib_class.pkl
*/

//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

class Fibonacci {
function fib(n) = if (n < 2) n else fib(n - 1) + fib(n - 2)
}
result = new Fibonacci {}.fib(35)
21 changes: 21 additions & 0 deletions tests/outputs/fib_class.pkl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 2.03
elapsed_seconds : 0.00434088706970215
n_files : 1
n_lines : 25
files_per_second : 230.367660789806
lines_per_second : 5759.19151974515
report_file : ../outputs/fib_class.pkl.yaml
'Pkl' :
nFiles: 1
blank: 3
comment: 18
code: 4
SUM:
blank: 3
comment: 18
code: 4
nFiles: 1

0 comments on commit fce9df6

Please sign in to comment.