Multiply entities beyond necessity even more (force better build parallelism)
[hiphop-php.git] / hphp / hack / src / parser / syntaxTransforms.ml
blob9f3f81d520c7105facb0843868e6d7ae04ce0e20
1 (*
2 * Copyright (c) 2018, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 module ES = Full_fidelity_editable_syntax
11 module PS = Full_fidelity_positioned_syntax
12 module ET = ES.Token
13 module PT = PS.Token
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
19 | PS.Token token ->
20 let source_text = PT.source_text token in
21 let width = PT.width token in
22 let leading =
23 Full_fidelity_editable_trivia.from_positioned_list
24 source_text
25 (PT.leading token)
26 offset
28 let trailing =
29 Full_fidelity_editable_trivia.from_positioned_list
30 source_text
31 (PT.trailing token)
32 (offset + PT.leading_width token + width)
34 let editable_token =
35 ET.make
36 (PT.kind token)
37 source_text
38 (PT.leading_start_offset token)
39 width
40 leading
41 trailing
43 let syntax = ES.Token editable_token in
44 ES.make syntax ES.Value.NoValue
45 | _ ->
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