2 * Copyright (c) 2018, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
10 module ES
= Full_fidelity_editable_syntax
11 module PS
= Full_fidelity_positioned_syntax
14 module PositionedSyntaxTree
= Full_fidelity_syntax_tree.WithSyntax
(PS
)
16 let editable_from_positioned tree
=
17 let rec aux text positioned_node offset
=
18 match PS.syntax positioned_node
with
20 let source_text = PT.source_text token
in
21 let width = PT.width token
in
23 Full_fidelity_editable_trivia.from_positioned_list
29 Full_fidelity_editable_trivia.from_positioned_list
32 (offset
+ PT.leading_width token
+ width)
38 (PT.leading_start_offset token
)
43 let syntax = ES.Token
editable_token in
44 ES.make
syntax ES.Value.NoValue
46 let folder (acc
, offset
) child
=
47 let new_child = aux text child offset
in
48 let w = PS.full_width child
in
49 (new_child :: acc
, offset
+ w)
51 let kind = PS.kind positioned_node
in
52 let positioneds = PS.children positioned_node
in
53 let (editables
, _
) = List.fold_left
folder ([], offset
) positioneds in
54 let editables = List.rev
editables in
55 let syntax = ES.syntax_from_children
kind editables in
56 ES.make
syntax ES.Value.NoValue
58 aux (PositionedSyntaxTree.text tree
) (PositionedSyntaxTree.root tree
) 0