@@ -14295,6 +14295,171 @@ let transform loc s =
14295
14295
14296
14296
14297
14297
14298
+ end
14299
+ module Ast_compatible : sig
14300
+ #1 "ast_compatible.mli"
14301
+ (* Copyright (C) 2018 Authors of BuckleScript
14302
+ *
14303
+ * This program is free software: you can redistribute it and/or modify
14304
+ * it under the terms of the GNU Lesser General Public License as published by
14305
+ * the Free Software Foundation, either version 3 of the License, or
14306
+ * (at your option) any later version.
14307
+ *
14308
+ * In addition to the permissions granted to you by the LGPL, you may combine
14309
+ * or link a "work that uses the Library" with a publicly distributed version
14310
+ * of this file to produce a combined library or application, then distribute
14311
+ * that combined work under the terms of your choosing, with no requirement
14312
+ * to comply with the obligations normally placed on you by section 4 of the
14313
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
14314
+ * should you choose to use a later version).
14315
+ *
14316
+ * This program is distributed in the hope that it will be useful,
14317
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14318
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14319
+ * GNU Lesser General Public License for more details.
14320
+ *
14321
+ * You should have received a copy of the GNU Lesser General Public License
14322
+ * along with this program; if not, write to the Free Software
14323
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
14324
+
14325
+
14326
+ type loc = Location.t
14327
+ type attrs = Parsetree.attribute list
14328
+ open Parsetree
14329
+
14330
+
14331
+ val const_exp_string:
14332
+ ?loc:Location.t ->
14333
+ ?attrs:attrs ->
14334
+ ?delimiter:string ->
14335
+ string ->
14336
+ expression
14337
+
14338
+ val const_exp_int:
14339
+ ?loc:Location.t ->
14340
+ ?attrs:attrs ->
14341
+ int ->
14342
+ expression
14343
+
14344
+ val const_exp_int_list_as_array:
14345
+ int list ->
14346
+ expression
14347
+
14348
+ val apply_simple:
14349
+ ?loc:Location.t ->
14350
+ ?attrs:attrs ->
14351
+ expression ->
14352
+ expression list ->
14353
+ expression
14354
+
14355
+
14356
+ val apply_labels:
14357
+ ?loc:Location.t ->
14358
+ ?attrs:attrs ->
14359
+ expression ->
14360
+ (string * expression) list ->
14361
+ (* [(label,e)] [label] is strictly interpreted as label *)
14362
+ expression
14363
+
14364
+ val fun_ :
14365
+ ?loc:Location.t ->
14366
+ ?attrs:attrs ->
14367
+ pattern ->
14368
+ expression ->
14369
+ expression
14370
+ end = struct
14371
+ #1 "ast_compatible.ml"
14372
+ (* Copyright (C) 2018 Authors of BuckleScript
14373
+ *
14374
+ * This program is free software: you can redistribute it and/or modify
14375
+ * it under the terms of the GNU Lesser General Public License as published by
14376
+ * the Free Software Foundation, either version 3 of the License, or
14377
+ * (at your option) any later version.
14378
+ *
14379
+ * In addition to the permissions granted to you by the LGPL, you may combine
14380
+ * or link a "work that uses the Library" with a publicly distributed version
14381
+ * of this file to produce a combined library or application, then distribute
14382
+ * that combined work under the terms of your choosing, with no requirement
14383
+ * to comply with the obligations normally placed on you by section 4 of the
14384
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
14385
+ * should you choose to use a later version).
14386
+ *
14387
+ * This program is distributed in the hope that it will be useful,
14388
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14389
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14390
+ * GNU Lesser General Public License for more details.
14391
+ *
14392
+ * You should have received a copy of the GNU Lesser General Public License
14393
+ * along with this program; if not, write to the Free Software
14394
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
14395
+
14396
+ type loc = Location.t
14397
+ type attrs = Parsetree.attribute list
14398
+ open Parsetree
14399
+ let default_loc = Location.none
14400
+
14401
+
14402
+
14403
+ let const_exp_string
14404
+ ?(loc = default_loc)
14405
+ ?(attrs = [])
14406
+ ?delimiter
14407
+ (s : string) : expression =
14408
+ {
14409
+ pexp_loc = loc;
14410
+ pexp_attributes = attrs;
14411
+ pexp_desc = Pexp_constant(Const_string(s,delimiter))
14412
+ }
14413
+
14414
+
14415
+ let const_exp_int
14416
+ ?(loc = default_loc)
14417
+ ?(attrs = [])
14418
+ (s : int) : expression =
14419
+ {
14420
+ pexp_loc = loc;
14421
+ pexp_attributes = attrs;
14422
+ pexp_desc = Pexp_constant(Const_int s)
14423
+ }
14424
+
14425
+
14426
+ let const_exp_int_list_as_array xs =
14427
+ Ast_helper.Exp.array
14428
+ (Ext_list.map (fun x -> const_exp_int x ) xs)
14429
+
14430
+ let apply_simple
14431
+ ?(loc = default_loc)
14432
+ ?(attrs = [])
14433
+ fn args : expression =
14434
+ { pexp_loc = loc;
14435
+ pexp_attributes = attrs;
14436
+ pexp_desc =
14437
+ Pexp_apply(
14438
+ fn,
14439
+ (Ext_list.map (fun x -> "",x) args) ) }
14440
+
14441
+ let apply_labels
14442
+ ?(loc = default_loc)
14443
+ ?(attrs = [])
14444
+ fn args : expression =
14445
+ { pexp_loc = loc;
14446
+ pexp_attributes = attrs;
14447
+ pexp_desc =
14448
+ Pexp_apply(
14449
+ fn,
14450
+ args ) }
14451
+
14452
+ let fun_
14453
+ ?(loc = default_loc)
14454
+ ?(attrs = [])
14455
+ pat
14456
+ exp =
14457
+ {
14458
+ pexp_loc = loc;
14459
+ pexp_attributes = attrs;
14460
+ pexp_desc = Pexp_fun("",None, pat, exp)
14461
+ }
14462
+
14298
14463
end
14299
14464
module Bs_loc : sig
14300
14465
#1 "bs_loc.mli"
@@ -14845,10 +15010,10 @@ let concat_exp
14845
15010
(a : Parsetree.expression)
14846
15011
(b : Parsetree.expression) : Parsetree.expression =
14847
15012
let loc = Bs_loc.merge a.pexp_loc b.pexp_loc in
14848
- Exp.apply ~loc
15013
+ Ast_compatible.apply_simple ~loc
14849
15014
(Exp.ident { txt =concat_ident; loc})
14850
- ["", a ;
14851
- "", b]
15015
+ [a ;
15016
+ b]
14852
15017
14853
15018
let border = String.length "{j|"
14854
15019
@@ -14859,19 +15024,17 @@ let aux loc (segment : segment) =
14859
15024
begin match kind with
14860
15025
| String ->
14861
15026
let loc = update border start finish loc in
14862
- Exp.constant
14863
- ~loc
14864
- (Const_string (content, escaped))
15027
+ Ast_compatible.const_exp_string
15028
+ content ?delimiter:escaped ~loc
14865
15029
| Var (soffset, foffset) ->
14866
15030
let loc = {
14867
15031
loc with
14868
15032
loc_start = update_position (soffset + border) start loc.loc_start ;
14869
15033
loc_end = update_position (foffset + border) finish loc.loc_start
14870
15034
} in
14871
- Exp.apply ~loc
15035
+ Ast_compatible.apply_simple ~loc
14872
15036
(Exp.ident ~loc {loc ; txt = to_string_ident })
14873
15037
[
14874
- "",
14875
15038
Exp.ident ~loc {loc ; txt = Lident content}
14876
15039
]
14877
15040
end
@@ -14896,8 +15059,8 @@ let transform_interp loc s =
14896
15059
let rev_segments = cxt.segments in
14897
15060
match rev_segments with
14898
15061
| [] ->
14899
- Exp.constant ~loc
14900
- (Const_string ("", Some Literals.escaped_j_delimiter))
15062
+ Ast_compatible.const_exp_string ~loc
15063
+ "" ~delimiter: Literals.escaped_j_delimiter
14901
15064
| [ segment] ->
14902
15065
aux loc segment
14903
15066
| a::rest ->
0 commit comments