Skip to content

Commit

Permalink
feat: simple X++ support, empty lines incorrect
Browse files Browse the repository at this point in the history
The language definition for X++ is based on C++.

Problem: Code in XPO files is always prefixed by 8
space and one hash character. Thus, the current
implementation does not count empty lines in the
code at all. Only empty lines in the XPO structuring
elements are counted.
  • Loading branch information
wonderbird committed Jan 3, 2022
1 parent 349e282 commit 2f66ca4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
5 changes: 5 additions & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,11 @@ my @Tests = (
'ref' => '../tests/outputs/harbour_xbase.prg.yaml',
'args' => '../tests/inputs/harbour_xbase.prg',
},
{
'name' => 'X++',
'ref' => '../tests/outputs/xplusplus.xpo.yaml',
'args' => '../tests/inputs/xplusplus.xpo',
},
{
'name' => 'XML',
'ref' => '../tests/outputs/XML.xml.yaml',
Expand Down
19 changes: 12 additions & 7 deletions Unix/t/99_xpp.t
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
#!/usr/bin/env perl
#
# TODO wonderbird: Before creating the pull request, delete this file.
#
# Collection of X++ tests.
#
# These tests are used during development of the X++ language definition.
# This file makes it easy to run a subset of tests for TDDing the feature.
#
use warnings;
use strict;
use Test::More;
use Cwd;
my @Tests = (
{
'name' => 'X++',
'ref' => './tests/outputs/xplusplus.xpo.yaml', # TODO Delete this line
'args' => './tests/inputs/xplusplus.xpo', # TODO Delete this line
# 'ref' => '../tests/outputs/xplusplus.xpo.yaml', # final code # TODO Activate this line
# 'args' => '../tests/inputs/xplusplus.xpo', # final code # TODO Activate this line
'ref' => './tests/outputs/xplusplus.xpo.yaml',
'args' => './tests/inputs/xplusplus.xpo',
},
);

my $Verbose = 0;
my $Verbose = 1;

my $results = 'results.yaml';
my $work_dir = getcwd;
#my $cloc = "$work_dir/../cloc"; # all-purpose version # TODO uncomment this line
my $cloc = "$work_dir/cloc"; # Unix-tuned version # TODO comment this line
my $cloc = "$work_dir/cloc";
my $Run = "$cloc --quiet --yaml --out $results ";
foreach my $t (@Tests) {
print $Run . $t->{'args'} if $Verbose;
Expand Down
12 changes: 11 additions & 1 deletion cloc
Original file line number Diff line number Diff line change
Expand Up @@ -8303,6 +8303,7 @@ sub set_constants { # {{{1
'wsdl' => 'Web Services Description',
'x' => 'Logos' ,
'xm' => 'Logos' ,
'xpo' => 'X++' , # Microsoft Dynamics AX 4.0 export format
'xmi' => 'XMI' ,
'XMI' => 'XMI' ,
'zcml' => 'XML' ,
Expand Down Expand Up @@ -9873,6 +9874,13 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C' ],
],
'X++' => [
[ 'remove_matches', '\s*#\s*//' ],
[ 'remove_between_regex', '#\s*/\*', '\*/' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'XMI' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
Expand Down Expand Up @@ -9980,6 +9988,7 @@ sub set_constants { # {{{1
'lex' => '\\\\$' ,
'Vala' => '\\\\$' ,
'Vala Header' => '\\\\$' ,
'X++' => '\\\\$' ,
'zsh' => '\\\\$' ,
);
# 1}}}
Expand Down Expand Up @@ -10712,6 +10721,7 @@ sub set_constants { # {{{1
'xBase' => 2.00,
'xBase Header' => 2.00,
'xlisp' => 1.25,
'X++' => 1.51, # This is a guess. Copied from C++, because the overhead for C++ headers might be equivalent to the overhead of structuring elements in XPO files
'XAML' => 1.90,
'XQuery' => 2.50,
'yacc' => 1.51,
Expand Down Expand Up @@ -14674,7 +14684,7 @@ my @generic = (
from_to => [['<?_c', '_c?>']],
},

{languages => [qw /C++/, 'C#', qw /Cg ECMAScript FPL Java JavaScript/],
{languages => [qw /C++/, 'C#', 'X++', qw /Cg ECMAScript FPL Java JavaScript/],
to_eol => ['//'],
from_to => [[qw {/* */}]]},

Expand Down
18 changes: 9 additions & 9 deletions tests/outputs/xplusplus.xpo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# github.com/AlDanial/cloc
header :
cloc_url : github.com/AlDanial/cloc
cloc_version : 1.67
elapsed_seconds : 0.00519108772277832
cloc_version : 1.92
elapsed_seconds : 0.0206189155578613
n_files : 1
n_lines : 13
files_per_second : 192.63785422312
lines_per_second : 2504.29210490056
report_file : xplusplus.xpo.yaml
X++ :
n_lines : 34
files_per_second : 48.499155893712
lines_per_second : 1648.97130038621
report_file : results.yaml
'X++' :
nFiles: 1
blank: 5
comment: 0
code: 19
code: 29
SUM:
blank: 5
comment: 0
code: 19
code: 29
nFiles: 1

0 comments on commit 2f66ca4

Please sign in to comment.