package comby-kernel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file types.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
open Core_kernel

module Language = struct
  module Syntax = struct
    type escapable_string_literals =
      { delimiters : string list
      ; escape_character: char
      }
    [@@deriving yojson]

    type comment_kind =
      | Multiline of string * string
      | Nested_multiline of string * string
      | Until_newline of string
    [@@deriving yojson]

    type t =
      { user_defined_delimiters : (string * string) list
      ; escapable_string_literals : escapable_string_literals option [@default None]
      ; raw_string_literals : (string * string) list
      ; comments : comment_kind list
      }
    [@@deriving yojson]

    module type S = sig
      val user_defined_delimiters : (string * string) list
      val escapable_string_literals : escapable_string_literals option
      val raw_string_literals : (string * string) list
      val comments : comment_kind list
    end
  end

  module Info = struct
    module type S = sig
      val name : string
      val extensions : string list
    end
  end

  module type S = sig
    module Info : Info.S
    module Syntax : Syntax.S
  end
end

type dimension =
  | Code
  | Escapable_string_literal
  | Raw_string_literal
  | Comment

type including = char list
type until = char option

module Hole = struct

  type sort =
    | Everything
    | Expression
    | Alphanum
    | Non_space
    | Line
    | Blank
    | Regex
  [@@deriving yojson]

  type t =
    { sort : sort
    ; identifier : string
    ; dimension : dimension
    ; at_depth : int option
    }

  let sorts () =
    [ Everything
    ; Expression
    ; Alphanum
    ; Non_space
    ; Line
    ; Blank
    ; Regex
    ]
end

type hole = Hole.t

module Metasyntax = struct
  type alias =
    { pattern : string
    ; match_template : string
    ; rule : string option
    }
  [@@deriving yojson]

  type hole_definition =
    | Delimited of string option * string option
    | Reserved_identifiers of string list
  [@@deriving yojson]

  type hole_syntax =
    | Hole of Hole.sort * hole_definition
    | Regex of string * char * string
  [@@deriving yojson]

  type t =
    { syntax : hole_syntax list
    ; identifier : string
    ; aliases : alias list
    }
  [@@deriving yojson]

  module type S = sig
    val syntax : hole_syntax list
    val identifier : string
    val aliases : alias list
  end
end

module External = struct
  type t = name:string -> filepath:string -> line:int -> column:int -> string option

  module type S = sig
    val handler : t
  end
end

type production =
  | Unit
  | String of string
  | Hole of hole

module Template = struct
  type kind =
    | Value
    | Length
    | Lines
    | OffsetStart
    | OffsetEnd
    | LineStart
    | LineEnd
    | ColumnStart
    | ColumnEnd
    | FileName
    | FilePath
    | FileDirectory
    | Lowercase
    | Uppercase
    | Capitalize
    | Uncapitalize
    | UpperCamelCase
    | LowerCamelCase
    | UpperSnakeCase
    | LowerSnakeCase
    | External of string
  [@@deriving sexp]

  type syntax =
    { variable: string (* E.g., x *)
    ; pattern: string (* E.g., the entire :[x] part *)
    ; offset : int
    ; kind : kind (* The kind of hole, to inform substitution *)
    }
  [@@deriving sexp]

  type atom =
    | Hole of syntax
    | Constant of string
  [@@deriving sexp]

  type t = atom list
  [@@deriving sexp]

  module type S = sig

    module Matching : sig
      val hole_parsers : (Hole.sort * string Vangstrom.t) list
    end

    val parse : string -> t

    val variables : string -> syntax list

    val to_string : t -> string

    val substitute : ?filepath:string -> t -> Match.Environment.t -> (string * Match.Environment.t)
  end
end

module Ast = struct
  type atom =
    | Template of Template.t
    | String of string
  [@@deriving sexp]

  type antecedent = atom
  [@@deriving sexp]

  type expression =
    | True
    | False
    | Option of string
    | Equal of atom * atom
    | Not_equal of atom * atom
    | Match of atom * (antecedent * consequent) list
    | Rewrite of atom * (antecedent * atom)
  and consequent = expression list
  [@@deriving sexp]
end

module Rule = struct
  type t = Ast.expression list
  [@@deriving sexp]

  module type S = sig
    val create : string -> (Ast.expression list, Error.t) result
  end
end

module Matcher = struct
  module type S = sig
    val all
      :  ?configuration:Configuration.t
      -> ?filepath:string
      -> ?rule:Rule.t
      -> template:string
      -> source:string
      -> unit
      -> Match.t list

    val first
      :  ?configuration:Configuration.t
      -> ?shift:int
      -> ?filepath:string
      -> string
      -> string
      -> Match.t Or_error.t

    include Language.Info.S

    val set_rewrite_template : string -> unit
  end
end

module Engine = struct
  module type S = sig
    module Make : Language.S -> Metasyntax.S -> External.S -> Matcher.S

    module Text : Matcher.S
    module Paren : Matcher.S
    module Dyck : Matcher.S
    module JSON : Matcher.S
    module JSONC : Matcher.S
    module GraphQL : Matcher.S
    module Dhall : Matcher.S
    module Latex : Matcher.S
    module Assembly : Matcher.S
    module Clojure : Matcher.S
    module Lisp : Matcher.S
    module Generic : Matcher.S
    module Bash : Matcher.S
    module Ruby : Matcher.S
    module Elixir : Matcher.S
    module Python : Matcher.S
    module Html : Matcher.S
    module Xml : Matcher.S
    module SQL : Matcher.S
    module Erlang : Matcher.S
    module C : Matcher.S
    module Csharp : Matcher.S
    module Java : Matcher.S
    module CSS : Matcher.S
    module Kotlin : Matcher.S
    module Scala : Matcher.S
    module Nim : Matcher.S
    module Matlab : Matcher.S
    module Dart : Matcher.S
    module Php : Matcher.S
    module Go : Matcher.S
    module Javascript : Matcher.S
    module Jsx : Matcher.S
    module Typescript : Matcher.S
    module Tsx : Matcher.S
    module Swift : Matcher.S
    module Rust : Matcher.S
    module R : Matcher.S
    module OCaml : Matcher.S
    module Reason : Matcher.S
    module Fsharp : Matcher.S
    module Pascal : Matcher.S
    module Julia : Matcher.S
    module Fortran : Matcher.S
    module Haskell : Matcher.S
    module HCL : Matcher.S
    module Elm : Matcher.S
    module Zig: Matcher.S
    module Coq: Matcher.S
    module Move: Matcher.S
    module Solidity: Matcher.S
    module C_nested_comments : Matcher.S

    val all : (module Matcher.S) list
    val select_with_extension : ?metasyntax:Metasyntax.t -> ?external_handler:External.t -> string -> (module Matcher.S) option
    val create : ?metasyntax:Metasyntax.t -> ?external_handler:External.t -> Language.Syntax.t -> (module Matcher.S)
  end
end
OCaml

Innovation. Community. Security.