Skip to content

Commit

Permalink
add support for Pawn, #843
Browse files Browse the repository at this point in the history
  • Loading branch information
AlDanial committed Jul 14, 2024
1 parent 9b97b60 commit eb48081
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 32 deletions.
94 changes: 78 additions & 16 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -1267,9 +1267,10 @@ my %Extension_Collision = (
'Lisp/Julia' => [ 'jl' ] ,
'Lisp/OpenCL' => [ 'cl' ] ,
'MATLAB/Mathematica/Objective-C/MUMPS/Mercury' => [ 'm' ] ,
'Pascal/Pawn' => [ 'p' ] ,
'Pascal/Puppet' => [ 'pp' ] ,
'Perl/Prolog' => [ 'pl', 'PL' ] ,
'PHP/Pascal/Fortran' => [ 'inc' ] ,
'PHP/Pascal/Fortran/Pawn' => [ 'inc' ] ,
'Raku/Prolog' => [ 'p6', 'P6' ] ,
'Qt/Glade' => [ 'ui' ] ,
'TypeScript/Qt Linguist' => [ 'ts' ] ,
Expand Down Expand Up @@ -6277,17 +6278,17 @@ sub classify_file { # {{{1
'failure in matlab_or_objective_C($full_file)';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'PHP/Pascal/Fortran') {
} elsif ($Language_by_Extension{$extension} eq 'PHP/Pascal/Fortran/Pawn') {
my $lang_F_or_P_or_P = "";
php_pascal_or_fortran($full_file ,
$rh_Err ,
$raa_errors,
\$lang_F_or_P_or_P);
php_pascal_fortran_pawn($full_file ,
$rh_Err ,
$raa_errors,
\$lang_F_or_P_or_P);
if ($lang_F_or_P_or_P) {
return $lang_F_or_P_or_P;
} else { # an error happened in php_pascal_or_fortran()
$rh_ignored->{$full_file} =
'failure in php_pascal_or_fortran($full_file)';
'failure in php_pascal_fortran_pawn($full_file)';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Puppet') {
Expand Down Expand Up @@ -6389,6 +6390,9 @@ sub classify_file { # {{{1
'failure in Visual_Basic_or_TeX_or_Apex()';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Pawn') {
my $lang_p_or_p = "";
return Pascal_or_Pawn($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Brainfuck') {
if (really_is_bf($full_file)) {
return $Language_by_Extension{$extension};
Expand Down Expand Up @@ -8535,7 +8539,7 @@ sub set_constants { # {{{1
'ig' => 'Modula3' ,
'il' => 'SKILL' ,
'ils' => 'SKILL++' ,
'inc' => 'PHP/Pascal/Fortran' ,
'inc' => 'PHP/Pascal/Fortran/Pawn',
'ino' => 'Arduino Sketch' ,
'ipf' => 'Igor Pro' ,
#'pde' => 'Arduino Sketch' , # pre 1.0
Expand Down Expand Up @@ -8701,6 +8705,7 @@ sub set_constants { # {{{1
'fnc' => 'Oracle PL/SQL' ,
'prc' => 'Oracle PL/SQL' ,
'trg' => 'Oracle PL/SQL' ,
'p' => 'Pascal/Pawn' ,
'pad' => 'Ada' , # Oracle Ada preprocessor
'page' => 'Visualforce Page' ,
'pas' => 'Pascal' ,
Expand Down Expand Up @@ -8744,7 +8749,6 @@ sub set_constants { # {{{1
'yap' => 'Prolog' ,
'prolog' => 'Prolog' ,
'P' => 'Prolog' ,
'p' => 'Pascal' ,
'pp' => 'Pascal/Puppet' ,
'viw' => 'SQL' ,
'udf' => 'SQL' ,
Expand Down Expand Up @@ -8842,6 +8846,8 @@ sub set_constants { # {{{1
'sp' => 'SparForte' ,
'sol' => 'Solidity' ,
'p4' => 'P4' ,
'pwn' => 'Pawn' ,
'pawn' => 'Pawn' ,
'ses' => 'Patran Command Language' ,
'pcl' => 'Patran Command Language' ,
'peg' => 'PEG' ,
Expand Down Expand Up @@ -10139,7 +10145,7 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'PHP/Pascal/Fortran' => [ [ 'die' , ], ], # never called
'PHP/Pascal/Fortran/Pawn' => [ [ 'die' , ], ], # never called
'Mako' => [
[ 'remove_matches' , '##.*$' ],
],
Expand Down Expand Up @@ -10213,6 +10219,11 @@ 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*\$#' ],
Expand Down Expand Up @@ -11342,6 +11353,7 @@ sub set_constants { # {{{1
'Oracle Developer/2000' => 3.48,
'Other' => 1.00,
'P4' => 1.5 ,
'Pawn' => 2.00,
'Pascal' => 0.88,
'Patran Command Language' => 2.50,
'Perl' => 4.00,
Expand Down Expand Up @@ -11521,7 +11533,7 @@ sub set_constants { # {{{1
'Fortran 77/Forth' => 1.00,
'Lisp/Julia' => 1.00,
'Lisp/OpenCL' => 1.00,
'PHP/Pascal/Fortran' => 1.00,
'PHP/Pascal/Fortran/Pawn' => 1.00,
'Pascal/Puppet' => 1.00,
'Perl/Prolog' => 1.00,
'Raku/Prolog' => 1.00,
Expand Down Expand Up @@ -11763,8 +11775,8 @@ printf "END LOOP obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $obje
if $opt_v > 2;

} # 1}}}
sub php_pascal_or_fortran { # {{{1
# Decide if code is Fortran, PHP, or Pascal
sub php_pascal_fortran_pawn { # {{{1
# Decide if code is Fortran, PHP, Pascal, Pawn
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
Expand All @@ -11786,6 +11798,11 @@ sub php_pascal_or_fortran { # {{{1
# Pascal:
# lines ending with ;
# writeln
#
# Pawn:
# lines ending with ;
# has /* ... */ style comments
# writeln

${$rs_language} = "";
my $IN = open_file('<', $file, 1);
Expand All @@ -11800,6 +11817,7 @@ sub php_pascal_or_fortran { # {{{1
my $fortran_points = 0;
my $php_points = 0;
my $pascal_points = 0;
my $pawn_points = 0;
while (<$IN>) {
if (/^\s*<\?php/i) {
$php_points += 100;
Expand All @@ -11822,13 +11840,16 @@ sub php_pascal_or_fortran { # {{{1
/^\s*end\s+(program|subroutine)/i or
/^\s*end\s*(if|do)\b/i) {
++$fortran_points;
} elsif (/^\s*(writeln|begin|procedure|interface|implementation|const|var)\b/i) {
} elsif (/^\s*(writeln|begin|procedure|interface|implementation|const)\b/i) {
++$pascal_points;
} elsif (/^\s*(<|\?>)/) {
++$php_points;
} elsif (/;\s*$/) {
++$pascal_points;
++$php_points;
} elsif (/^\@/ or /^\s*(Float:|bool:)/) {
$pawn_points += 1e+20;
last;
}
if (/^\s*(integer|real|complex|double|character|logical|public|private).*?::/i or
/^\s*(allocatable|dimension)/i or
Expand All @@ -11840,7 +11861,8 @@ sub php_pascal_or_fortran { # {{{1

my %points = ( 'Fortran' => $fortran_points ,
'PHP' => $php_points ,
'Pascal' => $pascal_points , );
'Pascal' => $pascal_points ,
'Pawn' => $pawn_points , );

${$rs_language} = (sort { $points{$b} <=> $points{$a} or $a cmp $b } keys %points)[0];
if (${$rs_language} eq 'Fortran') {
Expand All @@ -11851,7 +11873,8 @@ sub php_pascal_or_fortran { # {{{1
}
}

print "<- php_pascal_or_fortran($file: fortran=$fortran_points, php=$php_points, pascal=$pascal_points) => ${$rs_language}\n"
print "<- php_pascal_fortran_pawn($file: fortran=$fortran_points, php=$php_points, ",
"pascal=$pascal_points, pawn=$pawn_points) => ${$rs_language}\n"
if $opt_v > 2;

} # 1}}}
Expand Down Expand Up @@ -12454,6 +12477,45 @@ sub Scheme_or_SaltStack { # {{{1
return "SaltStack";
}
} # 1}}}
sub Pascal_or_Pawn { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;

print "-> Pascal_or_Pawn($file)\n" if $opt_v > 2;

my $lang = undef;
my $IN = open_file('<', $file, 1);
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $scal = 0;
my $wn = 0;
while (<$IN>) {
next if /^\s*$/;
if (/^\s*(program|begin|end|[Ww]riteln|procedure)\s/) {
$scal += 1e+20;
last;
} elsif (/^\@/ or m{/\*} or m{\*/} or /^\s*(Float:|bool:)/) {
$wn += 1e+20;
last;
} elsif (/^\s*(static|printf?|switch)\s/) {
$wn += 1;
} elsif (/;\s*$/) {
$scal += 1;
}
}
$IN->close;

print "<- Pascal_or_Pawn($file: Pascal=$scal, Pawn=$wn\n" if $opt_v > 2;
if ($scal > $wn) {
return "Pascal";
} else {
return "Pawn";
}
} # 1}}}
sub html_colored_text { # {{{1
# http://www.pagetutor.com/pagetutor/makapage/pics/net216-2.gif
my ($color, $text) = @_;
Expand Down
10 changes: 10 additions & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,16 @@ my @Tests = (
'ref' => '../tests/outputs/basic.p4.yaml',
'args' => '../tests/inputs/basic.p4',
},
{
'name' => 'Pawn',
'ref' => '../tests/outputs/pawn.yaml',
'args' => '../tests/inputs/fortran.inc ' .
'../tests/inputs/hanoi.inc ' .
'../tests/inputs/pascal.inc ' .
'../tests/inputs/test1.inc ' .
'../tests/inputs/Pascal.p ' .
'../tests/inputs/queue.p ',
},
{
'name' => 'Pascal',
'ref' => '../tests/outputs/Pascal.pas.yaml',
Expand Down
Loading

0 comments on commit eb48081

Please sign in to comment.