@@ -23,6 +23,7 @@ pub(crate) fn document(input: &str) -> IResult<&str, KdlDocument, KdlParseError<
23
23
24
24
pub ( crate ) fn node ( input : & str ) -> IResult < & str , KdlNode , KdlParseError < & str > > {
25
25
let ( input, leading) = all_whitespace ( input) ?;
26
+ let ( input, ty) = opt ( annotation) ( input) ?;
26
27
let ( input, name) = identifier ( input) ?;
27
28
let ( input, entries) = many0 ( entry) ( input) ?;
28
29
let ( input, children) = opt ( children) ( input) ?;
@@ -33,6 +34,7 @@ pub(crate) fn node(input: &str) -> IResult<&str, KdlNode, KdlParseError<&str>> {
33
34
let mut node = KdlNode :: new ( name) ;
34
35
node. set_leading ( leading) ;
35
36
node. set_trailing ( trailing) ;
37
+ node. ty = ty;
36
38
let ents = node. entries_mut ( ) ;
37
39
* ents = entries;
38
40
if let Some ( ( before, children) ) = children {
@@ -70,19 +72,23 @@ pub(crate) fn entry(input: &str) -> IResult<&str, KdlEntry, KdlParseError<&str>>
70
72
71
73
fn property ( input : & str ) -> IResult < & str , KdlEntry , KdlParseError < & str > > {
72
74
let ( input, leading) = recognize ( many0 ( node_space) ) ( input) ?;
75
+ let ( input, ty) = opt ( annotation) ( input) ?;
73
76
let ( input, name) = identifier ( input) ?;
74
77
let ( input, _) = tag ( "=" ) ( input) ?;
75
78
let ( input, ( raw, value) ) = value ( input) ?;
76
79
let mut entry = KdlEntry :: new_prop ( name, value) ;
80
+ entry. ty = ty;
77
81
entry. set_leading ( if leading. is_empty ( ) { " " } else { leading } ) ;
78
82
entry. set_value_repr ( raw) ;
79
83
Ok ( ( input, entry) )
80
84
}
81
85
82
86
fn argument ( input : & str ) -> IResult < & str , KdlEntry , KdlParseError < & str > > {
83
87
let ( input, leading) = recognize ( many0 ( node_space) ) ( input) ?;
88
+ let ( input, ty) = opt ( annotation) ( input) ?;
84
89
let ( input, ( raw, value) ) = value ( input) ?;
85
90
let mut entry = KdlEntry :: new ( value) ;
91
+ entry. ty = ty;
86
92
entry. set_leading ( if leading. is_empty ( ) { " " } else { leading } ) ;
87
93
entry. set_value_repr ( raw) ;
88
94
Ok ( ( input, entry) )
@@ -110,6 +116,13 @@ fn children(input: &str) -> IResult<&str, (&str, KdlDocument), KdlParseError<&st
110
116
Ok ( ( input, ( before, children) ) )
111
117
}
112
118
119
+ fn annotation ( input : & str ) -> IResult < & str , KdlIdentifier , KdlParseError < & str > > {
120
+ let ( input, _) = tag ( "(" ) ( input) ?;
121
+ let ( input, ty) = identifier ( input) ?;
122
+ let ( input, _) = tag ( ")" ) ( input) ?;
123
+ Ok ( ( input, ty) )
124
+ }
125
+
113
126
fn all_whitespace ( input : & str ) -> IResult < & str , & str , KdlParseError < & str > > {
114
127
recognize ( many0 ( alt ( ( comment, unicode_space, newline) ) ) ) ( input)
115
128
}
0 commit comments