11use nom:: {
22 branch:: alt,
33 bytes:: complete:: { tag, take_until} ,
4- combinator:: map_res,
5- sequence:: delimited ,
4+ combinator:: { map_res, rest } ,
5+ sequence:: { pair , terminated } ,
66 IResult , InputTake ,
77} ;
88use nom_locate:: LocatedSpan ;
@@ -12,32 +12,20 @@ use crate::{ast::node::comment::CommentNode, ast::range::Range};
1212use super :: * ;
1313
1414pub fn comment ( input : Span ) -> IResult < Span , Box < NodeEnum > > {
15- alt ( (
16- map_res (
17- delimited ( tag ( "///" ) , take_until ( "\n " ) , tag ( "\n " ) ) ,
18- |c : LocatedSpan < & str > | {
19- res_enum (
20- CommentNode {
21- comment : c. to_string ( ) ,
22- range : Range :: new ( input, c. take_split ( c. len ( ) ) . 0 ) ,
23- is_doc : true ,
24- }
25- . into ( ) ,
26- )
27- } ,
15+ map_res (
16+ pair (
17+ alt ( ( tag ( "///" ) , tag ( "//" ) ) ) ,
18+ alt ( ( terminated ( take_until ( "\n " ) , tag ( "\n " ) ) , rest) ) ,
2819 ) ,
29- map_res (
30- delimited ( tag ( "//" ) , take_until ( "\n " ) , tag ( "\n " ) ) ,
31- |c : LocatedSpan < & str > | {
32- res_enum (
33- CommentNode {
34- comment : c. to_string ( ) ,
35- range : Range :: new ( input, c. take_split ( c. len ( ) ) . 0 ) ,
36- is_doc : false ,
37- }
38- . into ( ) ,
39- )
40- } ,
41- ) ,
42- ) ) ( input)
20+ |( a, c) : ( LocatedSpan < & str > , LocatedSpan < & str > ) | {
21+ res_enum (
22+ CommentNode {
23+ comment : c. to_string ( ) ,
24+ range : Range :: new ( input, c. take_split ( c. len ( ) ) . 0 ) ,
25+ is_doc : a. contains ( "///" ) ,
26+ }
27+ . into ( ) ,
28+ )
29+ } ,
30+ ) ( input)
4331}
0 commit comments