Skip to content

Commit

Permalink
feat: Add OCaml support
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Lewis <[email protected]>
  • Loading branch information
ianlewis committed Feb 11, 2025
1 parent d9fb26a commit 3f16a94
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1609](https://github.com/ianlewis/todos/issues/1609)).
- Support was added for [Dart](https://dart.dev/)
([#1612](https://github.com/ianlewis/todos/issues/1612)).
- Support was added for [OCaml](https://ocaml.org/)
([#1610](https://github.com/ianlewis/todos/issues/1610)).

## [0.10.0] - 2024-10-31

Expand Down
1 change: 1 addition & 0 deletions SUPPORTED_LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
| MATLAB | `.matlab`, `.m` | `%`, `%{ }%` |
| Makefile | `.mak`, `.d`, `.make`, `.makefile`, `.mk`, `.mkfile` | `#` |
| Markdown | `.md`, `.livemd`, `.markdown`, `.mdown`, `.mdwn`, `.mkd`, `.mkdn`, `.mkdown`, `.ronn`, `.scd`, `.workbook` | `<!-- -->` |
| OCaml | `.ml`, `.eliom`, `.eliomi`, `.ml4`, `.mli`, `.mll`, `.mly` | `(* *)` |
| Objective-C | `.m`, `.h` | `//`, `/* */` |
| PHP | `.php`, `.aw`, `.ctp`, `.fcgi`, `.inc`, `.php3`, `.php4`, `.php5`, `.phps`, `.phpt` | `#`, `//`, `/* */` |
| Pascal | `.pas`, `.dfm`, `.dpr`, `.inc`, `.lpr`, `.pascal`, `.pp` | `//`, `(* *)`, `{ }` |
Expand Down
11 changes: 11 additions & 0 deletions internal/scanner/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ var LanguagesConfig = map[string]*Config{
MultilineComments: cBlockComments,
Strings: cStrings,
},
"OCaml": {
// TODO(#1627): Support OCaml nested comments.
MultilineComments: []MultilineCommentConfig{
{
Start: []rune("(*"),
End: []rune("*)"),
},
},
// TODO(#1627): Support OCaml quoted string literals.
Strings: cStrings,
},
"Pascal": {
LineComments: cLineComments, // Delphi comments
MultilineComments: []MultilineCommentConfig{
Expand Down
69 changes: 69 additions & 0 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,62 @@ This is more text.<!-- this is another comment -->
},
},

// OCaml
{
name: "comments.ml",
src: `(* single line comment *)
(* multiple line comment, commenting out part of a program, and containing a
nested comment:
let f = function
| 'A'..'Z' -> "Uppercase"
*)`,
config: "OCaml",
comments: []struct {
text string
line int
}{
{
text: "(* single line comment *)",
line: 1,
},
{
text: `(* multiple line comment, commenting out part of a program, and containing a
nested comment:
let f = function
| 'A'..'Z' -> "Uppercase"
*)`,
line: 3,
},
},
},

// TODO(#1627): Support OCaml nested comments.
// {
// name: "nested_comments.ml",
// src: `(* multiple line comment, commenting out part of a program, and containing a
// nested comment:
// let f = function
// | 'A'..'Z' -> "Uppercase"
// (* Add other cases later... *)
// *)`,
// config: "OCaml",
// comments: []struct {
// text string
// line int
// }{
// {
// text: `(* multiple line comment, commenting out part of a program, and containing a
// nested comment:
// let f = function
// | 'A'..'Z' -> "Uppercase"
// (* Add other cases later... *)
// *)`,
// line: 1,
// },
// },
// },

// Python
{
name: "raw_string.py",
Expand Down Expand Up @@ -3153,6 +3209,19 @@ var loaderTestCases = []struct {
expectedConfig: "Go",
},

// OCaml
{
name: "oca.ml",
src: []byte(`(* this is a comment *)
print_endline "hello world"
let () = print_endline "hello world"
`),
scanCharset: "UTF-8",
expectedConfig: "OCaml",
},

// XML
{
name: "block_comments.xml",
Expand Down

0 comments on commit 3f16a94

Please sign in to comment.