Package list ohcount / ab51af5
Import upstream version 4.0.0+git20210223.6654d48, md5 812919ba7c0399b769b912e325a4fe38 Debian Janitor 6 months ago
13 changed file(s) with 214 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
0 arch:
1 - amd64
2 - ppc64le
03 language: ruby
14 install:
25 - sudo apt-get install libpcre3 libpcre3-dev libmagic-dev gperf gcc ragel swig
4949
5050 Ohcount does not support Windows.
5151
52 Ohcount targets Ruby 2.5.0. The ruby dev headers provided by Ubuntu/Fedora
53 package managers were found to be missing a *config.h* header file. Installing
54 ruby using brew/rbenv/rvm works better for compiling ohcount.
55
5652 Source Code
5753 -----------
5854
6359 Building Ohcount
6460 ----------------
6561
66 > Last updated: 2019-01-28
62 > Last updated: 2020-02-12
63
64 Ohcount targets `Ruby 2.*`. The ruby dev headers provided by Ubuntu/Fedora
65 package managers were found to be missing a `config.h` header file. If the
66 default ruby and ruby-dev packages do not work, install ruby using
67 brew/rbenv/asdf/rvm, which work reliably with ohcount.
6768
6869 You will need ragel 7.0 or higher, bash, gperf, libpcre3-dev, libmagic-dev,
6970 gcc(version 7.3 or greater) and swig (>=3.0.0).
71 For older gcc versions one could try [this fix](https://github.com/blackducksoftware/ohcount/pull/70/commits/c7511b9810a8660a8268a958fee0e365fb9af18f).
72
73 ```
74 $ git clone git://github.com/blackducksoftware/ohcount.git
75 $ cd ohcount
76 ```
77
78 For the ruby bindings, there is a dependency for the 'test-unit' gem:
79 ```
80 $ gem install test-unit
81 ```
7082
7183 #### Ubuntu/Debian
7284
89101 $ ./build
90102 ```
91103
92 For the ruby bindings, there is a dependency for the 'test-unit' gem:
104 #### Other Unix systems
93105
94 ```
95 $ gem install test-unit
96 ```
106 * If build fails with a missing `ohcount.so` error and any `ruby/x86.../` folder has the file, copy it to `ruby/` folder.
97107
98108 Using Ohcount
99109 -------------
5050 cu, LANG_CUDA
5151 cxx, LANG_CPP
5252 d, LANG_DMD
53 dart, LANG_DART
5354 dat, DISAMBIGUATE("dat")
5455 def, DISAMBIGUATE("def")
5556 di, LANG_DMD
197198 sci, LANG_SCILAB
198199 scm, LANG_SCHEME
199200 sh, LANG_SHELL
201 sld, LANG_SCHEME
200202 sls, LANG_SCHEME
201203 sps, LANG_SCHEME
202204 sql, LANG_SQL
3131 csharp, LANG_CSHARP, "C#", 0
3232 css, LANG_CSS, "CSS", 1
3333 cuda, LANG_CUDA, "CUDA", 0
34 dart, LANG_DART, "Dart", 0
3435 dcl, LANG_DCL, "DCL", 0
3536 dmd, LANG_DMD, "D", 0
3637 dtx, LANG_TEX_DTX, "DTX for TeX/LaTeX", 1
2424 #include "../parsers/css.h"
2525 #include "../parsers/d.h"
2626 #include "../parsers/dcl.h"
27 #include "../parsers/dart.h"
2728 #include "../parsers/dylan.h"
2829 #include "../parsers/ebuild.h"
2930 #include "../parsers/eiffel.h"
134135 csharp, parse_csharp
135136 css, parse_css
136137 cuda, parse_cuda
138 dart, parse_dart
137139 dcl, parse_dcl
138140 dmd, parse_d
139141 dylan, parse_dylan
3333 #define LANG_CSHARP "csharp"
3434 #define LANG_CSS "css"
3535 #define LANG_CUDA "cuda"
36 #define LANG_DART "dart"
3637 #define LANG_DCL "dcl"
3738 #define LANG_DMD "dmd"
3839 #define LANG_DYLAN "dylan"
0 /************************* Required for every parser *************************/
1 #ifndef OHCOUNT_DART_PARSER_H
2 #define OHCOUNT_DART_PARSER_H
3
4 #include "../parser_macros.h"
5
6 // the name of the language
7 const char *DART_LANG = LANG_DART;
8
9 // the languages entities
10 const char *dart_entities[] = {
11 "space", "comment", "any"
12 };
13
14 // constants associated with the entities
15 enum {
16 DART_SPACE = 0, DART_COMMENT, DART_ANY
17 };
18
19 /*****************************************************************************/
20
21 %%{
22 machine dart;
23 write data;
24 include common "common.rl";
25
26 # Line counting machine
27
28 action dart_ccallback {
29 switch(entity) {
30 case DART_SPACE:
31 ls
32 break;
33 case DART_ANY:
34 code
35 break;
36 case INTERNAL_NL:
37 std_internal_newline(DART_LANG)
38 break;
39 case NEWLINE:
40 std_newline(DART_LANG)
41 }
42 }
43
44 dart_line_comment =
45 '//' @comment (
46 escaped_newline %{ entity = INTERNAL_NL; } %dart_ccallback
47 |
48 ws
49 |
50 (nonnewline - ws) @comment
51 )*;
52 dart_block_comment =
53 '/*' @comment (
54 newline %{ entity = INTERNAL_NL; } %dart_ccallback
55 |
56 ws
57 |
58 (nonnewline - ws) @comment
59 )* :>> '*/';
60 dart_comment = dart_line_comment | dart_block_comment;
61
62 dart_line := |*
63 spaces ${ entity = DART_SPACE; } => dart_ccallback;
64 dart_comment;
65 newline ${ entity = NEWLINE; } => dart_ccallback;
66 ^space ${ entity = DART_ANY; } => dart_ccallback;
67 *|;
68
69 # Entity machine
70 # TODO: This is a placeholder and most entities are missing.
71
72 action dart_ecallback {
73 callback(DART_LANG, dart_entities[entity], cint(ts), cint(te), userdata);
74 }
75
76 dart_line_comment_entity = '//' (escaped_newline | nonnewline)*;
77 dart_block_comment_entity = '/*' any* :>> '*/';
78 dart_comment_entity = dart_line_comment_entity | dart_block_comment_entity;
79
80 dart_entity := |*
81 space+ ${ entity = DART_SPACE; } => dart_ecallback;
82 dart_comment_entity ${ entity = DART_COMMENT; } => dart_ecallback;
83 ^space;
84 *|;
85 }%%
86
87 /************************* Required for every parser *************************/
88
89 /* Parses a string buffer with Dart code.
90 *
91 * @param *buffer The string to parse.
92 * @param length The length of the string to parse.
93 * @param count Integer flag specifying whether or not to count lines. If yes,
94 * uses the Ragel machine optimized for counting. Otherwise uses the Ragel
95 * machine optimized for returning entity positions.
96 * @param *callback Callback function. If count is set, callback is called for
97 * every line of code, comment, or blank with 'lcode', 'lcomment', and
98 * 'lblank' respectively. Otherwise callback is called for each entity found.
99 */
100 void parse_dart(char *buffer, int length, int count,
101 void (*callback) (const char *lang, const char *entity, int s,
102 int e, void *udata),
103 void *userdata
104 ) {
105 init
106
107 %% write init;
108 cs = (count) ? dart_en_dart_line : dart_en_dart_entity;
109 %% write exec;
110
111 // if no newline at EOF; callback contents of last line
112 if (count) { process_last_line(DART_LANG) }
113 }
114
115 #endif
116
117 /*****************************************************************************/
0 // Example Dart code
1 void main() {
2 print("Hello, World!");
3 }
0 dart code void main() {
1 dart comment // Line comment
2 dart blank
3 dart comment /* Block
4 dart comment comment */
5 dart blank
6 dart code print("Hello!"); // Code with line comment
7 dart code print("World!"); /* Code with block comment */
8 dart code }
0 void main() {
1 // Line comment
2
3 /* Block
4 comment */
5
6 print("Hello!"); // Code with line comment
7 print("World!"); /* Code with block comment */
8 }
220220 ASSERT_DETECT(LANG_BFPP, "foo.bfpp");
221221 }
222222
223 void test_detector_dart() {
224 ASSERT_DETECT(LANG_DART, "foo.dart");
225 }
226
223227 void test_detector_emacs_mode() {
224228 ASSERT_DETECT(LANG_C, "emacs_mode_c");
225229 }
271275 test_detector_basic();
272276 test_detector_xml_with_custom_extension();
273277 test_detector_brainfuck();
278 test_detector_dart();
274279 test_detector_emacs_mode();
275280 test_detector_emacs_with_extension();
276281 test_detector_puppet();
9797 #include "parsers/test_csharp.h"
9898 #include "parsers/test_css.h"
9999 #include "parsers/test_d.h"
100 #include "parsers/test_dart.h"
100101 #include "parsers/test_dcl.h"
101102 #include "parsers/test_dylan.h"
102103 #include "parsers/test_ebuild.h"
287288 all_cs_aspx_tests();
288289 all_csharp_tests();
289290 all_css_tests();
291 all_dart_tests();
290292 all_dmd_tests();
291293 all_dcl_tests();
292294 all_dylan_tests();
0
1 void test_dart_comments() {
2 test_parser_verify_parse(
3 test_parser_sourcefile("dart", " //comment"),
4 "dart", "", "//comment", 0
5 );
6 }
7
8 void test_dart_empty_comments() {
9 test_parser_verify_parse(
10 test_parser_sourcefile("dart", " //\n"),
11 "dart", "", "//\n", 0
12 );
13 }
14
15 void test_dart_block_comment() {
16 test_parser_verify_parse(
17 test_parser_sourcefile("dart", "/*comment*/"),
18 "dart", "", "/*comment*/", 0
19 );
20 }
21
22 void test_dart_comment_entities() {
23 test_parser_verify_entity(
24 test_parser_sourcefile("dart", " //comment"),
25 "comment", "//comment"
26 );
27 test_parser_verify_entity(
28 test_parser_sourcefile("c", " /*comment*/"),
29 "comment", "/*comment*/"
30 );
31 }
32
33 void all_dart_tests() {
34 test_dart_comments();
35 test_dart_empty_comments();
36 test_dart_block_comment();
37 test_dart_comment_entities();
38 }