Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e6f34b

Browse files
authored
refactor: structured record for printer maker result, add intf file (#2884)
1 parent91dd1f9 commit2e6f34b

File tree

4 files changed

+106
-14
lines changed

4 files changed

+106
-14
lines changed

‎src/refmt/printer_maker.ml‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
openReason
22

3+
type'a parser_result=
4+
{ast :'a
5+
;comments :Reason_comment.tlist
6+
;parsed_as_ml :bool
7+
;parsed_as_intf :bool
8+
}
9+
310
typeparse_itype=
411
[`ML
512
|`Reason
@@ -40,8 +47,7 @@ end
4047

4148
leterrs= raise (Invalid_config s)
4249

43-
letprepare_output_filename=
44-
match namewith
50+
letprepare_output_file=function
4551
|Somename -> open_out_bin name
4652
|None ->
4753
set_binary_mode_out stdouttrue;
@@ -57,8 +63,18 @@ let ocamlBinaryParser use_stdin filename =
5763
in
5864
matchAst_io.read input_source~input_kind:Necessarily_binarywith
5965
|Error_ ->assertfalse
60-
|Ok{ast =Implast; _ } -> (Obj.magic ast,[]),true,false
61-
|Ok{ast =Intfast; _ } -> (Obj.magic ast,[]),true,true
66+
|Ok{ast =Implast; _ } ->
67+
{ ast=Obj.magic ast
68+
; comments=[]
69+
; parsed_as_ml=true
70+
; parsed_as_intf=false
71+
}
72+
|Ok{ast =Intfast; _ } ->
73+
{ ast=Obj.magic ast
74+
; comments=[]
75+
; parsed_as_ml=true
76+
; parsed_as_intf=true
77+
}
6278

6379
letreasonBinaryParseruse_stdinfilename=
6480
let chan=
@@ -69,5 +85,5 @@ let reasonBinaryParser use_stdin filename =
6985
seek_in file_chan0;
7086
file_chan
7187
in
72-
let _, _, ast, comments,parsedAsML, parsedAsInterface= input_value chanin
73-
(ast, comments), parsedAsML, parsedAsInterface
88+
let _, _, ast, comments,parsed_as_ml, parsed_as_intf= input_value chanin
89+
{ast; comments; parsed_as_ml; parsed_as_intf }

‎src/refmt/printer_maker.mli‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
openReason
2+
3+
type'a parser_result=
4+
{ast :'a
5+
;comments :Reason_comment.tlist
6+
;parsed_as_ml :bool
7+
;parsed_as_intf :bool
8+
}
9+
10+
typeparse_itype=
11+
[`ML
12+
|`Reason
13+
|`Binary
14+
|`BinaryReason
15+
|`Auto
16+
]
17+
18+
typeprint_itype=
19+
[`ML
20+
|`Reason
21+
|`Binary
22+
|`BinaryReason
23+
|`AST
24+
|`None
25+
]
26+
27+
exceptionInvalid_config ofstring
28+
29+
module typePRINTER=sig
30+
typet
31+
32+
valparse :
33+
use_stdin:bool
34+
->parse_itype
35+
->string
36+
-> (t*Reason_comment.tlist)*bool
37+
38+
valprint :
39+
print_itype
40+
->string
41+
->bool
42+
->out_channel
43+
->Format.formatter
44+
->t*Reason_comment.tlist
45+
->unit
46+
end
47+
48+
valerr :string ->'a
49+
valocamlBinaryParser :bool ->string ->'aparser_result
50+
valreasonBinaryParser :bool ->string ->'aparser_result
51+
valprepare_output_file :stringoption ->out_channel
52+
valclose_output_file :stringoption ->out_channel ->unit

‎src/refmt/reason_implementation_printer.ml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,34 @@ let defaultImplementationParserFor use_stdin filename =
1919
^ filename
2020
^"'.")
2121
in
22-
theParser (setup_lexbuf use_stdin filename), parsedAsML,false
22+
let ast, comments= theParser (setup_lexbuf use_stdin filename)in
23+
{Printer_maker.ast
24+
; comments
25+
; parsed_as_ml= parsedAsML
26+
; parsed_as_intf=false
27+
}
2328

2429
letparse~use_stdinfiletypefilename=
25-
let (ast, comments), parsedAsML, parsedAsInterface=
30+
let {Printer_maker.ast
31+
; comments
32+
; parsed_as_ml= parsedAsML
33+
; parsed_as_intf= parsedAsInterface
34+
}
35+
=
2636
match filetypewith
2737
|`Auto -> defaultImplementationParserFor use_stdin filename
2838
|`BinaryReason ->Printer_maker.reasonBinaryParser use_stdin filename
2939
|`Binary ->Printer_maker.ocamlBinaryParser use_stdin filename
3040
|`ML ->
3141
let lexbuf=Reason_toolchain.setup_lexbuf use_stdin filenamein
3242
let impl=Reason_toolchain.ML.implementation_with_commentsin
33-
impl lexbuf,true,false
43+
let ast, comments= impl lexbufin
44+
{ ast; comments; parsed_as_ml=true; parsed_as_intf=false }
3445
|`Reason ->
3546
let lexbuf=Reason_toolchain.setup_lexbuf use_stdin filenamein
3647
let impl=Reason_toolchain.RE.implementation_with_commentsin
37-
impl lexbuf,false,false
48+
let ast, comments= impl lexbufin
49+
{ ast; comments; parsed_as_ml=false; parsed_as_intf=false }
3850
in
3951
if parsedAsInterface
4052
then err"The file parsed does not appear to be an implementation file."

‎src/refmt/reason_interface_printer.ml‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,34 @@ let defaultInterfaceParserFor use_stdin filename =
1919
^ filename
2020
^"'.")
2121
in
22-
theParser (setup_lexbuf use_stdin filename), parsedAsML,true
22+
let ast, comments= theParser (setup_lexbuf use_stdin filename)in
23+
{Printer_maker.ast
24+
; comments
25+
; parsed_as_ml= parsedAsML
26+
; parsed_as_intf=true
27+
}
2328

2429
letparse~use_stdinfiletypefilename=
25-
let (ast, comments), parsedAsML, parsedAsInterface=
30+
let {Printer_maker.ast
31+
; comments
32+
; parsed_as_ml= parsedAsML
33+
; parsed_as_intf= parsedAsInterface
34+
}
35+
=
2636
match filetypewith
2737
|`Auto -> defaultInterfaceParserFor use_stdin filename
2838
|`BinaryReason ->Printer_maker.reasonBinaryParser use_stdin filename
2939
|`Binary ->Printer_maker.ocamlBinaryParser use_stdin filename
3040
|`ML ->
3141
let lexbuf=Reason_toolchain.setup_lexbuf use_stdin filenamein
3242
let intf=Reason_toolchain.ML.interface_with_commentsin
33-
intf lexbuf,true,true
43+
let ast, comments= intf lexbufin
44+
{ ast; comments; parsed_as_ml=true; parsed_as_intf=true }
3445
|`Reason ->
3546
let lexbuf=Reason_toolchain.setup_lexbuf use_stdin filenamein
3647
let intf=Reason_toolchain.RE.interface_with_commentsin
37-
intf lexbuf,false,true
48+
let ast, comments= intf lexbufin
49+
{ ast; comments; parsed_as_ml=false; parsed_as_intf=true }
3850
in
3951
ifnot parsedAsInterface
4052
then err"The file parsed does not appear to be an interface file."

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp