2 * Copyright (c) 2018, Facebook, Inc.
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the "hack" directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
11 module ES
= Full_fidelity_editable_syntax
12 module PS
= Full_fidelity_positioned_syntax
15 module PositionedSyntaxTree
= Full_fidelity_syntax_tree.WithSyntax
(PS
)
17 let editable_from_positioned tree
=
18 let rec aux text positioned_node offset
=
19 match PS.syntax positioned_node
with
21 let source_text = PT.source_text token
in
22 let width = PT.width token
in
24 Full_fidelity_editable_trivia.from_positioned_list
30 Full_fidelity_editable_trivia.from_positioned_list
33 (offset
+ (PT.leading_width token
) + width)
39 (PT.leading_start_offset token
)
44 let syntax = ES.Token
editable_token in
45 ES.make
syntax ES.Value.NoValue
47 let folder (acc
, offset
) child
=
48 let new_child = aux text child offset
in
49 let w = PS.full_width child
in
50 (new_child :: acc
, offset
+ w) in
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