File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1212
1313## master
1414
15+ #### :rocket : New Feature
16+
17+ - _ internal_ Add experimental command for extracting (string) contents from extension points.
18+
1519## 0.5.0
1620
1721#### :rocket : New Feature
Original file line number Diff line number Diff line change @@ -50,6 +50,12 @@ let main () =
5050 done ;
5151 Sys. argv.(len - 1 ) < - " " ;
5252 Reanalyze. cli ()
53+ | "extract-embedded" :: extPointNames :: filename :: _ ->
54+ logAndExit
55+ (Ok
56+ (Tools. extractEmbedded
57+ ~extension Points:(extPointNames |> String. split_on_char ',' )
58+ ~filename ))
5359 | [" -h" ] | [" --help" ] -> logAndExit (Ok help)
5460 | [" -v" ] | [" --version" ] -> logAndExit (Ok version)
5561 | _ -> logAndExit (Error help)
Original file line number Diff line number Diff line change @@ -443,3 +443,42 @@ let extractDocs ~entryPointFile ~debug =
443443 in
444444
445445 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