Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>OxCaml SyntaxNew to Visual Studio Code? Get it now.
OxCaml Syntax

OxCaml Syntax

OxCaml-NG

|
2 installs
| (0) | Free
Provides basic syntax highlighting functionality for OxCaml dev.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

OxCaml Syntax

Syntax highlighting for OxCaml, Jane Street's fork of OCaml that adds modal types, unboxed layouts, comprehensions, and other language extensions.

This extension injects into the standard OCaml grammar provided by ocamllabs.ocaml-platform, layering OxCaml-specific highlighting on top without replacing anything.

OxCaml Syntax Highlighting

Features

Mode Annotations

Highlights mode keywords after the @ operator in expressions and type signatures:

let f (x @ local) (y @ local shared portable) = ...
let g : string @ local -> int = ...
val h : int -> string @ local

Supported modes: global, local, unique, aliased, once, many, shared, contended, uncontended, portable, nonportable, immutable, read, read_write, unyielding, yielding, forkable, unforkable, stateless, observing, stateful

Stack Allocation Keywords

let result = local_ (x, y, z)
let f x = exclave_ (process x)

Layout / Kind Annotations

Type parameters with layout constraints, including product layouts with &:

let f (type a : float64) (x : a) : a = x
type ('a : immediate) boxed = { value : 'a }
type t : value mod global portable

Common layouts: value, void, any, float64, float32, bits32, bits64, word, immediate, immediate64

Unboxed Types

The # suffix on type names indicates unboxed variants:

type t = { x : float64#; y : float64# }
let a : int32# = Int32_u.of_int 42

Float32 Literals

Floating-point literals with an s suffix:

let x = 1.0s
let y = 3.14s
let z = 1e10s

Immutable Arrays

Square-bracket-colon delimiters for immutable array literals:

let arr = [: "zero"; "one"; "two" :]

Comprehensions

List and array comprehensions (the base OCaml grammar handles keyword highlighting for for, to, when, etc., while this extension adds the immutable array bracket support):

let pyth = [
  a, b, c
  for a = 1 to 10
  for b = a to 10
  for c = b to 10
  when a*a + b*b = c*c
]
let grid = [| sprintf "%d,%d" x y for x = 0 to 9 and y = 0 to 9 |]

Template Attributes

PPX-style %template syntax:

let%template f (type a : immediate) (x : a) : a = x
val%template f : ('a : float64). 'a -> 'a
[%%template:
  val f : ('a : float64). 'a -> 'a
]

Zero-Alloc Attribute

let[@zero_alloc] fast_path x = x + 1
let[@zero_alloc assume] risky_path x = x + 1

Tracing Probes

let traced_fn x =
  [%probe "my_event" (record_event x)];
  x

Installation

  1. Install the OCaml Platform extension (required dependency).
  2. Install this extension from the VS Code marketplace, or build from source:
npm install -g @vscode/vsce
vsce package
code --install-extension oxcaml-syntax-0.1.0.vsix

How It Works

This extension uses a TextMate injection grammar (injectTo: ["source.ocaml"]) that layers OxCaml-specific patterns on top of the standard OCaml grammar. It does not replace or conflict with existing OCaml highlighting. Patterns are excluded from string and comment scopes to avoid false matches.

The extension also registers the [: :] immutable array delimiters as bracket pairs for auto-closing and matching.

Scope Reference

Construct TextMate Scope
Mode keywords (local, global, ...) storage.modifier.mode.ocaml
Mode @ operator keyword.operator.mode.ocaml
local_, exclave_ keyword.control.allocation.ocaml
Layout names (float64, value, ...) entity.name.type.layout.ocaml
Layout product & keyword.operator.layout-product.ocaml
Unboxed types (float64#) entity.name.type.unboxed.ocaml
Float32 literals (1.0s) constant.numeric.float32.ocaml
[: and :] punctuation.definition.array.immutable.*.ocaml
%template keyword.other.attribute.template.ocaml
zero_alloc keyword.other.attribute.zero-alloc.ocaml
[%probe ...] meta.attribute.probe.ocaml
mod (in kinds) keyword.other.mod.ocaml

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft