66
77use super :: tokenizer:: Kind :: * ;
88use super :: tokenizer:: * ;
9- use crate :: ast:: Ident ;
10- use crate :: data:: { DiagnosticHandler , DiagnosticResult , Symbol } ;
9+ use crate :: ast:: { AttributeDesignator , Ident } ;
10+ use crate :: data:: { DiagnosticHandler , DiagnosticResult , Symbol , WithPos } ;
1111
1212pub struct TokenStream < ' a > {
1313 tokenizer : Tokenizer < ' a > ,
@@ -18,14 +18,6 @@ impl<'a> TokenStream<'a> {
1818 TokenStream { tokenizer }
1919 }
2020
21- pub fn subtype_sym ( & self ) -> & Symbol {
22- self . tokenizer . subtype_sym ( )
23- }
24-
25- pub fn range_sym ( & self ) -> & Symbol {
26- self . tokenizer . range_sym ( )
27- }
28-
2921 pub fn reverse_range_sym ( & self ) -> & Symbol {
3022 self . tokenizer . reverse_range_sym ( )
3123 }
@@ -140,16 +132,24 @@ impl<'a> TokenStream<'a> {
140132
141133 /// Expect identifier or subtype/range keywords
142134 /// foo'subtype or foo'range
143- pub fn expect_attribute_designator ( & mut self ) -> DiagnosticResult < Ident > {
135+ pub fn expect_attribute_designator (
136+ & mut self ,
137+ ) -> DiagnosticResult < WithPos < AttributeDesignator > > {
144138 let token = self . expect ( ) ?;
145- match_token_kind ! (
139+ let des = try_token_kind ! (
146140 token,
147- Identifier => token. expect_ident( ) ,
148- Subtype => Ok ( Ident { item: self . tokenizer. subtype_sym( ) . clone( ) ,
149- pos: token. pos} ) ,
150- Range => Ok ( Ident { item: self . range_sym( ) . clone( ) ,
151- pos: token. pos} )
152- )
141+ Identifier => {
142+ let ident = token. expect_ident( ) ?;
143+ if & ident. item == self . reverse_range_sym( ) {
144+ ident. map_into( |_| AttributeDesignator :: ReverseRange )
145+ } else {
146+ ident. map_into( AttributeDesignator :: Ident )
147+ }
148+ } ,
149+ Subtype => WithPos :: new( AttributeDesignator :: Subtype , token. pos) ,
150+ Range => WithPos :: new( AttributeDesignator :: Range , token. pos)
151+ ) ;
152+ Ok ( des)
153153 }
154154}
155155
0 commit comments