1use crate::resource_table::{PathId, TokenId};
2use crate::veryl_grammar_trait::*;
3use crate::veryl_token::{Token, TokenSource, VerylToken};
4use paste::paste;
5
6#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct TokenRange {
8 pub beg: Token,
9 pub end: Token,
10}
11
12impl TokenRange {
13 pub fn new(beg: &VerylToken, end: &VerylToken) -> Self {
14 Self {
15 beg: beg.token,
16 end: end.token,
17 }
18 }
19
20 pub fn from_range(beg: &TokenRange, end: &TokenRange) -> Self {
21 Self {
22 beg: beg.beg,
23 end: end.end,
24 }
25 }
26
27 pub fn include(&self, path: PathId, line: u32, column: u32) -> bool {
28 if self.beg.source == path {
29 if self.beg.line == line {
30 if self.end.line == line {
31 self.beg.column <= column && column <= self.end.column
32 } else {
33 self.beg.column <= column
34 }
35 } else if self.end.line == line {
36 column <= self.end.column
37 } else {
38 self.beg.line < line && line < self.end.line
39 }
40 } else {
41 false
42 }
43 }
44
45 pub fn offset(&mut self, value: u32) {
46 self.beg.pos += value;
47 self.end.pos += value;
48 }
49
50 pub fn set_beg(&mut self, value: TokenRange) {
51 self.beg = value.beg;
52 }
53
54 pub fn set_end(&mut self, value: TokenRange) {
55 self.end = value.end;
56 }
57
58 pub fn source(&self) -> TokenSource {
59 self.beg.source
60 }
61}
62
63impl From<&TokenRange> for miette::SourceSpan {
64 fn from(x: &TokenRange) -> Self {
65 let length = (x.end.pos - x.beg.pos + x.end.length) as usize;
66 (x.beg.pos as usize, length).into()
67 }
68}
69
70impl From<TokenRange> for miette::SourceSpan {
71 fn from(x: TokenRange) -> Self {
72 let length = (x.end.pos - x.beg.pos + x.end.length) as usize;
73 (x.beg.pos as usize, length).into()
74 }
75}
76
77impl From<Token> for TokenRange {
78 fn from(value: Token) -> Self {
79 let beg = value;
80 let end = value;
81 TokenRange { beg, end }
82 }
83}
84
85impl From<&Token> for TokenRange {
86 fn from(value: &Token) -> Self {
87 let beg = *value;
88 let end = *value;
89 TokenRange { beg, end }
90 }
91}
92
93impl From<&VerylToken> for TokenRange {
94 fn from(value: &VerylToken) -> Self {
95 let beg = value.token;
96 let end = value.token;
97 TokenRange { beg, end }
98 }
99}
100
101pub trait TokenExt {
102 fn range(&self) -> TokenRange;
103 fn first(&self) -> Token {
104 self.range().beg
105 }
106 fn last(&self) -> Token {
107 self.range().end
108 }
109 fn id(&self) -> TokenId {
110 self.first().id
111 }
112 fn line(&self) -> u32 {
113 self.first().line
114 }
115}
116
117macro_rules! impl_token_ext {
118 ($typename:ty) => {
119 impl TokenExt for $typename {
120 fn range(&self) -> TokenRange {
121 self.into()
122 }
123 }
124 };
125}
126
127macro_rules! impl_token_range {
128 ($typename:ty, $first:ident, $last:ident) => {
129 impl From<&$typename> for TokenRange {
130 fn from(value: &$typename) -> Self {
131 let beg: TokenRange = value.$first.as_ref().into();
132 let end: TokenRange = value.$last.as_ref().into();
133 TokenRange {
134 beg: beg.beg,
135 end: end.end,
136 }
137 }
138 }
139 impl_token_ext!($typename);
140 };
141 ($typename:ty, $first:ident) => {
142 impl From<&$typename> for TokenRange {
143 fn from(value: &$typename) -> Self {
144 value.$first.as_ref().into()
145 }
146 }
147 impl_token_ext!($typename);
148 };
149}
150
151macro_rules! impl_token_range_singular {
152 ($typename:ty) => {
153 paste! {
154 impl From<&$typename> for TokenRange {
155 fn from(value: &$typename) -> Self {
156 let beg = value.[<$typename:snake _token>].token;
157 let end = beg;
158 TokenRange { beg, end }
159 }
160 }
161 impl_token_ext!($typename);
162 }
163 };
164}
165
166macro_rules! impl_token_range_enum {
167 ($typename:ty, $( $x:ident ),*) => {
168 paste! {
169 impl From<&$typename> for TokenRange {
170 fn from(value: &$typename) -> Self {
171 match value {
172 $(
173 $typename::[<$x:camel>](x) => x.$x.as_ref().into()
174 ),*
175 }
176 }
177 }
178 impl_token_ext!($typename);
179 }
180 };
181}
182
183macro_rules! expression_token_range {
184 ($typename:ty, $beg:ident, $list:ident, $prev:ident) => {
185 impl From<&$typename> for TokenRange {
186 fn from(value: &$typename) -> Self {
187 let beg: TokenRange = value.$beg.as_ref().into();
188 let end = if value.$list.is_empty() {
189 beg.end
190 } else {
191 let last = value.$list.last().unwrap();
192 let end: TokenRange = last.$prev.as_ref().into();
193 end.end
194 };
195 let beg = beg.beg;
196 TokenRange { beg, end }
197 }
198 }
199 impl_token_ext!($typename);
200 };
201}
202
203macro_rules! impl_token_range_list {
204 ($typename:ty, $item:ty) => {
205 paste! {
206 impl From<&$typename> for TokenRange {
207 fn from(value: &$typename) -> Self {
208 let mut ret: TokenRange = value.[<$item:snake>].as_ref().into();
209 if let Some(x) = value.[<$typename:snake _list>].last() {
210 let end: TokenRange = x.[<$item:snake>].as_ref().into();
211 ret.end = end.end;
212 }
213 if let Some(x) = &value.[<$typename:snake _opt>] {
214 let end: TokenRange = x.comma.as_ref().into();
215 ret.end = end.end;
216 }
217 ret
218 }
219 }
220 impl_token_ext!($typename);
221 }
222 };
223}
224
225macro_rules! impl_token_range_group {
226 ($typename:ty, $item:ty) => {
227 paste! {
228 impl From<&$typename> for TokenRange {
229 fn from(value: &$typename) -> Self {
230 let mut ret: TokenRange = match value.[<$typename:snake _group>].as_ref() {
231 [<$typename Group>]::[<LBrace $typename GroupListRBrace>](x) => {
232 let beg = x.l_brace.l_brace_token.token;
233 let end = x.r_brace.r_brace_token.token;
234 TokenRange { beg, end }
235 }
236 [<$typename Group>]::$item(x) => x.[<$item:snake>].as_ref().into(),
237 };
238 if let Some(x) = value.[<$typename:snake _list>].first() {
239 let beg: TokenRange = x.attribute.as_ref().into();
240 ret.beg = beg.beg;
241 }
242 ret
243 }
244 }
245 impl_token_ext!($typename);
246 }
247 };
248 ($typename:ty, $list:ty, $item:ty) => {
249 paste! {
250 impl From<&$typename> for TokenRange {
251 fn from(value: &$typename) -> Self {
252 let mut ret: TokenRange = match value.[<$typename:snake _group>].as_ref() {
253 [<$typename Group>]::[<LBrace $list RBrace>](x) => {
254 let beg = x.l_brace.l_brace_token.token;
255 let end = x.r_brace.r_brace_token.token;
256 TokenRange { beg, end }
257 }
258 [<$typename Group>]::$item(x) => x.[<$item:snake>].as_ref().into(),
259 };
260 if let Some(x) = value.[<$typename:snake _list>].first() {
261 let beg: TokenRange = x.attribute.as_ref().into();
262 ret.beg = beg.beg;
263 }
264 ret
265 }
266 }
267 impl_token_ext!($typename);
268 }
269 };
270}
271
272impl_token_range_singular!(Start);
278
279impl_token_range_singular!(StringLiteral);
281
282impl_token_range_singular!(Exponent);
284impl_token_range_singular!(FixedPoint);
285impl_token_range_singular!(Based);
286impl_token_range_singular!(BaseLess);
287impl_token_range_singular!(AllBit);
288
289impl_token_range_singular!(AssignmentOperator);
291impl_token_range_singular!(DiamondOperator);
292impl_token_range_singular!(Operator01);
293impl_token_range_singular!(Operator02);
294impl_token_range_singular!(Operator03);
295impl_token_range_singular!(Operator04);
296impl_token_range_singular!(Operator05);
297impl_token_range_singular!(Operator06);
298impl_token_range_singular!(Operator07);
299impl_token_range_singular!(Operator08);
300impl_token_range_singular!(UnaryOperator);
301
302impl_token_range_singular!(Colon);
304impl_token_range_singular!(ColonColonLAngle);
305impl_token_range_singular!(ColonColon);
306impl_token_range_singular!(Comma);
307impl_token_range_singular!(DotDot);
308impl_token_range_singular!(DotDotEqu);
309impl_token_range_singular!(Dot);
310impl_token_range_singular!(Equ);
311impl_token_range_singular!(HashLBracket);
312impl_token_range_singular!(Hash);
313impl_token_range_singular!(Question);
314impl_token_range_singular!(Quote);
315impl_token_range_singular!(QuoteLBrace);
316impl_token_range_singular!(LAngle);
317impl_token_range_singular!(EmbedLBrace);
318impl_token_range_singular!(EscapedLBrace);
319impl_token_range_singular!(TripleLBrace);
320impl_token_range_singular!(LBrace);
321impl_token_range_singular!(LBracket);
322impl_token_range_singular!(LParen);
323impl_token_range_singular!(LTMinus);
324impl_token_range_singular!(MinusColon);
325impl_token_range_singular!(MinusGT);
326impl_token_range_singular!(PlusColon);
327impl_token_range_singular!(RAngle);
328impl_token_range_singular!(EmbedRBrace);
329impl_token_range_singular!(EscapedRBrace);
330impl_token_range_singular!(TripleRBrace);
331impl_token_range_singular!(RBrace);
332impl_token_range_singular!(RBracket);
333impl_token_range_singular!(RParen);
334impl_token_range_singular!(Semicolon);
335impl_token_range_singular!(Star);
336
337impl_token_range_singular!(Alias);
339impl_token_range_singular!(AlwaysComb);
340impl_token_range_singular!(AlwaysFf);
341impl_token_range_singular!(As);
342impl_token_range_singular!(Assign);
343impl_token_range_singular!(Bind);
344impl_token_range_singular!(Bit);
345impl_token_range_singular!(BBool);
346impl_token_range_singular!(LBool);
347impl_token_range_singular!(Break);
348impl_token_range_singular!(Case);
349impl_token_range_singular!(Clock);
350impl_token_range_singular!(ClockPosedge);
351impl_token_range_singular!(ClockNegedge);
352impl_token_range_singular!(Connect);
353impl_token_range_singular!(Const);
354impl_token_range_singular!(Converse);
355
356impl From<&Defaul> for TokenRange {
357 fn from(value: &Defaul) -> Self {
358 let beg = value.default_token.token;
359 let end = beg;
360 TokenRange { beg, end }
361 }
362}
363impl_token_ext!(Defaul);
364
365impl_token_range_singular!(Else);
366impl_token_range_singular!(Embed);
367impl_token_range_singular!(Enum);
368impl_token_range_singular!(F32);
369impl_token_range_singular!(F64);
370impl_token_range_singular!(False);
371impl_token_range_singular!(Final);
372impl_token_range_singular!(For);
373impl_token_range_singular!(Function);
374impl_token_range_singular!(Gen);
375impl_token_range_singular!(I8);
376impl_token_range_singular!(I16);
377impl_token_range_singular!(I32);
378impl_token_range_singular!(I64);
379impl_token_range_singular!(If);
380impl_token_range_singular!(IfReset);
381impl_token_range_singular!(Import);
382impl_token_range_singular!(In);
383impl_token_range_singular!(Include);
384impl_token_range_singular!(Initial);
385impl_token_range_singular!(Inout);
386impl_token_range_singular!(Input);
387impl_token_range_singular!(Inside);
388impl_token_range_singular!(Inst);
389impl_token_range_singular!(Interface);
390impl_token_range_singular!(Let);
391impl_token_range_singular!(Logic);
392impl_token_range_singular!(Lsb);
393impl_token_range_singular!(Modport);
394impl_token_range_singular!(Module);
395impl_token_range_singular!(Msb);
396impl_token_range_singular!(Output);
397impl_token_range_singular!(Outside);
398impl_token_range_singular!(Package);
399impl_token_range_singular!(Param);
400impl_token_range_singular!(Proto);
401impl_token_range_singular!(Pub);
402impl_token_range_singular!(Repeat);
403impl_token_range_singular!(Reset);
404impl_token_range_singular!(ResetAsyncHigh);
405impl_token_range_singular!(ResetAsyncLow);
406impl_token_range_singular!(ResetSyncHigh);
407impl_token_range_singular!(ResetSyncLow);
408impl_token_range_singular!(Return);
409impl_token_range_singular!(Same);
410impl_token_range_singular!(Signed);
411impl_token_range_singular!(Step);
412
413impl From<&Strin> for TokenRange {
414 fn from(value: &Strin) -> Self {
415 let beg = value.string_token.token;
416 let end = beg;
417 TokenRange { beg, end }
418 }
419}
420impl_token_ext!(Strin);
421
422impl_token_range_singular!(Struct);
423impl_token_range_singular!(Switch);
424impl_token_range_singular!(Tri);
425impl_token_range_singular!(True);
426impl_token_range_singular!(Type);
427impl_token_range_singular!(P8);
428impl_token_range_singular!(P16);
429impl_token_range_singular!(P32);
430impl_token_range_singular!(P64);
431impl_token_range_singular!(U8);
432impl_token_range_singular!(U16);
433impl_token_range_singular!(U32);
434impl_token_range_singular!(U64);
435impl_token_range_singular!(Union);
436impl_token_range_singular!(Unsafe);
437impl_token_range_singular!(Var);
438
439impl_token_range_singular!(DollarIdentifier);
441impl_token_range_singular!(Identifier);
442
443impl_token_range_singular!(Any);
444
445impl_token_range_enum!(Number, integral_number, real_number);
450impl_token_range_enum!(IntegralNumber, based, base_less, all_bit);
451impl_token_range_enum!(RealNumber, fixed_point, exponent);
452
453impl From<&HierarchicalIdentifier> for TokenRange {
458 fn from(value: &HierarchicalIdentifier) -> Self {
459 let mut ret: TokenRange = value.identifier.as_ref().into();
460 if let Some(x) = value.hierarchical_identifier_list.last() {
461 ret.set_end(x.select.as_ref().into());
462 }
463 if let Some(x) = value.hierarchical_identifier_list0.last() {
464 ret.set_end(x.identifier.as_ref().into());
465 if let Some(x) = x.hierarchical_identifier_list0_list.last() {
466 ret.set_end(x.select.as_ref().into());
467 }
468 }
469 ret
470 }
471}
472impl_token_ext!(HierarchicalIdentifier);
473
474impl From<&ScopedIdentifier> for TokenRange {
475 fn from(value: &ScopedIdentifier) -> Self {
476 let mut ret: TokenRange = match value.scoped_identifier_group.as_ref() {
477 ScopedIdentifierGroup::DollarIdentifier(x) => x.dollar_identifier.as_ref().into(),
478 ScopedIdentifierGroup::IdentifierScopedIdentifierOpt(x) => {
479 let mut ret: TokenRange = x.identifier.as_ref().into();
480 if let Some(x) = &x.scoped_identifier_opt {
481 ret.set_end(x.with_generic_argument.as_ref().into());
482 }
483 ret
484 }
485 };
486 if let Some(x) = value.scoped_identifier_list.last() {
487 ret.set_end(x.identifier.as_ref().into());
488 if let Some(x) = &x.scoped_identifier_opt0 {
489 ret.set_end(x.with_generic_argument.as_ref().into());
490 }
491 }
492 ret
493 }
494}
495impl_token_ext!(ScopedIdentifier);
496
497impl From<&ExpressionIdentifier> for TokenRange {
498 fn from(value: &ExpressionIdentifier) -> Self {
499 let mut ret: TokenRange = value.scoped_identifier.as_ref().into();
500 if let Some(x) = &value.expression_identifier_opt {
501 ret.set_end(x.width.as_ref().into());
502 }
503 if let Some(x) = &value.expression_identifier_list.last() {
504 ret.set_end(x.select.as_ref().into());
505 }
506 if let Some(x) = &value.expression_identifier_list0.last() {
507 ret.set_end(x.identifier.as_ref().into());
508 if let Some(x) = &x.expression_identifier_list0_list.last() {
509 ret.set_end(x.select.as_ref().into());
510 }
511 }
512 ret
513 }
514}
515impl_token_ext!(ExpressionIdentifier);
516
517impl From<&GenericArgIdentifier> for TokenRange {
518 fn from(value: &GenericArgIdentifier) -> Self {
519 let mut ret: TokenRange = value.scoped_identifier.as_ref().into();
520 if let Some(x) = &value.generic_arg_identifier_list.last() {
521 ret.set_end(x.identifier.as_ref().into());
522 }
523 ret
524 }
525}
526impl_token_ext!(GenericArgIdentifier);
527
528impl_token_range!(Expression, if_expression);
533
534impl From<&IfExpression> for TokenRange {
535 fn from(value: &IfExpression) -> Self {
536 let mut ret: TokenRange = value.expression01.as_ref().into();
537 if let Some(x) = value.if_expression_list.first() {
538 ret.set_beg(x.r#if.as_ref().into());
539 }
540 ret
541 }
542}
543impl_token_ext!(IfExpression);
544
545expression_token_range!(Expression01, expression02, expression01_list, expression02);
546
547impl From<&Expression02> for TokenRange {
548 fn from(value: &Expression02) -> Self {
549 let mut ret: TokenRange = value.factor.as_ref().into();
550 if let Some(ref x) = value.expression02_opt {
551 ret.set_end(x.casting_type.as_ref().into());
552 };
553 if let Some(x) = value.expression02_list.first() {
554 ret.set_beg(match x.expression02_op.as_ref() {
555 Expression02Op::UnaryOperator(x) => x.unary_operator.as_ref().into(),
556 Expression02Op::Operator06(x) => x.operator06.as_ref().into(),
557 Expression02Op::Operator05(x) => x.operator05.as_ref().into(),
558 Expression02Op::Operator03(x) => x.operator03.as_ref().into(),
559 Expression02Op::Operator04(x) => x.operator04.as_ref().into(),
560 });
561 }
562 ret
563 }
564}
565impl_token_ext!(Expression02);
566
567impl From<&Factor> for TokenRange {
568 fn from(value: &Factor) -> Self {
569 match value {
570 Factor::Number(x) => x.number.as_ref().into(),
571 Factor::BooleanLiteral(x) => x.boolean_literal.as_ref().into(),
572 Factor::IdentifierFactor(x) => {
573 x.identifier_factor.expression_identifier.as_ref().into()
574 }
575 Factor::LParenExpressionRParen(x) => {
576 let beg = x.l_paren.l_paren_token.token;
577 let end = x.r_paren.r_paren_token.token;
578 TokenRange { beg, end }
579 }
580 Factor::LBraceConcatenationListRBrace(x) => {
581 let beg = x.l_brace.l_brace_token.token;
582 let end = x.r_brace.r_brace_token.token;
583 TokenRange { beg, end }
584 }
585 Factor::QuoteLBraceArrayLiteralListRBrace(x) => {
586 let beg = x.quote_l_brace.quote_l_brace_token.token;
587 let end = x.r_brace.r_brace_token.token;
588 TokenRange { beg, end }
589 }
590 Factor::CaseExpression(x) => x.case_expression.as_ref().into(),
591 Factor::SwitchExpression(x) => x.switch_expression.as_ref().into(),
592 Factor::StringLiteral(x) => x.string_literal.as_ref().into(),
593 Factor::FactorGroup(x) => match x.factor_group.as_ref() {
594 FactorGroup::Msb(x) => x.msb.as_ref().into(),
595 FactorGroup::Lsb(x) => x.lsb.as_ref().into(),
596 },
597 Factor::InsideExpression(x) => x.inside_expression.as_ref().into(),
598 Factor::OutsideExpression(x) => x.outside_expression.as_ref().into(),
599 Factor::TypeExpression(x) => x.type_expression.as_ref().into(),
600 Factor::FactorTypeFactor(x) => x.factor_type_factor.as_ref().into(),
601 }
602 }
603}
604impl_token_ext!(Factor);
605
606impl_token_range_enum!(BooleanLiteral, r#true, r#false);
607
608impl From<&IdentifierFactor> for TokenRange {
609 fn from(value: &IdentifierFactor) -> Self {
610 let mut ret: TokenRange = value.expression_identifier.as_ref().into();
611 if let Some(x) = &value.identifier_factor_opt {
612 ret.set_end(match x.identifier_factor_opt_group.as_ref() {
613 IdentifierFactorOptGroup::FunctionCall(x) => x.function_call.as_ref().into(),
614 IdentifierFactorOptGroup::StructConstructor(x) => {
615 x.struct_constructor.as_ref().into()
616 }
617 });
618 }
619 ret
620 }
621}
622impl_token_ext!(IdentifierFactor);
623
624impl From<&FactorTypeFactor> for TokenRange {
625 fn from(value: &FactorTypeFactor) -> Self {
626 let beg: TokenRange = if let Some(x) = value.factor_type_factor_list.first() {
627 x.type_modifier.as_ref().into()
628 } else {
629 value.factor_type.as_ref().into()
630 };
631 let end: TokenRange = value.factor_type.as_ref().into();
632 TokenRange {
633 beg: beg.beg,
634 end: end.end,
635 }
636 }
637}
638impl_token_ext!(FactorTypeFactor);
639
640impl_token_range!(FunctionCall, l_paren, r_paren);
641impl_token_range_list!(ArgumentList, ArgumentItem);
642
643impl From<&ArgumentItem> for TokenRange {
644 fn from(value: &ArgumentItem) -> Self {
645 let mut ret: TokenRange = value.argument_expression.as_ref().into();
646 if let Some(x) = &value.argument_item_opt {
647 ret.set_end(x.expression.as_ref().into());
648 }
649 ret
650 }
651}
652impl_token_ext!(ArgumentItem);
653
654impl_token_range!(ArgumentExpression, expression);
655impl_token_range!(StructConstructor, quote_l_brace, r_brace);
656impl_token_range_list!(StructConstructorList, StructConstructorItem);
657impl_token_range!(StructConstructorItem, identifier, expression);
658impl_token_range_list!(ConcatenationList, ConcatenationItem);
659
660impl From<&ConcatenationItem> for TokenRange {
661 fn from(value: &ConcatenationItem) -> Self {
662 let mut ret: TokenRange = value.expression.as_ref().into();
663 if let Some(x) = &value.concatenation_item_opt {
664 ret.set_end(x.expression.as_ref().into());
665 }
666 ret
667 }
668}
669impl_token_ext!(ConcatenationItem);
670
671impl_token_range_list!(ArrayLiteralList, ArrayLiteralItem);
672
673impl From<&ArrayLiteralItem> for TokenRange {
674 fn from(value: &ArrayLiteralItem) -> Self {
675 match value.array_literal_item_group.as_ref() {
676 ArrayLiteralItemGroup::ExpressionArrayLiteralItemOpt(x) => {
677 let mut ret: TokenRange = x.expression.as_ref().into();
678 if let Some(x) = &x.array_literal_item_opt {
679 ret.set_end(x.expression.as_ref().into());
680 }
681 ret
682 }
683 ArrayLiteralItemGroup::DefaulColonExpression(x) => {
684 let beg: TokenRange = x.defaul.as_ref().into();
685 let end: TokenRange = x.expression.as_ref().into();
686 TokenRange {
687 beg: beg.beg,
688 end: end.end,
689 }
690 }
691 }
692 }
693}
694impl_token_ext!(ArrayLiteralItem);
695
696impl_token_range!(CaseExpression, case, r_brace);
697impl_token_range!(SwitchExpression, switch, r_brace);
698impl_token_range!(TypeExpression, r#type, r_paren);
699impl_token_range!(InsideExpression, inside, r_brace);
700impl_token_range!(OutsideExpression, outside, r_brace);
701impl_token_range_list!(RangeList, RangeItem);
702impl_token_range!(RangeItem, range);
703
704impl_token_range!(Select, l_bracket, r_bracket);
709impl_token_range_enum!(SelectOperator, colon, plus_colon, minus_colon, step);
710impl_token_range!(Width, l_angle, r_angle);
711impl_token_range!(Array, l_bracket, r_bracket);
712
713impl From<&Range> for TokenRange {
714 fn from(value: &Range) -> Self {
715 let mut ret: TokenRange = value.expression.as_ref().into();
716 if let Some(x) = &value.range_opt {
717 ret.set_end(x.expression.as_ref().into());
718 }
719 ret
720 }
721}
722impl_token_ext!(Range);
723
724impl_token_range_enum!(RangeOperator, dot_dot, dot_dot_equ);
725
726impl_token_range_enum!(
731 FixedType, p8, p16, p32, p64, u8, u16, u32, u64, i32, i8, i16, i64, f32, f64, b_bool, l_bool,
732 strin
733);
734impl_token_range_enum!(
735 VariableType,
736 clock,
737 clock_posedge,
738 clock_negedge,
739 reset,
740 reset_async_high,
741 reset_async_low,
742 reset_sync_high,
743 reset_sync_low,
744 logic,
745 bit
746);
747impl_token_range!(UserDefinedType, scoped_identifier);
748impl_token_range_enum!(TypeModifier, tri, signed, defaul);
749
750impl From<&FactorType> for TokenRange {
751 fn from(value: &FactorType) -> Self {
752 match value.factor_type_group.as_ref() {
753 FactorTypeGroup::VariableTypeFactorTypeOpt(x) => {
754 let mut ret: TokenRange = x.variable_type.as_ref().into();
755 if let Some(ref x) = x.factor_type_opt {
756 ret.set_end(x.width.as_ref().into());
757 }
758 ret
759 }
760 FactorTypeGroup::FixedType(x) => x.fixed_type.as_ref().into(),
761 }
762 }
763}
764impl_token_ext!(FactorType);
765
766impl From<&ScalarType> for TokenRange {
767 fn from(value: &ScalarType) -> Self {
768 let mut ret: TokenRange = match &*value.scalar_type_group {
769 ScalarTypeGroup::UserDefinedTypeScalarTypeOpt(x) => {
770 let mut ret: TokenRange = x.user_defined_type.as_ref().into();
771 if let Some(x) = &x.scalar_type_opt {
772 ret.set_end(x.width.as_ref().into());
773 }
774 ret
775 }
776 ScalarTypeGroup::FactorType(x) => x.factor_type.as_ref().into(),
777 };
778
779 if let Some(x) = value.scalar_type_list.first() {
780 ret.set_beg(x.type_modifier.as_ref().into());
781 }
782
783 ret
784 }
785}
786impl_token_ext!(ScalarType);
787
788impl From<&ArrayType> for TokenRange {
789 fn from(value: &ArrayType) -> Self {
790 let mut ret: TokenRange = value.scalar_type.as_ref().into();
791 if let Some(x) = &value.array_type_opt {
792 ret.set_end(x.array.as_ref().into());
793 }
794 ret
795 }
796}
797impl_token_ext!(ArrayType);
798
799impl_token_range_enum!(
800 CastingType,
801 p8,
802 p16,
803 p32,
804 p64,
805 u8,
806 u16,
807 u32,
808 u64,
809 i8,
810 i16,
811 i32,
812 i64,
813 f32,
814 f64,
815 b_bool,
816 l_bool,
817 clock,
818 clock_posedge,
819 clock_negedge,
820 reset,
821 reset_async_high,
822 reset_async_low,
823 reset_sync_high,
824 reset_sync_low,
825 user_defined_type,
826 based,
827 base_less
828);
829
830impl_token_range!(ClockDomain, quote, identifier);
835
836impl_token_range!(StatementBlock, l_brace, r_brace);
841
842impl From<&StatementBlockGroup> for TokenRange {
843 fn from(value: &StatementBlockGroup) -> Self {
844 let mut ret: TokenRange = match value.statement_block_group_group.as_ref() {
845 StatementBlockGroupGroup::BlockLBraceStatementBlockGroupGroupListRBrace(x) => {
846 let beg = x.block.block_token.token;
847 let end = x.r_brace.r_brace_token.token;
848 TokenRange { beg, end }
849 }
850 StatementBlockGroupGroup::StatementBlockItem(x) => {
851 x.statement_block_item.as_ref().into()
852 }
853 };
854 if let Some(x) = value.statement_block_group_list.first() {
855 let beg: TokenRange = x.attribute.as_ref().into();
856 ret.beg = beg.beg;
857 }
858 ret
859 }
860}
861impl_token_ext!(StatementBlockGroup);
862
863impl_token_range_enum!(
864 StatementBlockItem,
865 var_declaration,
866 let_statement,
867 statement,
868 const_declaration,
869 gen_declaration,
870 concatenation_assignment
871);
872impl_token_range_enum!(
873 Statement,
874 identifier_statement,
875 if_statement,
876 if_reset_statement,
877 return_statement,
878 break_statement,
879 for_statement,
880 case_statement,
881 switch_statement
882);
883impl_token_range!(LetStatement, r#let, semicolon);
884impl_token_range!(ConcatenationAssignment, l_brace, semicolon);
885impl_token_range!(IdentifierStatement, expression_identifier, semicolon);
886
887impl From<&Assignment> for TokenRange {
888 fn from(value: &Assignment) -> Self {
889 let mut ret: TokenRange = match value.assignment_group.as_ref() {
890 AssignmentGroup::Equ(x) => x.equ.as_ref().into(),
891 AssignmentGroup::AssignmentOperator(x) => x.assignment_operator.as_ref().into(),
892 AssignmentGroup::DiamondOperator(x) => x.diamond_operator.as_ref().into(),
893 };
894 ret.set_end(value.expression.as_ref().into());
895 ret
896 }
897}
898impl_token_ext!(Assignment);
899
900impl From<&IfStatement> for TokenRange {
901 fn from(value: &IfStatement) -> Self {
902 let mut ret: TokenRange = value.r#if.as_ref().into();
903 ret.set_end(value.statement_block.as_ref().into());
904 if let Some(x) = value.if_statement_list.last() {
905 ret.set_end(x.statement_block.as_ref().into());
906 }
907 if let Some(x) = &value.if_statement_opt {
908 ret.set_end(x.statement_block.as_ref().into());
909 }
910 ret
911 }
912}
913impl_token_ext!(IfStatement);
914
915impl From<&IfStatementList> for TokenRange {
916 fn from(value: &IfStatementList) -> Self {
917 let mut ret: TokenRange = value.r#else.as_ref().into();
918 ret.set_end(value.statement_block.as_ref().into());
919 ret
920 }
921}
922impl_token_ext!(IfStatementList);
923
924impl From<&IfResetStatement> for TokenRange {
925 fn from(value: &IfResetStatement) -> Self {
926 let mut ret: TokenRange = value.if_reset.as_ref().into();
927 ret.set_end(value.statement_block.as_ref().into());
928 if let Some(x) = value.if_reset_statement_list.last() {
929 ret.set_end(x.statement_block.as_ref().into());
930 }
931 if let Some(x) = &value.if_reset_statement_opt {
932 ret.set_end(x.statement_block.as_ref().into());
933 }
934 ret
935 }
936}
937impl_token_ext!(IfResetStatement);
938
939impl From<&IfResetStatementList> for TokenRange {
940 fn from(value: &IfResetStatementList) -> Self {
941 let mut ret: TokenRange = value.r#else.as_ref().into();
942 ret.set_end(value.statement_block.as_ref().into());
943 ret
944 }
945}
946impl_token_ext!(IfResetStatementList);
947
948impl_token_range!(ReturnStatement, r#return, semicolon);
949impl_token_range!(BreakStatement, r#break, semicolon);
950impl_token_range!(ForStatement, r#for, statement_block);
951impl_token_range!(CaseStatement, r#case, r_brace);
952
953impl From<&CaseItem> for TokenRange {
954 fn from(value: &CaseItem) -> Self {
955 let mut ret: TokenRange = match value.case_item_group.as_ref() {
956 CaseItemGroup::CaseCondition(x) => x.case_condition.as_ref().into(),
957 CaseItemGroup::Defaul(x) => x.defaul.as_ref().into(),
958 };
959 match value.case_item_group0.as_ref() {
960 CaseItemGroup0::Statement(x) => {
961 ret.set_end(x.statement.as_ref().into());
962 }
963 CaseItemGroup0::StatementBlock(x) => {
964 ret.set_end(x.statement_block.as_ref().into());
965 }
966 }
967 ret
968 }
969}
970impl_token_ext!(CaseItem);
971
972impl From<&CaseCondition> for TokenRange {
973 fn from(value: &CaseCondition) -> Self {
974 let mut ret: TokenRange = value.range_item.as_ref().into();
975 if let Some(x) = value.case_condition_list.last() {
976 ret.set_end(x.range_item.as_ref().into());
977 }
978 ret
979 }
980}
981impl_token_ext!(CaseCondition);
982
983impl_token_range!(SwitchStatement, switch, r_brace);
984
985impl From<&SwitchItem> for TokenRange {
986 fn from(value: &SwitchItem) -> Self {
987 let mut ret: TokenRange = match value.switch_item_group.as_ref() {
988 SwitchItemGroup::SwitchCondition(x) => x.switch_condition.as_ref().into(),
989 SwitchItemGroup::Defaul(x) => x.defaul.as_ref().into(),
990 };
991 match value.switch_item_group0.as_ref() {
992 SwitchItemGroup0::Statement(x) => {
993 ret.set_end(x.statement.as_ref().into());
994 }
995 SwitchItemGroup0::StatementBlock(x) => {
996 ret.set_end(x.statement_block.as_ref().into());
997 }
998 }
999 ret
1000 }
1001}
1002impl_token_ext!(SwitchItem);
1003
1004impl From<&SwitchCondition> for TokenRange {
1005 fn from(value: &SwitchCondition) -> Self {
1006 let mut ret: TokenRange = value.expression.as_ref().into();
1007 if let Some(x) = value.switch_condition_list.last() {
1008 ret.set_end(x.expression.as_ref().into());
1009 }
1010 ret
1011 }
1012}
1013impl_token_ext!(SwitchCondition);
1014
1015impl_token_range!(Attribute, hash_l_bracket, r_bracket);
1020impl_token_range_list!(AttributeList, AttributeItem);
1021impl_token_range_enum!(AttributeItem, identifier, string_literal);
1022
1023impl_token_range!(LetDeclaration, r#let, semicolon);
1028impl_token_range!(VarDeclaration, var, semicolon);
1029impl_token_range!(ConstDeclaration, r#const, semicolon);
1030
1031impl From<&ConstDeclarationOptGroup> for TokenRange {
1032 fn from(value: &ConstDeclarationOptGroup) -> Self {
1033 match value {
1034 ConstDeclarationOptGroup::Type(x) => x.r#type.as_ref().into(),
1035 ConstDeclarationOptGroup::ArrayType(x) => x.array_type.as_ref().into(),
1036 }
1037 }
1038}
1039impl_token_ext!(ConstDeclarationOptGroup);
1040
1041impl_token_range!(GenDeclaration, r#gen, semicolon);
1042impl_token_range_enum!(GenDeclarationGroup, generic_proto_bound, r#type);
1043
1044impl_token_range!(TypeDefDeclaration, r#type, semicolon);
1045impl_token_range!(AlwaysFfDeclaration, always_ff, statement_block);
1046impl_token_range!(AlwaysFfEventList, l_paren, r_paren);
1047impl_token_range!(AlwaysFfClock, hierarchical_identifier);
1048impl_token_range!(AlwaysFfReset, hierarchical_identifier);
1049impl_token_range!(AlwaysCombDeclaration, always_comb, statement_block);
1050impl_token_range!(AssignDeclaration, assign, semicolon);
1051
1052impl From<&AssignDestination> for TokenRange {
1053 fn from(value: &AssignDestination) -> Self {
1054 match value {
1055 AssignDestination::HierarchicalIdentifier(x) => {
1056 x.hierarchical_identifier.as_ref().into()
1057 }
1058 AssignDestination::LBraceAssignConcatenationListRBrace(x) => {
1059 let beg = x.l_brace.l_brace_token.token;
1060 let end = x.r_brace.r_brace_token.token;
1061 TokenRange { beg, end }
1062 }
1063 }
1064 }
1065}
1066impl_token_ext!(AssignDestination);
1067
1068impl_token_range_list!(AssignConcatenationList, AssignConcatenationItem);
1069impl_token_range!(AssignConcatenationItem, hierarchical_identifier);
1070impl_token_range!(ConnectDeclaration, connect, semicolon);
1071impl_token_range!(ModportDeclaration, modport, r_brace);
1072impl_token_range_list!(ModportList, ModportGroup);
1073impl_token_range_group!(ModportGroup, ModportList, ModportItem);
1074impl_token_range!(ModportItem, identifier, direction);
1075
1076impl From<&ModportDefault> for TokenRange {
1077 fn from(value: &ModportDefault) -> Self {
1078 match value {
1079 ModportDefault::Input(x) => x.input.as_ref().into(),
1080 ModportDefault::Output(x) => x.output.as_ref().into(),
1081 ModportDefault::SameLParenModportDefaultListRParen(x) => {
1082 let beg = x.same.same_token.token;
1083 let end = x.r_paren.r_paren_token.token;
1084 TokenRange { beg, end }
1085 }
1086 ModportDefault::ConverseLParenModportDefaultListRParen(x) => {
1087 let beg = x.converse.converse_token.token;
1088 let end = x.r_paren.r_paren_token.token;
1089 TokenRange { beg, end }
1090 }
1091 }
1092 }
1093}
1094impl_token_ext!(ModportDefault);
1095
1096impl_token_range!(EnumDeclaration, r#enum, r_brace);
1097impl_token_range_list!(EnumList, EnumGroup);
1098impl_token_range_group!(EnumGroup, EnumList, EnumItem);
1099
1100impl From<&EnumItem> for TokenRange {
1101 fn from(value: &EnumItem) -> Self {
1102 let mut ret: TokenRange = value.identifier.as_ref().into();
1103 if let Some(x) = &value.enum_item_opt {
1104 ret.set_end(x.expression.as_ref().into());
1105 }
1106 ret
1107 }
1108}
1109impl_token_ext!(EnumItem);
1110
1111impl_token_range_enum!(StructUnion, r#struct, union);
1112impl_token_range!(StructUnionDeclaration, struct_union, r_brace);
1113impl_token_range_list!(StructUnionList, StructUnionGroup);
1114impl_token_range_group!(StructUnionGroup, StructUnionList, StructUnionItem);
1115impl_token_range!(StructUnionItem, identifier, scalar_type);
1116impl_token_range!(InitialDeclaration, initial, statement_block);
1117impl_token_range!(FinalDeclaration, r#final, statement_block);
1118
1119impl_token_range!(InstDeclaration, inst, semicolon);
1124impl_token_range!(BindDeclaration, bind, semicolon);
1125
1126impl From<&ComponentInstantiation> for TokenRange {
1127 fn from(value: &ComponentInstantiation) -> Self {
1128 let mut ret: TokenRange = value.identifier.as_ref().into();
1129 if let Some(x) = &value.component_instantiation_opt2 {
1130 ret.set_end(x.inst_port.as_ref().into());
1131 } else if let Some(x) = &value.component_instantiation_opt1 {
1132 ret.set_end(x.inst_parameter.as_ref().into());
1133 } else if let Some(x) = &value.component_instantiation_opt0 {
1134 ret.set_end(x.array.as_ref().into());
1135 } else {
1136 ret.set_end(value.scoped_identifier.as_ref().into());
1137 }
1138 ret
1139 }
1140}
1141
1142impl_token_range!(InstParameter, hash, r_paren);
1143impl_token_range_list!(InstParameterList, InstParameterGroup);
1144impl_token_range_group!(InstParameterGroup, InstParameterList, InstParameterItem);
1145
1146impl From<&InstParameterItem> for TokenRange {
1147 fn from(value: &InstParameterItem) -> Self {
1148 let mut ret: TokenRange = value.identifier.as_ref().into();
1149 if let Some(x) = &value.inst_parameter_item_opt {
1150 ret.set_end(x.expression.as_ref().into());
1151 }
1152 ret
1153 }
1154}
1155impl_token_ext!(InstParameterItem);
1156
1157impl_token_range!(InstPort, l_paren, r_paren);
1158impl_token_range_list!(InstPortList, InstPortGroup);
1159impl_token_range_group!(InstPortGroup, InstPortList, InstPortItem);
1160
1161impl From<&InstPortItem> for TokenRange {
1162 fn from(value: &InstPortItem) -> Self {
1163 let mut ret: TokenRange = value.identifier.as_ref().into();
1164 if let Some(x) = &value.inst_port_item_opt {
1165 ret.set_end(x.expression.as_ref().into());
1166 }
1167 ret
1168 }
1169}
1170impl_token_ext!(InstPortItem);
1171
1172impl_token_range!(WithParameter, hash, r_paren);
1177impl_token_range_list!(WithParameterList, WithParameterGroup);
1178impl_token_range_group!(WithParameterGroup, WithParameterList, WithParameterItem);
1179
1180impl From<&WithParameterItem> for TokenRange {
1181 fn from(value: &WithParameterItem) -> Self {
1182 let mut ret: TokenRange = match value.with_parameter_item_group.as_ref() {
1183 WithParameterItemGroup::Param(x) => x.param.as_ref().into(),
1184 WithParameterItemGroup::Const(x) => x.r#const.as_ref().into(),
1185 };
1186
1187 if let Some(x) = &value.with_parameter_item_opt {
1188 ret.set_end(x.expression.as_ref().into());
1189 } else {
1190 ret.set_end(value.with_parameter_item_group0.as_ref().into());
1191 }
1192
1193 ret
1194 }
1195}
1196impl_token_ext!(WithParameterItem);
1197impl_token_range_enum!(WithParameterItemGroup0, array_type, r#type);
1198
1199impl From<&GenericBound> for TokenRange {
1204 fn from(value: &GenericBound) -> Self {
1205 match value {
1206 GenericBound::Type(x) => x.r#type.as_ref().into(),
1207 GenericBound::InstScopedIdentifier(x) => {
1208 let mut ret: TokenRange = x.inst.as_ref().into();
1209 ret.set_end(x.scoped_identifier.as_ref().into());
1210 ret
1211 }
1212 GenericBound::GenericProtoBound(x) => x.generic_proto_bound.as_ref().into(),
1213 }
1214 }
1215}
1216impl_token_ext!(GenericBound);
1217
1218impl_token_range!(WithGenericParameter, colon_colon_l_angle, r_angle);
1219impl_token_range_list!(WithGenericParameterList, WithGenericParameterItem);
1220
1221impl From<&WithGenericParameterItem> for TokenRange {
1222 fn from(value: &WithGenericParameterItem) -> Self {
1223 let mut ret: TokenRange = value.identifier.as_ref().into();
1224 ret.set_end(value.generic_bound.as_ref().into());
1225 if let Some(x) = &value.with_generic_parameter_item_opt {
1226 ret.set_end(x.with_generic_argument_item.as_ref().into());
1227 }
1228 ret
1229 }
1230}
1231impl_token_ext!(WithGenericParameterItem);
1232
1233impl_token_range_enum!(GenericProtoBound, scoped_identifier, fixed_type);
1234
1235impl_token_range!(WithGenericArgument, colon_colon_l_angle, r_angle);
1240impl_token_range_list!(WithGenericArgumentList, WithGenericArgumentItem);
1241impl_token_range_enum!(
1242 WithGenericArgumentItem,
1243 generic_arg_identifier,
1244 fixed_type,
1245 number,
1246 boolean_literal
1247);
1248
1249impl_token_range!(PortDeclaration, l_paren, r_paren);
1254impl_token_range_list!(PortDeclarationList, PortDeclarationGroup);
1255impl_token_range_group!(
1256 PortDeclarationGroup,
1257 PortDeclarationList,
1258 PortDeclarationItem
1259);
1260
1261impl From<&PortDeclarationItem> for TokenRange {
1262 fn from(value: &PortDeclarationItem) -> Self {
1263 let mut ret: TokenRange = value.identifier.as_ref().into();
1264 match value.port_declaration_item_group.as_ref() {
1265 PortDeclarationItemGroup::PortTypeConcrete(x) => {
1266 ret.set_end(x.port_type_concrete.as_ref().into());
1267 }
1268 PortDeclarationItemGroup::PortTypeAbstract(x) => {
1269 ret.set_end(x.port_type_abstract.as_ref().into());
1270 }
1271 }
1272 ret
1273 }
1274}
1275impl_token_ext!(PortDeclarationItem);
1276
1277impl From<&PortDeclarationItemGroup> for TokenRange {
1278 fn from(value: &PortDeclarationItemGroup) -> Self {
1279 match value {
1280 PortDeclarationItemGroup::PortTypeConcrete(x) => x.port_type_concrete.as_ref().into(),
1281 PortDeclarationItemGroup::PortTypeAbstract(x) => x.port_type_abstract.as_ref().into(),
1282 }
1283 }
1284}
1285impl_token_ext!(PortDeclarationItemGroup);
1286
1287impl From<&PortTypeConcrete> for TokenRange {
1288 fn from(value: &PortTypeConcrete) -> Self {
1289 let mut ret: TokenRange = value.direction.as_ref().into();
1290 ret.set_end(value.array_type.as_ref().into());
1291 if let Some(x) = &value.port_type_concrete_opt0 {
1292 ret.set_end(x.port_default_value.as_ref().into());
1293 }
1294 ret
1295 }
1296}
1297impl_token_ext!(PortTypeConcrete);
1298
1299impl_token_range!(PortDefaultValue, expression);
1300
1301impl From<&PortTypeAbstract> for TokenRange {
1302 fn from(value: &PortTypeAbstract) -> Self {
1303 let mut ret: TokenRange = value.interface.as_ref().into();
1304 if let Some(x) = &value.port_type_abstract_opt {
1305 ret.set_beg(x.clock_domain.as_ref().into());
1306 }
1307 if let Some(x) = &value.port_type_abstract_opt0 {
1308 ret.set_beg(x.identifier.as_ref().into());
1309 }
1310 if let Some(x) = &value.port_type_abstract_opt1 {
1311 ret.set_beg(x.array.as_ref().into());
1312 }
1313 ret
1314 }
1315}
1316impl_token_ext!(PortTypeAbstract);
1317
1318impl_token_range_enum!(Direction, input, output, inout, modport, import);
1319
1320impl_token_range!(FunctionDeclaration, function, statement_block);
1325
1326impl_token_range!(ImportDeclaration, import, semicolon);
1331
1332impl_token_range!(UnsafeBlock, r#unsafe, r_brace);
1337
1338impl_token_range!(ModuleDeclaration, module, r_brace);
1343impl_token_range_group!(ModuleGroup, ModuleItem);
1344impl_token_range!(ModuleItem, generate_item);
1345impl_token_range!(InterfaceDeclaration, interface, r_brace);
1346impl_token_range_group!(InterfaceGroup, InterfaceItem);
1347impl_token_range_enum!(InterfaceItem, generate_item, modport_declaration);
1348
1349impl From<&GenerateIfDeclaration> for TokenRange {
1350 fn from(value: &GenerateIfDeclaration) -> Self {
1351 let mut ret: TokenRange = value.r#if.as_ref().into();
1352 ret.set_end(value.generate_named_block.as_ref().into());
1353 if let Some(x) = value.generate_if_declaration_list.last() {
1354 ret.set_end(x.generate_optional_named_block.as_ref().into());
1355 }
1356 if let Some(x) = &value.generate_if_declaration_opt {
1357 ret.set_end(x.generate_optional_named_block.as_ref().into());
1358 }
1359 ret
1360 }
1361}
1362impl_token_ext!(GenerateIfDeclaration);
1363
1364impl_token_range!(
1365 GenerateIfDeclarationList,
1366 r#else,
1367 generate_optional_named_block
1368);
1369impl_token_range!(GenerateForDeclaration, r#for, generate_named_block);
1370impl_token_range!(GenerateBlockDeclaration, generate_named_block);
1371impl_token_range!(GenerateNamedBlock, colon, r_brace);
1372
1373impl From<&GenerateOptionalNamedBlock> for TokenRange {
1374 fn from(value: &GenerateOptionalNamedBlock) -> Self {
1375 let beg = value.l_brace.l_brace_token.token;
1376 let end = value.r_brace.r_brace_token.token;
1377 let mut ret = TokenRange { beg, end };
1378 if let Some(x) = &value.generate_optional_named_block_opt {
1379 ret.set_beg(x.colon.as_ref().into());
1380 }
1381 ret
1382 }
1383}
1384impl_token_ext!(GenerateOptionalNamedBlock);
1385
1386impl_token_range_group!(GenerateGroup, GenerateItem);
1387impl_token_range_enum!(
1388 GenerateItem,
1389 let_declaration,
1390 var_declaration,
1391 inst_declaration,
1392 bind_declaration,
1393 const_declaration,
1394 gen_declaration,
1395 always_ff_declaration,
1396 always_comb_declaration,
1397 assign_declaration,
1398 connect_declaration,
1399 function_declaration,
1400 generate_if_declaration,
1401 generate_for_declaration,
1402 generate_block_declaration,
1403 type_def_declaration,
1404 enum_declaration,
1405 struct_union_declaration,
1406 import_declaration,
1407 alias_declaration,
1408 initial_declaration,
1409 final_declaration,
1410 unsafe_block,
1411 embed_declaration
1412);
1413
1414impl_token_range!(PackageDeclaration, package, r_brace);
1419impl_token_range_group!(PackageGroup, PackageItem);
1420impl_token_range_enum!(
1421 PackageItem,
1422 const_declaration,
1423 gen_declaration,
1424 type_def_declaration,
1425 enum_declaration,
1426 struct_union_declaration,
1427 function_declaration,
1428 import_declaration,
1429 alias_declaration,
1430 embed_declaration
1431);
1432
1433impl_token_range!(AliasDeclaration, alias, semicolon);
1438
1439impl From<&ProtoDeclaration> for TokenRange {
1444 fn from(value: &ProtoDeclaration) -> Self {
1445 let beg: TokenRange = value.proto.as_ref().into();
1446 let end: TokenRange = match &*value.proto_declaration_group {
1447 ProtoDeclarationGroup::ProtoModuleDeclaration(x) => {
1448 x.proto_module_declaration.as_ref().into()
1449 }
1450 ProtoDeclarationGroup::ProtoInterfaceDeclaration(x) => {
1451 x.proto_interface_declaration.as_ref().into()
1452 }
1453 ProtoDeclarationGroup::ProtoPackageDeclaration(x) => {
1454 x.proto_package_declaration.as_ref().into()
1455 }
1456 };
1457 TokenRange {
1458 beg: beg.beg,
1459 end: end.end,
1460 }
1461 }
1462}
1463impl_token_range!(ProtoModuleDeclaration, module, semicolon);
1464impl_token_range!(ProtoInterfaceDeclaration, interface, r_brace);
1465impl_token_range_enum!(
1466 ProtoInterfaceItem,
1467 var_declaration,
1468 proto_const_declaration,
1469 proto_function_declaration,
1470 proto_type_def_declaration,
1471 proto_alias_declaration,
1472 modport_declaration,
1473 import_declaration
1474);
1475impl_token_range!(ProtoPackageDeclaration, package, r_brace);
1476impl_token_range_enum!(
1477 ProtoPacakgeItem,
1478 proto_const_declaration,
1479 proto_type_def_declaration,
1480 enum_declaration,
1481 struct_union_declaration,
1482 proto_function_declaration,
1483 proto_alias_declaration,
1484 import_declaration
1485);
1486impl_token_range!(ProtoConstDeclaration, r#const, semicolon);
1487
1488impl From<&ProtoConstDeclarationGroup> for TokenRange {
1489 fn from(value: &ProtoConstDeclarationGroup) -> Self {
1490 match value {
1491 ProtoConstDeclarationGroup::Type(x) => x.r#type.as_ref().into(),
1492 ProtoConstDeclarationGroup::ArrayType(x) => x.array_type.as_ref().into(),
1493 }
1494 }
1495}
1496impl_token_ext!(ProtoConstDeclarationGroup);
1497
1498impl_token_range!(ProtoTypeDefDeclaration, r#type, semicolon);
1499impl_token_range!(ProtoFunctionDeclaration, function, semicolon);
1500impl_token_range!(ProtoAliasDeclaration, alias, semicolon);
1501
1502impl_token_range!(EmbedDeclaration, embed, embed_content);
1507impl_token_range!(EmbedContent, triple_l_brace, triple_r_brace);
1508impl_token_range!(EmbedScopedIdentifier, escaped_l_brace, escaped_r_brace);
1509
1510impl From<&EmbedItem> for TokenRange {
1511 fn from(value: &EmbedItem) -> Self {
1512 match value {
1513 EmbedItem::EmbedLBraceEmbedItemListEmbedRBrace(x) => {
1514 let beg: TokenRange = x.embed_l_brace.as_ref().into();
1515 let end: TokenRange = x.embed_r_brace.as_ref().into();
1516 TokenRange {
1517 beg: beg.beg,
1518 end: end.end,
1519 }
1520 }
1521 EmbedItem::EmbedScopedIdentifier(x) => x.embed_scoped_identifier.as_ref().into(),
1522 EmbedItem::Any(x) => x.any.as_ref().into(),
1523 }
1524 }
1525}
1526
1527impl_token_range!(IncludeDeclaration, include, semicolon);
1532
1533impl From<&DescriptionItem> for TokenRange {
1538 fn from(value: &DescriptionItem) -> Self {
1539 match value {
1540 DescriptionItem::DescriptionItemOptPublicDescriptionItem(x) => {
1541 let mut ret: TokenRange = x.public_description_item.as_ref().into();
1542 if let Some(x) = &x.description_item_opt {
1543 ret.set_beg(x.r#pub.as_ref().into());
1544 }
1545 ret
1546 }
1547 DescriptionItem::ImportDeclaration(x) => x.import_declaration.as_ref().into(),
1548 DescriptionItem::BindDeclaration(x) => x.bind_declaration.as_ref().into(),
1549 DescriptionItem::EmbedDeclaration(x) => x.embed_declaration.as_ref().into(),
1550 DescriptionItem::IncludeDeclaration(x) => x.include_declaration.as_ref().into(),
1551 }
1552 }
1553}
1554impl_token_ext!(DescriptionItem);
1555
1556impl_token_range_group!(DescriptionGroup, DescriptionItem);
1557impl_token_range_enum!(
1558 PublicDescriptionItem,
1559 module_declaration,
1560 interface_declaration,
1561 package_declaration,
1562 alias_declaration,
1563 proto_declaration,
1564 function_declaration
1565);
1566
1567impl From<&Veryl> for TokenRange {
1572 fn from(value: &Veryl) -> Self {
1573 let mut ret: TokenRange = value.start.as_ref().into();
1574 if let Some(x) = value.veryl_list.last() {
1575 ret.set_end(x.description_group.as_ref().into());
1576 }
1577 ret
1578 }
1579}
1580impl_token_ext!(Veryl);