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