package reason

  1. Overview
  2. Docs
val is_prefixed : string -> string -> int -> bool

is_prefixed prefix i str checks if prefix is the prefix of str * starting from position i

val pick_while : ('a -> bool) -> 'a list -> 'a list * 'a list

* pick_while returns a tuple where first element is longest prefix (possibly empty) of the list of elements that satisfy p * and second element is the remainder of the list

val find_substring : string -> string -> int -> int

find_substring sub str i returns the smallest j >= i such that sub = str.[j..length sub - 1] raises Not_found if there is no such j behavior is not defined if sub is the empty string

val replace_string : string -> string -> string -> string

replace_string old_str new_str str replaces old_str to new_str in str

val split_by : ?keep_empty:bool -> (char -> bool) -> string -> string list
val trim_right_idx : string -> int -> int
val trim_right : string -> string
val strip_trailing_whitespace : string -> string
module StringMap : sig ... end
val syntax_error_extension_node : Ast_404.Location.t -> string -> string Ast_404.Location.loc * Ast_404.Parsetree.payload

Generate a suitable extension node for Merlin's consumption, for the purposes of reporting a syntax error - only used in recovery mode.

val potentially_conflicts_with : keyword:string -> string -> bool

Check to see if the string `s` is made up of `keyword` and zero or more trailing `_` characters.

val string_add_suffix : string -> string

Add/remove an appropriate suffix when mangling potential keywords

val string_drop_suffix : string -> string

What do these *_swap functions do? Here's an example: Reason code uses `!` for logical not, while ocaml uses `not`. So, for converting between reason and ocaml syntax, ocaml `not` converts to `!`, reason `!` converts to `not`.

In more complicated cases where a reserved keyword exists in one syntax but not the other, these functions translate any potentially conflicting identifier into the same identifier with a suffix attached, or remove the suffix when converting back. Two examples:

reason to ocaml:

pub: invalid in reason to begin with pub_: pub pub__: pub_

ocaml to reason:

pub: pub_ pub_: pub__ pub__: pub___

=====

reason to ocaml:

match: match_ match_: match__ match__: match___

ocaml to reason:

match: invalid in ocaml to begin with match_: match match__: match_

val reason_to_ml_swap : string -> string
val ml_to_reason_swap : string -> string
val identifier_mapper : (string -> string) -> Ast_404.Ast_mapper.mapper -> Ast_404.Ast_mapper.mapper

identifier_mapper maps all identifiers in an AST with a mapping function f this is used by swap_operator_mapper right below, to traverse the whole AST and swapping the symbols listed above.

val escape_stars_slashes_mapper : Ast_404.Ast_mapper.mapper -> Ast_404.Ast_mapper.mapper

escape_stars_slashes_mapper escapes all stars and slases in an AST

val reason_to_ml_swap_operator_mapper : Ast_404.Ast_mapper.mapper -> Ast_404.Ast_mapper.mapper
val ml_to_reason_swap_operator_mapper : Ast_404.Ast_mapper.mapper -> Ast_404.Ast_mapper.mapper
val attribute_equals : 'a -> ('a Ast_404.Asttypes.loc * 'b) -> bool
val attribute_exists : 'a -> ('a Ast_404.Asttypes.loc * 'b) list -> bool
val attributes_conflicted : 'a -> 'a -> ('a Ast_404.Asttypes.loc * 'b) list -> bool
val normalized_attributes : 'a -> ('a Ast_404.Asttypes.loc * 'b) list -> ('a Ast_404.Asttypes.loc * 'b) list
val apply_mapper_to_structure : Migrate_parsetree__Ast_404.Parsetree.structure_item list -> Ast_404.Ast_mapper.mapper -> Migrate_parsetree__Ast_404.Parsetree.structure_item list
val apply_mapper_to_signature : Migrate_parsetree__Ast_404.Parsetree.signature_item list -> Ast_404.Ast_mapper.mapper -> Migrate_parsetree__Ast_404.Parsetree.signature_item list
val apply_mapper_to_type : Migrate_parsetree__Ast_404.Parsetree.core_type -> Ast_404.Ast_mapper.mapper -> Migrate_parsetree__Ast_404.Parsetree.core_type
val apply_mapper_to_expr : Migrate_parsetree__Ast_404.Parsetree.expression -> Ast_404.Ast_mapper.mapper -> Migrate_parsetree__Ast_404.Parsetree.expression
val apply_mapper_to_pattern : Migrate_parsetree__Ast_404.Parsetree.pattern -> Ast_404.Ast_mapper.mapper -> Migrate_parsetree__Ast_404.Parsetree.pattern
type error =
  1. | Syntax_error of string
exception Error of Ast_404.Location.t * error
val report_error : Format.formatter -> error -> unit
type menhirMessagesError = {
  1. msg : string;
  2. loc : Ast_404.Location.t;
}
type menhirError =
  1. | NoMenhirMessagesError
  2. | MenhirMessagesError of menhirMessagesError
val menhirMessagesError : menhirError list Pervasives.ref
val findMenhirErrorMessage : Ast_404.Location.t -> menhirError
val add_error_message : menhirMessagesError -> unit