Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OCaml Support #161

Merged
merged 3 commits into from
Mar 17, 2025
Merged

Add OCaml Support #161

merged 3 commits into from
Mar 17, 2025

Conversation

WayneYam
Copy link
Contributor

@WayneYam WayneYam commented Mar 5, 2025

Basic support for OCaml, including basic delimiters and let ... in, if ... else, match ... with, for and while blocks.

@S41d
Copy link

S41d commented Mar 10, 2025

I started to write some of the rules for OCaml a while ago but never got to make a PR. Here's everything I had in rainbow-delimiters.scm in case it helps :

(parenthesized_pattern
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(parenthesized_operator
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(parenthesized_expression
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(parenthesized_module_expression
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(list_expression
  "[" @delimiter
  "]" @delimiter @sentinel) @container

(list_pattern
  "[" @delimiter
  "]" @delimiter @sentinel) @container

(array_expression
  "[|" @delimiter
  "|]" @delimiter @sentinel) @container

(array_pattern
  "[|" @delimiter
  "|]" @delimiter @sentinel) @container

(array_get_expression
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(attribute
  "[@" @delimiter
  "]" @delimiter @sentinel) @container

(item_attribute
  "[@@" @delimiter
  "]" @delimiter @sentinel) @container

(floating_attribute
  "[@@@" @delimiter
  "]" @delimiter @sentinel) @container

(record_pattern
  "{" @delimiter
  "}" @delimiter @sentinel) @container

(record_expression
  "{" @delimiter
  "}" @delimiter @sentinel) @container

(record_declaration
  "{" @delimiter
  "}" @delimiter @sentinel) @container

(record_binding_pattern
  "{" @delimiter
  "}" @delimiter @sentinel) @container

(class_binding
  "[" @delimiter
  "]" @delimiter @sentinel) @container

(object_expression
  "(" @delimiter
  ")" @delimiter @sentinel) @container

; (parenthesized_expression
;   "begin" @delimiter
;   "end" @delimiter @sentinel) @container

(typed_pattern
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(typed_expression
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(parenthesized_type
  "(" @delimiter
  ")" @delimiter @sentinel) @container

(polymorphic_variant_type
  "[<" @delimiter
  "]" @delimiter @sentinel) @container

(polymorphic_variant_type
  "[>" @delimiter
  "]" @delimiter @sentinel) @container

(string_get_expression
  "[" @delimiter
  "]" @delimiter @sentinel) @container

(extension
  "[%" @delimiter
  "]" @delimiter @sentinel) @container

; this errors so we comment it out for now
; (quoted_extension
;   "{%" @delimiter
;   "}" @delimiter @sentinel) @container

(item_extension
  "[%%" @delimiter
  "]" @delimiter @sentinel) @container

(quoted_item_extension
  "{%%" @delimiter
  "}" @delimiter @sentinel) @container

(quoted_string
  "{" @delimiter
  "}" @sentinel) @container

(bigarray_get_expression
  "{" @delimiter
  "}" @delimiter @sentinel) @container

(object_copy_expression
  "{<" @delimiter
  ">}" @delimiter @sentinel) @container

@HiPhish
Copy link
Owner

HiPhish commented Mar 11, 2025

Thank you for the PR, but can you please add a sample file which contains all the patterns you have defined? Place it in test/highlight/samples/ocaml. You can give it some generic names like regular.ml (or whatever the extension is). The file does not need to make particular sense, but it should compile if possible.

@WayneYam
Copy link
Contributor Author

Thanks for replying.

I will first merge the other patterns that @S41d suggested, and then write a sample file, but it will take some time and I'm a little busy right now. It should be done in a week or so.

@WayneYam
Copy link
Contributor Author

There seems to be some more delimiters (mainly just ()) but this should cover the most common ones

@HiPhish
Copy link
Owner

HiPhish commented Mar 15, 2025

Should I review now?

@WayneYam
Copy link
Contributor Author

Yes, please.

Copy link
Owner

@HiPhish HiPhish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. If you can answer that one question I will go ahead and merge.

@HiPhish HiPhish merged commit 9e10c04 into HiPhish:master Mar 17, 2025
@HiPhish
Copy link
Owner

HiPhish commented Mar 17, 2025

Merged, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants