package ppxlib_jane

  1. Overview
  2. Docs

Novel syntax in patterns

type t =
  1. | Jpat_immutable_array of Immutable_arrays.pattern
  2. | Jpat_layout of Layouts.pattern
  3. | Jpat_tuple of Labeled_tuples.pattern
include AST with type t := t * Ppxlib_ast.Parsetree.attributes and type ast := Ppxlib_ast.Parsetree.pattern

Given an OCaml AST node, check to see if it corresponds to an embedded term from our novel syntax. If it does, as long as the feature isn't a disabled language extension, then return it; if it's not a piece of novel syntax, return None; if it's an embedded term from a disabled language extension, raise an error.

AN IMPORTANT NOTE: The design of this function is careful to make merge conflicts with upstream less likely: we want no edits at all -- not even indentation -- to surrounding code. This is why we return a t option, not some structure that could include the ast_desc if there is no extension.

Indentation: we *do not change the indentation level* when we match on this function's result! E.g. from type_expect_ in typecore.ml:

match Jane_syntax.Expression.of_ast sexp with
| Some jexp ->
    type_expect_jane_syntax
      ~loc
      ~env
      ~expected_mode
      ~ty_expected
      ~explanation
      ~attributes:sexp.pexp_attributes
      jexp
| None      -> match sexp.pexp_desc with
| Pexp_ident lid ->
    let path, mode, desc, kind = type_ident env ~recarg lid in
    (* ... *)
| Pexp_constant(Pconst_string (str, _, _) as cst) ->
    register_allocation expected_mode;
    (* ... *)
| (* ... *)
| Pexp_unreachable ->
    re { exp_desc = Texp_unreachable;
         exp_loc = loc; exp_extra = [];
         exp_type = instance ty_expected;
         exp_mode = expected_mode.mode;
         exp_attributes = sexp.pexp_attributes;
         exp_env = env }

Note that we match on the result of this function, forward to type_expect_jane_syntax if we get something, and otherwise do the real match on sexp.pexp_desc *without going up an indentation level*. This is important to reduce the number of merge conflicts.

OCaml

Innovation. Community. Security.