File tree 4 files changed +29
-11
lines changed
fluent-bundle/src/resolver
4 files changed +29
-11
lines changed Original file line number Diff line number Diff line change @@ -32,8 +32,8 @@ impl<'bundle> WriteValue<'bundle> for ast::Expression<&'bundle str> {
32
32
FluentValue :: String ( _) | FluentValue :: Number ( _) => {
33
33
for variant in variants {
34
34
let key = match variant. key {
35
- ast:: VariantKey :: Identifier { name } => name. into ( ) ,
36
- ast:: VariantKey :: NumberLiteral { value } => {
35
+ ast:: VariantKey :: Identifier { name, .. } => name. into ( ) ,
36
+ ast:: VariantKey :: NumberLiteral { value, .. } => {
37
37
FluentValue :: try_number ( value)
38
38
}
39
39
} ;
Original file line number Diff line number Diff line change @@ -785,8 +785,16 @@ pub struct Variant<S> {
785
785
#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
786
786
#[ cfg_attr( feature = "serde" , serde( tag = "type" ) ) ]
787
787
pub enum VariantKey < S > {
788
- Identifier { name : S } ,
789
- NumberLiteral { value : S } ,
788
+ Identifier {
789
+ name : S ,
790
+ #[ cfg( feature = "spans" ) ]
791
+ span : Span ,
792
+ } ,
793
+ NumberLiteral {
794
+ value : S ,
795
+ #[ cfg( feature = "spans" ) ]
796
+ span : Span ,
797
+ } ,
790
798
}
791
799
792
800
/// Fluent [`Comment`].
@@ -1539,12 +1547,12 @@ pub enum Expression<S> {
1539
1547
///
1540
1548
/// ```
1541
1549
/// #![cfg(feature = "spans")]
1542
- ///
1550
+ ///
1543
1551
/// use fluent_syntax::parser;
1544
1552
/// use fluent_syntax::ast::*;
1545
- ///
1553
+ ///
1546
1554
/// let ftl = "hello-world = Hello, World!";
1547
- ///
1555
+ ///
1548
1556
/// let resource = parser::parse(ftl).expect("Failed to parse an FTL resource.");
1549
1557
/// let Entry::Message(Message { ref id, .. }) = resource.body[0] else { unreachable!() };
1550
1558
///
@@ -1563,4 +1571,4 @@ impl Deref for Span {
1563
1571
fn deref ( & self ) -> & Self :: Target {
1564
1572
& self . 0
1565
1573
}
1566
- }
1574
+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use super::{
3
3
errors:: { ErrorKind , ParserError } ,
4
4
slice:: Slice ,
5
5
} ;
6
- use crate :: ast;
6
+ use crate :: ast:: { self , Span } ;
7
7
8
8
pub type Result < T > = std:: result:: Result < T , ParserError > ;
9
9
@@ -248,12 +248,22 @@ where
248
248
self . skip_blank ( ) ;
249
249
250
250
let key = if self . is_number_start ( ) {
251
+ #[ cfg( feature = "spans" ) ]
252
+ let start = self . ptr ;
253
+
251
254
ast:: VariantKey :: NumberLiteral {
252
255
value : self . get_number_literal ( ) ?,
256
+ #[ cfg( feature = "spans" ) ]
257
+ span : Span ( start..self . ptr ) ,
253
258
}
254
259
} else {
260
+ #[ cfg( feature = "spans" ) ]
261
+ let start = self . ptr ;
262
+
255
263
ast:: VariantKey :: Identifier {
256
264
name : self . get_identifier ( ) ?. name ,
265
+ #[ cfg( feature = "spans" ) ]
266
+ span : Span ( start..self . ptr ) ,
257
267
}
258
268
} ;
259
269
Original file line number Diff line number Diff line change @@ -325,7 +325,7 @@ impl Serializer {
325
325
326
326
fn serialize_variant_key < ' s , S : Slice < ' s > > ( & mut self , key : & VariantKey < S > ) {
327
327
match key {
328
- VariantKey :: NumberLiteral { value } | VariantKey :: Identifier { name : value } => {
328
+ VariantKey :: NumberLiteral { value, .. } | VariantKey :: Identifier { name : value, .. } => {
329
329
self . writer . write_literal ( value. as_ref ( ) ) ;
330
330
}
331
331
}
@@ -577,7 +577,7 @@ mod test {
577
577
let mut ast = parse ( message) . expect ( "failed to parse ftl resource" ) ;
578
578
579
579
let one_variant = Variant {
580
- key : VariantKey :: Identifier { name : "one" } ,
580
+ key : VariantKey :: Identifier { name : "one" , span : Span :: default ( ) } ,
581
581
value : Pattern {
582
582
elements : vec ! [
583
583
PatternElement :: Placeable {
You can’t perform that action at this time.
0 commit comments