Skip to content

Commit

Permalink
add support for Yang, #836
Browse files Browse the repository at this point in the history
also some clean-ups; no longer need negative values for --fmt
  • Loading branch information
AlDanial committed Jun 14, 2024
1 parent 64005f3 commit fe41615
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 37 deletions.
39 changes: 21 additions & 18 deletions Unix/cloc
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,8 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
printed with
perl -MEncode -e 'print join(\"\\n\", Encode->encodings(\":all\")), \"\\n\"'
--fmt=<N> Alternate text output format where <N> is a number
from 1 to 5, or -1 to -5. 'total lines' means the
sum of code, comment, and blank lines. Negative
values are the same as the positive values but retain,
instead of deleting, the intermediate JSON file that
is written. The JSON file name is randomly generated
unless --out/--report-file is given. The formats are:
from 1 to 5. 'total lines' means the sum of code,
comment, and blank lines. The formats are:
1: by language (same as cloc default output)
2: by language with an extra column for total lines
3: by file with language
Expand Down Expand Up @@ -9171,6 +9167,7 @@ sub set_constants { # {{{1
'clang-format'=> 'YAML' ,
'yaml' => 'YAML' ,
'yml' => 'YAML' ,
'yang' => 'Yang' ,
'zig' => 'Zig' ,
'zsh' => 'zsh' ,
);
Expand Down Expand Up @@ -10011,6 +10008,7 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'lex' => [ [ 'call_regexp_common' , 'C' ], ],
'LFE' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_between_general', '#|', '|#' ],
Expand Down Expand Up @@ -10720,6 +10718,14 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Velocity Template Language' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*##' ],
[ 'remove_between_general', '#**', '*#' ],
[ 'add_newlines' , ],
],
'Verilog-SystemVerilog/Coq' => [ ['die'] ], # never called
'Verilog-SystemVerilog' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
Expand Down Expand Up @@ -10765,13 +10771,15 @@ sub set_constants { # {{{1
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Velocity Template Language' => [
'Visual Studio Module' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Visual Studio Solution' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*##' ],
[ 'remove_between_general', '#**', '*#' ],
[ 'add_newlines' , ],
],
'Vuejs Component' => [
[ 'remove_html_comments', ],
Expand Down Expand Up @@ -10800,7 +10808,6 @@ sub set_constants { # {{{1
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'lex' => [ [ 'call_regexp_common' , 'C' ], ],
'XAML' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'xBase Header' => [
Expand Down Expand Up @@ -10915,16 +10922,11 @@ sub set_constants { # {{{1
[ 'call_regexp_common' , 'HTML' ], ],
'MSBuild script' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'Visual Studio Module' => [
'Yang' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Visual Studio Solution' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Zig' => [
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
Expand Down Expand Up @@ -11510,6 +11512,7 @@ sub set_constants { # {{{1
'Luau' => 4.50,
'OpenCL' => 1.50,
'Xtend' => 2.00,
'Yang' => 3.00,
'Zig' => 2.50,
# aggregates; value is meaningless
'C#/Smalltalk' => 1.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 @@ -1366,6 +1366,11 @@ my @Tests = (
'ref' => '../tests/outputs/Xtend.xtend.yaml',
'args' => '../tests/inputs/Xtend.xtend',
},
{
'name' => 'Yang',
'ref' => '../tests/outputs/bbf-device.yang.yaml',
'args' => '../tests/inputs/bbf-device.yang',
},
{
'name' => 'Zig',
'ref' => '../tests/outputs/zir_sema.zig.yaml',
Expand Down
41 changes: 22 additions & 19 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -641,12 +641,8 @@ Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <repo
printed with
perl -MEncode -e 'print join(\"\\n\", Encode->encodings(\":all\")), \"\\n\"'
--fmt=<N> Alternate text output format where <N> is a number
from 1 to 5, or -1 to -5. 'total lines' means the
sum of code, comment, and blank lines. Negative
values are the same as the positive values but retain,
instead of deleting, the intermediate JSON file that
is written. The JSON file name is randomly generated
unless --out/--report-file is given. The formats are:
from 1 to 5. 'total lines' means the sum of code,
comment, and blank lines. The formats are:
1: by language (same as cloc default output)
2: by language with an extra column for total lines
3: by file with language
Expand Down Expand Up @@ -6847,7 +6843,7 @@ sub write_file { # {{{1
$OUT->close;

if (can_read($file)) {
print "Wrote $file" unless $opt_quiet or $opt_fmt > 0;
print "Wrote $file" unless $opt_quiet;
print ", $CLOC_XSL" if $opt_xsl and $opt_xsl eq $CLOC_XSL;
print "\n" unless $opt_quiet;
}
Expand Down Expand Up @@ -9186,6 +9182,7 @@ sub set_constants { # {{{1
'clang-format'=> 'YAML' ,
'yaml' => 'YAML' ,
'yml' => 'YAML' ,
'yang' => 'Yang' ,
'zig' => 'Zig' ,
'zsh' => 'zsh' ,
);
Expand Down Expand Up @@ -10026,6 +10023,7 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'lex' => [ [ 'call_regexp_common' , 'C' ], ],
'LFE' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_between_general', '#|', '|#' ],
Expand Down Expand Up @@ -10735,6 +10733,14 @@ sub set_constants { # {{{1
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Velocity Template Language' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*##' ],
[ 'remove_between_general', '#**', '*#' ],
[ 'add_newlines' , ],
],
'Verilog-SystemVerilog/Coq' => [ ['die'] ], # never called
'Verilog-SystemVerilog' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
Expand Down Expand Up @@ -10780,13 +10786,15 @@ sub set_constants { # {{{1
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Velocity Template Language' => [
'Visual Studio Module' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Visual Studio Solution' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*##' ],
[ 'remove_between_general', '#**', '*#' ],
[ 'add_newlines' , ],
],
'Vuejs Component' => [
[ 'remove_html_comments', ],
Expand Down Expand Up @@ -10815,7 +10823,6 @@ sub set_constants { # {{{1
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'lex' => [ [ 'call_regexp_common' , 'C' ], ],
'XAML' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'xBase Header' => [
Expand Down Expand Up @@ -10930,16 +10937,11 @@ sub set_constants { # {{{1
[ 'call_regexp_common' , 'HTML' ], ],
'MSBuild script' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'Visual Studio Module' => [
'Yang' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Visual Studio Solution' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Zig' => [
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
Expand Down Expand Up @@ -11525,6 +11527,7 @@ sub set_constants { # {{{1
'Luau' => 4.50,
'OpenCL' => 1.50,
'Xtend' => 2.00,
'Yang' => 3.00,
'Zig' => 2.50,
# aggregates; value is meaningless
'C#/Smalltalk' => 1.00,
Expand Down
104 changes: 104 additions & 0 deletions tests/inputs/bbf-device.yang
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// fragment of
// https://github.com/BroadbandForum/yang/raw/eaac2c3904365d3c7b17100c7d5120ed06a56b74/standard/common/bbf-device.yang
module bbf-device {
yang-version 1.1;
namespace "urn:bbf:yang:bbf-device";
prefix bbf-dvc;

import ietf-yang-types {
prefix yang;
}
import ietf-inet-types {
prefix inet;
}
import bbf-yang-types {
prefix bbf-yang;
}
import bbf-device-types {
prefix bbf-dvct;
}
import bbf-node-types {
prefix bbf-nodet;
}

organization
"Broadband Forum <https://www.broadband-forum.org>
Common YANG Work Area";
contact
"Comments or questions about this Broadband Forum YANG module
should be directed to <mailto:[email protected]>.
Editor: Nick Hancock, ADTRAN
Editor: Ludwig Pauwels, Nokia
PS Leader: Joey Boyd, ADTRAN
WA Director: Joey Boyd, ADTRAN
WA Director: Sven Ooghe, Nokia";

description
"This module contains a collection of YANG definitions for
supporting the Broadband Forum requirements on managing physical
devices.";

revision 2022-03-01 {
description
"Amendment 5.
* Approval Date: 2022-03-01.
* Publication Date: 2022-03-01.";
reference
"TR-383a5: Common YANG Modules
<https://www.broadband-forum.org/technical/download/
TR-383_Amendment-5.pdf>";
}

// Features

feature reports-device-powering-state {
description
"Indicates the support for reporting the device powering
state.";
}

// Device Properties

grouping device-alias {
description
"Alias information for the device.";
leaf alias {
type bbf-yang:string-ascii64;
description
"The alias that can be used to identify a device.";
}
}

// Device hardware information


// Device Management Information

grouping device-management-info {
description
"Data nodes relating to management plane information needed to
reach and communicate with the device.";
leaf ip-address {
type inet:host;
description
"The IP address or DNS domain name of the device.";
}
leaf port {
type inet:port-number;
description
"The port number used on the device for
management.";
}
leaf admin-state {
type bbf-nodet:admin-state;
description
"The administrative state of the device.";
}
}

}
21 changes: 21 additions & 0 deletions tests/outputs/bbf-device.yang.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.01
elapsed_seconds : 0.0034480094909668
n_files : 1
n_lines : 104
files_per_second : 290.022403540313
lines_per_second : 30162.3299681925
report_file : ../outputs/bbf-device.yang.yaml
'Yang' :
nFiles: 1
blank: 18
comment: 6
code: 80
SUM:
blank: 18
comment: 6
code: 80
nFiles: 1

0 comments on commit fe41615

Please sign in to comment.