Skip to content

Commit 09372e1

Browse files
authored
Merge pull request #963 from aubertc/master
Adding documentation on how to implement your own language
2 parents 00ff5f1 + e70d159 commit 09372e1

1 file changed

Lines changed: 74 additions & 3 deletions

File tree

README.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ at http://cloc.sourceforge.net/ since August 2006.
4747
* [Java Programmatic Interface](#java-programmatic-interface-)
4848
* [Complex regular subexpression recursion limit ](#complex-regular-subexpression-recursion-limit-)
4949
* [Limitations](#limitations-)
50-
* [Requesting Support for Additional Languages](#requesting-support-for-additional-languages-)
50+
* [Support for Additional Languages](#support-for-additional-languages-)
5151
* [Reporting Problems](#reporting-problems-)
5252
* [Citation](#citation-)
5353
* [Acknowledgments](#acknowledgments-)
@@ -3111,10 +3111,81 @@ comments rather than code.
31113111

31123112
[](1}}})
31133113
<a name="AdditionalLanguages"></a> []({{{1)
3114-
# [Requesting Support for Additional Languages &#9650;](#___top "click to go to top of document")
3114+
# [Support for Additional Languages &#9650;](#___top "click to go to top of document")
31153115

31163116
If cloc does not recognize a language you are interested in counting,
3117-
create a [GitHub issue](https://github.com/AlDanial/cloc/issues)
3117+
you can either
3118+
3119+
1. [implement it yourself](#implement-it-yourself),
3120+
2. [request it to be implemented](#request-to-implement).
3121+
3122+
<a name="implement-it-yourself"></a> []({{{1)
3123+
## Implement an Additional Language
3124+
3125+
In short, you will need to:
3126+
3127+
- edit the `cloc` file:
3128+
3129+
- look for `%{$rh_Language_by_Extension} = ( # {{{1` and add, respecting the alphabetical order,
3130+
3131+
```
3132+
'<ext>' => '<Language Name>' ,
3133+
```
3134+
3135+
where `<ext>` is the extension used by your language, and `<Language Name>` is its name. Repeat for each extension used by your language.
3136+
3137+
- look for `%{$rhaa_Filters_by_Language} = ( # {{{1`, and add, respecting the alphabetical order,
3138+
3139+
```
3140+
'<Language Name>' => [
3141+
<list>
3142+
],
3143+
```
3144+
3145+
where `<Language Name>` is the name of the language you are implementing, and `<list>` is a list of filter options (whose documentation remains to be written -- take inspiration from existing languages).
3146+
3147+
- look for `%{$rh_Scale_Factor} = ( # {{{1`, and add, respecting the alphabetical order,
3148+
3149+
```
3150+
'<Language Name>' => <factor>,
3151+
```
3152+
3153+
where `<Language Name>` is the name of the language you are implementing, and `<factor>` is a [third generation language scale factor](#third-generation-language-scale-factors-).
3154+
3155+
- edit the `Readme.md` file, adding under ["Recognized Languages"](#recognized-languages-)
3156+
3157+
```
3158+
<Language Name> (<list of extensions>)
3159+
```
3160+
3161+
for `<Language Name>` the name of the language you are implementing, and `<list of extensions>` the list of extensions you declared in `rh_Language_by_Extension`.
3162+
3163+
- (optional, but recommended) Add a test case:
3164+
3165+
- Create a `tests/inputs/<Language name>.<extension>` file, containing some code written in `<Language name>`,
3166+
- Generate a `‎tests/outputs/<Language name>.<extension>.yaml` file, using
3167+
3168+
```
3169+
cloc --yaml tests/inputs/<Language name>.<extension> --out ‎tests/outputs/<Language name>.<extension>.yaml
3170+
```
3171+
- Add your case in `Unix/t/00_C.t`: under `my @Tests = (`, add
3172+
3173+
```
3174+
{
3175+
'name' => '<Language name>',
3176+
'ref' => '../tests/outputs/<Language name>.<extension>.yaml',
3177+
'args' => '../tests/inputs/<Language name>.<extension>',
3178+
},
3179+
```
3180+
3181+
- Make sure you examine the output of `‎tests/outputs/<Language name>.<extension>.yaml` and that it is correct, then run `make test` from the `Unix` folder to make sure your test was successful.
3182+
3183+
You can use [this pull request](https://github.com/AlDanial/cloc/pull/962) or [this one](https://github.com/AlDanial/cloc/pull/947) as guidelines.
3184+
3185+
<a name="implement-it-yourself"></a> []({{{1)
3186+
## Request an Additional Language
3187+
3188+
Create a [GitHub issue](https://github.com/AlDanial/cloc/issues)
31183189
requesting support for your language. Include this information:
31193190
<ol>
31203191
<li> File extensions associated with the language. If the language does

0 commit comments

Comments
 (0)