File tree 3 files changed +49
-0
lines changed
3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 12
12
13
13
## master
14
14
15
+ #### :rocket : New Feature
16
+
17
+ - _ internal_ Add experimental command for extracting (string) contents from extension points.
18
+
15
19
## 0.5.0
16
20
17
21
#### :rocket : New Feature
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ let main () =
50
50
done ;
51
51
Sys. argv.(len - 1 ) < - " " ;
52
52
Reanalyze. cli ()
53
+ | "extract-embedded" :: extPointNames :: filename :: _ ->
54
+ logAndExit
55
+ (Ok
56
+ (Tools. extractEmbedded
57
+ ~extension Points:(extPointNames |> String. split_on_char ',' )
58
+ ~filename ))
53
59
| [" -h" ] | [" --help" ] -> logAndExit (Ok help)
54
60
| [" -v" ] | [" --version" ] -> logAndExit (Ok version)
55
61
| _ -> logAndExit (Error help)
Original file line number Diff line number Diff line change @@ -443,3 +443,42 @@ let extractDocs ~entryPointFile ~debug =
443
443
in
444
444
445
445
result
446
+
447
+ let extractEmbedded ~extensionPoints ~filename =
448
+ let {Res_driver. parsetree = structure} =
449
+ Res_driver. parsingEngine.parseImplementation ~for Printer:false ~filename
450
+ in
451
+ let content = ref [] in
452
+ let append item = content := item :: ! content in
453
+ let extension (iterator : Ast_iterator.iterator ) (ext : Parsetree.extension ) =
454
+ (match ext with
455
+ | ( {txt},
456
+ PStr
457
+ [
458
+ {
459
+ pstr_desc =
460
+ Pstr_eval
461
+ ( {
462
+ pexp_loc;
463
+ pexp_desc = Pexp_constant (Pconst_string (contents, _));
464
+ },
465
+ _ );
466
+ };
467
+ ] )
468
+ when extensionPoints |> List. exists (fun v -> v = txt) ->
469
+ append (pexp_loc, txt, contents)
470
+ | _ -> () );
471
+ Ast_iterator. default_iterator.extension iterator ext
472
+ in
473
+ let iterator = {Ast_iterator. default_iterator with extension} in
474
+ iterator.structure iterator structure;
475
+ let open Analysis.Protocol in
476
+ ! content
477
+ |> List. map (fun (loc , extensionName , contents ) ->
478
+ stringifyObject
479
+ [
480
+ (" extensionName" , Some extensionName);
481
+ (" contents" , Some contents);
482
+ (" loc" , Some (Analysis.Utils. cmtLocToRange loc |> stringifyRange));
483
+ ])
484
+ |> array
You can’t perform that action at this time.
0 commit comments