1use crate::callbacks::*;
7use logos::Logos;
8use std::fmt;
9
10#[derive(Logos, Debug, Clone, PartialEq, Eq, Copy)]
17#[logos(skip r"[ \t\f]+")]
18#[logos(error = String)]
19pub enum Token<'a> {
20 Error,
22 #[token("always")]
24 Always,
25 #[token("and")]
26 And,
27 #[token("assign")]
28 Assign,
29 #[token("begin")]
30 Begin,
31 #[token("buf")]
32 Buf,
33 #[token("bufif0")]
34 Bufif0,
35 #[token("bufif1")]
36 Bufif1,
37 #[token("case")]
38 Case,
39 #[token("casex")]
40 Casex,
41 #[token("casez")]
42 Casez,
43 #[token("cmos")]
44 Cmos,
45 #[token("deassign")]
46 Deassign,
47 #[token("default")]
48 Default,
49 #[token("defparam")]
50 Defparam,
51 #[token("disable")]
52 Disable,
53 #[token("edge")]
54 Edge,
55 #[token("else")]
56 Else,
57 #[token("end")]
58 End,
59 #[token("endcase")]
60 Endcase,
61 #[token("endfunction")]
62 Endfunction,
63 #[token("endmodule")]
64 Endmodule,
65 #[token("endprimitive")]
66 Endprimitive,
67 #[token("endspecify")]
68 Endspecify,
69 #[token("endtable")]
70 Endtable,
71 #[token("endtask")]
72 Endtask,
73 #[token("event")]
74 Event,
75 #[token("for")]
76 For,
77 #[token("force")]
78 Force,
79 #[token("forever")]
80 Forever,
81 #[token("fork")]
82 Fork,
83 #[token("function")]
84 Function,
85 #[token("highz0")]
86 Highz0,
87 #[token("highz1")]
88 Highz1,
89 #[token("if")]
90 If,
91 #[token("ifnone")]
92 Ifnone,
93 #[token("initial")]
94 Initial,
95 #[token("inout")]
96 Inout,
97 #[token("input")]
98 Input,
99 #[token("integer")]
100 Integer,
101 #[token("join")]
102 Join,
103 #[token("large")]
104 Large,
105 #[token("macromodule")]
106 Macromodule,
107 #[token("medium")]
108 Medium,
109 #[token("module")]
110 Module,
111 #[token("nand")]
112 Nand,
113 #[token("negedge")]
114 Negedge,
115 #[token("nmos")]
116 Nmos,
117 #[token("nor")]
118 Nor,
119 #[token("not")]
120 Not,
121 #[token("notif0")]
122 Notif0,
123 #[token("notif1")]
124 Notif1,
125 #[token("or")]
126 Or,
127 #[token("output")]
128 Output,
129 #[token("parameter")]
130 Parameter,
131 #[token("pmos")]
132 Pmos,
133 #[token("posedge")]
134 Posedge,
135 #[token("primitive")]
136 Primitive,
137 #[token("pull0")]
138 Pull0,
139 #[token("pull1")]
140 Pull1,
141 #[token("pulldown")]
142 Pulldown,
143 #[token("pullup")]
144 Pullup,
145 #[token("rcmos")]
146 Rcmos,
147 #[token("real")]
148 Real,
149 #[token("realtime")]
150 Realtime,
151 #[token("reg")]
152 Reg,
153 #[token("release")]
154 Release,
155 #[token("repeat")]
156 Repeat,
157 #[token("rnmos")]
158 Rnmos,
159 #[token("rpmos")]
160 Rpmos,
161 #[token("rtran")]
162 Rtran,
163 #[token("rtranif0")]
164 Rtranif0,
165 #[token("rtranif1")]
166 Rtranif1,
167 #[token("scalared")]
168 Scalared,
169 #[token("small")]
170 Small,
171 #[token("specify")]
172 Specify,
173 #[token("specparam")]
174 Specparam,
175 #[token("strong0")]
176 Strong0,
177 #[token("strong1")]
178 Strong1,
179 #[token("supply0")]
180 Supply0,
181 #[token("supply1")]
182 Supply1,
183 #[token("table")]
184 Table,
185 #[token("task")]
186 Task,
187 #[token("time")]
188 Time,
189 #[token("tran")]
190 Tran,
191 #[token("tranif0")]
192 Tranif0,
193 #[token("tranif1")]
194 Tranif1,
195 #[token("tri")]
196 Tri,
197 #[token("tri0")]
198 Tri0,
199 #[token("tri1")]
200 Tri1,
201 #[token("triand")]
202 Triand,
203 #[token("trior")]
204 Trior,
205 #[token("trireg")]
206 Trireg,
207 #[token("vectored")]
208 Vectored,
209 #[token("wait")]
210 Wait,
211 #[token("wand")]
212 Wand,
213 #[token("weak0")]
214 Weak0,
215 #[token("weak1")]
216 Weak1,
217 #[token("while")]
218 While,
219 #[token("wire")]
220 Wire,
221 #[token("wor")]
222 Wor,
223 #[token("xnor")]
224 Xnor,
225 #[token("xor")]
226 Xor,
227 #[token("automatic")]
229 Automatic,
230 #[token("cell")]
231 Cell,
232 #[token("config")]
233 Config,
234 #[token("design")]
235 Design,
236 #[token("endconfig")]
237 Endconfig,
238 #[token("endgenerate")]
239 Endgenerate,
240 #[token("generate")]
241 Generate,
242 #[token("genvar")]
243 Genvar,
244 #[token("incdir")]
245 Incdir,
246 #[token("include")]
247 Include,
248 #[token("instance")]
249 Instance,
250 #[token("liblist")]
251 Liblist,
252 #[token("library")]
253 Library,
254 #[token("localparam")]
255 Localparam,
256 #[token("noshowcancelled")]
257 Noshowcancelled,
258 #[token("pulsestyle_ondetect")]
259 PulsestyleOndetect,
260 #[token("pulsestyle_onevent")]
261 PulsestyleOnevent,
262 #[token("showcancelled")]
263 Showcancelled,
264 #[token("signed")]
265 Signed,
266 #[token("unsigned")]
267 Unsigned,
268 #[token("use")]
269 Use,
270 #[token("uwire")]
272 Uwire,
273 #[token("alias")]
275 Alias,
276 #[token("always_comb")]
277 AlwaysComb,
278 #[token("always_ff")]
279 AlwaysFf,
280 #[token("always_latch")]
281 AlwaysLatch,
282 #[token("assert")]
283 Assert,
284 #[token("assume")]
285 Assume,
286 #[token("before")]
287 Before,
288 #[token("bind")]
289 Bind,
290 #[token("bins")]
291 Bins,
292 #[token("binsof")]
293 Binsof,
294 #[token("bit")]
295 Bit,
296 #[token("break")]
297 Break,
298 #[token("byte")]
299 Byte,
300 #[token("chandle")]
301 Chandle,
302 #[token("class")]
303 Class,
304 #[token("clocking")]
305 Clocking,
306 #[token("const")]
307 Const,
308 #[token("constraint")]
309 Constraint,
310 #[token("context")]
311 Context,
312 #[token("continue")]
313 Continue,
314 #[token("cover")]
315 Cover,
316 #[token("covergroup")]
317 Covergroup,
318 #[token("coverpoint")]
319 Coverpoint,
320 #[token("cross")]
321 Cross,
322 #[token("dist")]
323 Dist,
324 #[token("do")]
325 Do,
326 #[token("endclass")]
327 Endclass,
328 #[token("endclocking")]
329 Endclocking,
330 #[token("endgroup")]
331 Endgroup,
332 #[token("endinterface")]
333 Endinterface,
334 #[token("endpackage")]
335 Endpackage,
336 #[token("endprogram")]
337 Endprogram,
338 #[token("endproperty")]
339 Endproperty,
340 #[token("endsequence")]
341 Endsequence,
342 #[token("enum")]
343 Enum,
344 #[token("expect")]
345 Expect,
346 #[token("export")]
347 Export,
348 #[token("extends")]
349 Extends,
350 #[token("extern")]
351 Extern,
352 #[token("final")]
353 Final,
354 #[token("first_match")]
355 FirstMatch,
356 #[token("foreach")]
357 Foreach,
358 #[token("forkjoin")]
359 Forkjoin,
360 #[token("iff")]
361 Iff,
362 #[token("ignore_bins")]
363 IgnoreBins,
364 #[token("illegal_bins")]
365 IllegalBins,
366 #[token("import")]
367 Import,
368 #[token("inside")]
369 Inside,
370 #[token("int")]
371 Int,
372 #[token("interface")]
373 Interface,
374 #[token("intersect")]
375 Intersect,
376 #[token("join_any")]
377 JoinAny,
378 #[token("join_none")]
379 JoinNone,
380 #[token("local")]
381 Local,
382 #[token("logic")]
383 Logic,
384 #[token("longint")]
385 Longint,
386 #[token("matches")]
387 Matches,
388 #[token("modport")]
389 Modport,
390 #[token("new")]
391 New,
392 #[token("null")]
393 Null,
394 #[token("package")]
395 Package,
396 #[token("packed")]
397 Packed,
398 #[token("priority")]
399 Priority,
400 #[token("program")]
401 Program,
402 #[token("property")]
403 Property,
404 #[token("protected")]
405 Protected,
406 #[token("pure")]
407 Pure,
408 #[token("rand")]
409 Rand,
410 #[token("randc")]
411 Randc,
412 #[token("randcase")]
413 Randcase,
414 #[token("randsequence")]
415 Randsequence,
416 #[token("ref")]
417 Ref,
418 #[token("return")]
419 Return,
420 #[token("sequence")]
421 Sequence,
422 #[token("shortint")]
423 Shortint,
424 #[token("shortreal")]
425 Shortreal,
426 #[token("solve")]
427 Solve,
428 #[token("static")]
429 Static,
430 #[token("string")]
431 String,
432 #[token("struct")]
433 Struct,
434 #[token("super")]
435 Super,
436 #[token("tagged")]
437 Tagged,
438 #[token("this")]
439 This,
440 #[token("throughout")]
441 Throughout,
442 #[token("timeprecision")]
443 Timeprecision,
444 #[token("timeunit")]
445 Timeunit,
446 #[token("type")]
447 Type,
448 #[token("typedef")]
449 Typedef,
450 #[token("union")]
451 Union,
452 #[token("unique")]
453 Unique,
454 #[token("var")]
455 Var,
456 #[token("virtual")]
457 Virtual,
458 #[token("void")]
459 Void,
460 #[token("wait_order")]
461 WaitOrder,
462 #[token("wildcard")]
463 Wildcard,
464 #[token("with")]
465 With,
466 #[token("within")]
467 Within,
468 #[token("accept_on")]
470 AcceptOn,
471 #[token("checker")]
472 Checker,
473 #[token("endchecker")]
474 Endchecker,
475 #[token("eventually")]
476 Eventually,
477 #[token("global")]
478 Global,
479 #[token("implies")]
480 Implies,
481 #[token("let")]
482 Let,
483 #[token("nexttime")]
484 Nexttime,
485 #[token("reject_on")]
486 RejectOn,
487 #[token("restrict")]
488 Restrict,
489 #[token("s_always")]
490 SAlways,
491 #[token("s_eventually")]
492 SEventually,
493 #[token("s_nexttime")]
494 SNexttime,
495 #[token("s_until")]
496 SUntil,
497 #[token("s_until_with")]
498 SUntilWith,
499 #[token("strong")]
500 Strong,
501 #[token("sync_accept_on")]
502 SyncAcceptOn,
503 #[token("sync_reject_on")]
504 SyncRejectOn,
505 #[token("unique0")]
506 Unique0,
507 #[token("until")]
508 Until,
509 #[token("until_with")]
510 UntilWith,
511 #[token("untyped")]
512 Untyped,
513 #[token("weak")]
514 Weak,
515 #[token("implements")]
517 Implements,
518 #[token("interconnect")]
519 Interconnect,
520 #[token("nettype")]
521 Nettype,
522 #[token("soft")]
523 Soft,
524 #[token("`__FILE__")]
526 DirUnderscoreFile,
527 #[token("`__LINE__")]
528 DirUnderscoreLine,
529 #[token("`begin_keywords")]
530 DirBeginKeywords,
531 #[token("`celldefine")]
532 DirCelldefine,
533 #[token("`default_nettype")]
534 DirDefaultNettype,
535 #[token("`define")]
536 DirDefine,
537 #[token("`else")]
538 DirElse,
539 #[token("`elsif")]
540 DirElsif,
541 #[token("`end_keywords")]
542 DirEndKeywords,
543 #[token("`endcelldefine")]
544 DirEndcelldefine,
545 #[token("`endif")]
546 DirEndif,
547 #[token("`ifdef")]
548 DirIfdef,
549 #[token("`ifndef")]
550 DirIfndef,
551 #[token("`include")]
552 DirInclude,
553 #[token("`line")]
554 DirLine,
555 #[token("`nounconnected_drive")]
556 DirNounconnectedDrive,
557 #[token("`pragma")]
558 DirPragma,
559 #[token("`resetall")]
560 DirResetall,
561 #[token("`timescale")]
562 DirTimescale,
563 #[token("`unconnected_drive")]
564 DirUnconnectedDrive,
565 #[token("`undef")]
566 DirUndef,
567 #[token("`undefineall")]
568 DirUndefineall,
569 #[token("+")]
571 Plus,
572 #[token("-")]
573 Minus,
574 #[token("!")]
575 Exclamation,
576 #[token("?")]
577 Quest,
578 #[token("~")]
579 Tilde,
580 #[token("&")]
581 Amp,
582 #[token("~&")]
583 TildeAmp,
584 #[token("|")]
585 Pipe,
586 #[token("~|")]
587 TildePipe,
588 #[token("^")]
589 Caret,
590 #[token("~^")]
591 TildeCaret,
592 #[token("^~")]
593 CaretTilde,
594 #[token("*")]
595 Star,
596 #[token("/")]
597 Slash,
598 #[token("%")]
599 Percent,
600 #[token("==")]
601 EqEq,
602 #[token("!=")]
603 ExclEq,
604 #[token("+=")]
605 PlusEq,
606 #[token("-=")]
607 MinusEq,
608 #[token("*=")]
609 StarEq,
610 #[token("/=")]
611 SlashEq,
612 #[token("%=")]
613 PercentEq,
614 #[token("&=")]
615 AmpEq,
616 #[token("|=")]
617 PipeEq,
618 #[token("^=")]
619 CaretEq,
620 #[token("===")]
621 EqEqEq,
622 #[token("!==")]
623 ExclEqEq,
624 #[token("==?")]
625 EqEqQuest,
626 #[token("!=?")]
627 ExclEqQuest,
628 #[token("&&")]
629 AmpAmp,
630 #[token("&&&")]
631 AmpAmpAmp,
632 #[token("||")]
633 PipePipe,
634 #[token("**")]
635 StarStar,
636 #[token("<")]
637 Lt,
638 #[token("<=")]
639 LtEq,
640 #[token(">")]
641 Gt,
642 #[token(">=")]
643 GtEq,
644 #[token(">>")]
645 GtGt,
646 #[token("<<")]
647 LtLt,
648 #[token(">>=")]
649 GtGtEq,
650 #[token("<<=")]
651 LtLtEq,
652 #[token(">>>")]
653 GtGtGt,
654 #[token("<<<")]
655 LtLtLt,
656 #[token(">>>=")]
657 GtGtGtEq,
658 #[token("<<<=")]
659 LtLtLtEq,
660 #[token("->")]
661 MinusGt,
662 #[token("->>")]
663 MinusGtGt,
664 #[token("<->")]
665 LtMinusGt,
666 #[token("++")]
667 PlusPlus,
668 #[token("--")]
669 MinusMinus,
670 #[token("+:")]
671 PlusColon,
672 #[token("-:")]
673 MinusColon,
674 #[token("+/-")]
675 PlusSlashMinus,
676 #[token("+%-")]
677 PlusPercentMinus,
678 #[token("(")]
680 Paren,
681 #[token(")")]
682 EParen,
683 #[token("[")]
684 Bracket,
685 #[token("]")]
686 EBracket,
687 #[token("{")]
688 Brace,
689 #[token("}")]
690 EBrace,
691 #[token(":")]
692 Colon,
693 #[token(";")]
694 SColon,
695 #[token("'")]
696 Apost,
697 #[token(",")]
698 Comma,
699 #[token(".")]
700 Period,
701 #[token("#")]
702 Pound,
703 #[token("$")]
704 Dollar,
705 #[token("@")]
706 At,
707 #[token("@@")]
708 AtAt,
709 #[token("=")]
710 Eq,
711 #[token("::")]
712 ColonColon,
713 #[token(":=")]
714 ColonEq,
715 #[token(":/")]
716 ColonSlash,
717 #[token("##")]
718 PoundPound,
719 #[token("#-#")]
720 PoundMinusPound,
721 #[token("#=#")]
722 PoundEqPound,
723 #[token("=>")]
724 EqGt,
725 #[token("*>")]
726 StarGt,
727 #[token("|->")]
728 PipeMinusGt,
729 #[token("|=>")]
730 PipeEqGt,
731 #[token(r"\")]
732 Bslash,
733 #[token("std")]
735 Std,
736 #[token("PATHPULSE$")]
737 PathpulseDollar,
738 #[token("option")]
739 Option,
740 #[token("type_option")]
741 TypeOption,
742 #[token("randomize")]
743 Randomize,
744 #[token("sample")]
745 Sample,
746 #[token("1step")]
747 OneStep,
748 #[token("$setup")]
749 DollarSetup,
750 #[token("$hold")]
751 DollarHold,
752 #[token("$setuphold")]
753 DollarSetuphold,
754 #[token("$recovery")]
755 DollarRecovery,
756 #[token("$removal")]
757 DollarRemoval,
758 #[token("$recrem")]
759 DollarRecrem,
760 #[token("$skew")]
761 DollarSkew,
762 #[token("$timeskew")]
763 DollarTimeskew,
764 #[token("$fullskew")]
765 DollarFullskew,
766 #[token("$period")]
767 DollarPeriod,
768 #[token("$width")]
769 DollarWidth,
770 #[token("$nochange")]
771 DollarNochange,
772 #[token("$root")]
773 DollarRoot,
774 #[token("$unit")]
775 DollarUnit,
776 #[token("$fatal")]
777 DollarFatal,
778 #[token("$error")]
779 DollarError,
780 #[token("$warning")]
781 DollarWarning,
782 #[token("$info")]
783 DollarInfo,
784 #[regex(r"//[^\r\n]*", oneline_comment, allow_greedy = true)]
786 OnelineComment(&'a str),
787 #[token(r"/*", block_comment)]
788 BlockComment(&'a str),
789 #[regex(r"[0-9][0-9_]*", |lex| lex.slice())]
791 UnsignedNumber(&'a str),
792 #[regex(r"[0-9][0-9_]*\.[0-9][0-9_]*", |lex| lex.slice())]
793 FixedPointNumber(&'a str),
794 #[regex(r"([0-9][0-9_]*)?\s*'[s|S]?(b|B)\s*[0-1xXzZ\?][0-1xXzZ\?_]*", |lex| lex.slice())]
795 BinaryNumber(&'a str),
796 #[regex(r"([0-9][0-9_]*)?\s*'[s|S]?(o|O)\s*[0-7xXzZ\?][0-7xXzZ\?_]*", |lex| lex.slice())]
797 OctalNumber(&'a str),
798 #[regex(r"([0-9][0-9_]*)?\s*'[s|S]?(d|D)\s*[0-9][0-9_]*", |lex| lex.slice())]
799 #[regex(r"([0-9][0-9_]*)?\s*'[s|S]?(d|D)\s*(x|X|z|Z|\?)_*", |lex| lex.slice())]
800 DecimalNumber(&'a str),
801 #[regex(r"([0-9][0-9_]*)?\s*'[s|S]?(h|H)\s*[0-9a-fA-FxXzZ\?][0-9a-fA-FxXzZ\?_]*", |lex| lex.slice())]
802 HexNumber(&'a str),
803 #[regex(r"[0-9][0-9_]*(\.[0-9][0-9_]*)?(e|E)(\+|-)?[0-9][0-9_]*", |lex| lex.slice())]
804 ScientificNumber(&'a str),
805 #[regex(r"('0|'1|'x|'X|'z|'Z|'\?)", |lex| lex.slice())]
806 UnbasedUnsizedLiteral(&'a str),
807 #[regex(r"\$[a-zA-Z0-9_\$]+", |lex| lex.slice())]
809 SystemTfIdentifier(&'a str),
810 #[regex(r"[a-zA-Z_][a-zA-Z0-9_\$]*", |lex| lex.slice())]
811 SimpleIdentifier(&'a str),
812 #[regex(r"\\[!-~]+(\s|$)", |lex| lex.slice())]
813 EscapedIdentifier(&'a str),
814 #[regex(r"[a-zA-Z_][a-zA-Z0-9_\$]*(``([a-zA-Z_][a-zA-Z0-9_\$]*)?)+", |lex| lex.slice())]
815 PreprocessorIdentifier(&'a str),
816 #[regex(r"`[a-zA-Z_][a-zA-Z0-9_\$]*", text_macro)]
817 #[regex(r"`\\[!-~]+", text_macro)]
818 TextMacro(&'a str),
819 #[regex(
820 r"`[a-zA-Z_][a-zA-Z0-9_\$]*(``([a-zA-Z_][a-zA-Z0-9_\$]*)?)+",
821 text_macro
822 )]
823 ConcatenatedTextMacro(&'a str),
824 #[token(r#"""#, string_literal)]
825 StringLiteral(&'a str),
826 #[token(r#"`""#, preprocessor_string_literal)]
827 PreprocessorStringLiteral(&'a str),
828 #[token(r#"""""#, multiline_string_literal)]
829 TripleQuoteStringLiteral(&'a str),
830 #[token(r#"`""""#, preprocessor_multiline_string_literal)]
831 PreprocessorTripleQuoteStringLiteral(&'a str),
832 #[token("\n")]
833 #[token("\r")]
834 #[token("\r\n")]
835 #[token("\u{0085}")]
836 #[token("\u{2028}")]
837 #[token("\u{2029}")]
838 Newline,
839}
840
841impl<'a> Token<'a> {
842 pub fn is_directive(&self) -> bool {
844 match self {
845 Token::DirUnderscoreFile
846 | Token::DirUnderscoreLine
847 | Token::DirBeginKeywords
848 | Token::DirCelldefine
849 | Token::DirDefaultNettype
850 | Token::DirDefine
851 | Token::DirElse
852 | Token::DirElsif
853 | Token::DirEndKeywords
854 | Token::DirEndcelldefine
855 | Token::DirEndif
856 | Token::DirIfdef
857 | Token::DirIfndef
858 | Token::DirInclude
859 | Token::DirLine
860 | Token::DirNounconnectedDrive
861 | Token::DirPragma
862 | Token::DirResetall
863 | Token::DirTimescale
864 | Token::DirUnconnectedDrive
865 | Token::DirUndef
866 | Token::DirUndefineall
867 | Token::TextMacro(_)
868 | Token::ConcatenatedTextMacro(_) => true,
869 _ => false,
870 }
871 }
872 pub fn as_str(&self) -> &'static str {
874 match self {
875 Token::Error => "a lexer error",
876 Token::Always => "always",
877 Token::And => "and",
878 Token::Assign => "assign",
879 Token::Begin => "begin",
880 Token::Buf => "buf",
881 Token::Bufif0 => "bufif0",
882 Token::Bufif1 => "bufif1",
883 Token::Case => "case",
884 Token::Casex => "casex",
885 Token::Casez => "casez",
886 Token::Cmos => "cmos",
887 Token::Deassign => "deassign",
888 Token::Default => "default",
889 Token::Defparam => "defparam",
890 Token::Disable => "disable",
891 Token::Edge => "edge",
892 Token::Else => "else",
893 Token::End => "end",
894 Token::Endcase => "endcase",
895 Token::Endfunction => "endfunction",
896 Token::Endmodule => "endmodule",
897 Token::Endprimitive => "endprimitive",
898 Token::Endspecify => "endspecify",
899 Token::Endtable => "endtable",
900 Token::Endtask => "endtask",
901 Token::Event => "event",
902 Token::For => "for",
903 Token::Force => "force",
904 Token::Forever => "forever",
905 Token::Fork => "fork",
906 Token::Function => "function",
907 Token::Highz0 => "highz0",
908 Token::Highz1 => "highz1",
909 Token::If => "if",
910 Token::Ifnone => "ifnone",
911 Token::Initial => "initial",
912 Token::Inout => "inout",
913 Token::Input => "input",
914 Token::Integer => "integer",
915 Token::Join => "join",
916 Token::Large => "large",
917 Token::Macromodule => "macromodule",
918 Token::Medium => "medium",
919 Token::Module => "module",
920 Token::Nand => "nand",
921 Token::Negedge => "negedge",
922 Token::Nmos => "nmos",
923 Token::Nor => "nor",
924 Token::Not => "not",
925 Token::Notif0 => "notif0",
926 Token::Notif1 => "notif1",
927 Token::Or => "or",
928 Token::Output => "output",
929 Token::Parameter => "parameter",
930 Token::Pmos => "pmos",
931 Token::Posedge => "posedge",
932 Token::Primitive => "primitive",
933 Token::Pull0 => "pull0",
934 Token::Pull1 => "pull1",
935 Token::Pulldown => "pulldown",
936 Token::Pullup => "pullup",
937 Token::Rcmos => "rcmos",
938 Token::Real => "real",
939 Token::Realtime => "realtime",
940 Token::Reg => "reg",
941 Token::Release => "release",
942 Token::Repeat => "repeat",
943 Token::Rnmos => "rnmos",
944 Token::Rpmos => "rpmos",
945 Token::Rtran => "rtran",
946 Token::Rtranif0 => "rtranif0",
947 Token::Rtranif1 => "rtranif1",
948 Token::Scalared => "scalared",
949 Token::Small => "small",
950 Token::Specify => "specify",
951 Token::Specparam => "specparam",
952 Token::Strong0 => "strong0",
953 Token::Strong1 => "strong1",
954 Token::Supply0 => "supply0",
955 Token::Supply1 => "supply1",
956 Token::Table => "table",
957 Token::Task => "task",
958 Token::Time => "time",
959 Token::Tran => "tran",
960 Token::Tranif0 => "tranif0",
961 Token::Tranif1 => "tranif1",
962 Token::Tri => "tri",
963 Token::Tri0 => "tri0",
964 Token::Tri1 => "tri1",
965 Token::Triand => "triand",
966 Token::Trior => "trior",
967 Token::Trireg => "trireg",
968 Token::Vectored => "vectored",
969 Token::Wait => "wait",
970 Token::Wand => "wand",
971 Token::Weak0 => "weak0",
972 Token::Weak1 => "weak1",
973 Token::While => "while",
974 Token::Wire => "wire",
975 Token::Wor => "wor",
976 Token::Xnor => "xnor",
977 Token::Xor => "xor",
978 Token::Automatic => "automatic",
979 Token::Cell => "cell",
980 Token::Config => "config",
981 Token::Design => "design",
982 Token::Endconfig => "endconfig",
983 Token::Endgenerate => "endgenerate",
984 Token::Generate => "generate",
985 Token::Genvar => "genvar",
986 Token::Incdir => "incdir",
987 Token::Include => "include",
988 Token::Instance => "instance",
989 Token::Liblist => "liblist",
990 Token::Library => "library",
991 Token::Localparam => "localparam",
992 Token::Noshowcancelled => "noshowcancelled",
993 Token::PulsestyleOndetect => "pulsestyle_ondetect",
994 Token::PulsestyleOnevent => "pulsestyle_onevent",
995 Token::Showcancelled => "showcancelled",
996 Token::Signed => "signed",
997 Token::Unsigned => "unsigned",
998 Token::Use => "use",
999 Token::Uwire => "uwire",
1000 Token::Alias => "alias",
1001 Token::AlwaysComb => "always_comb",
1002 Token::AlwaysFf => "always_ff",
1003 Token::AlwaysLatch => "always_latch",
1004 Token::Assert => "assert",
1005 Token::Assume => "assume",
1006 Token::Before => "before",
1007 Token::Bind => "bind",
1008 Token::Bins => "bins",
1009 Token::Binsof => "binsof",
1010 Token::Bit => "bit",
1011 Token::Break => "break",
1012 Token::Byte => "byte",
1013 Token::Chandle => "chandle",
1014 Token::Class => "class",
1015 Token::Clocking => "clocking",
1016 Token::Const => "const",
1017 Token::Constraint => "constraint",
1018 Token::Context => "context",
1019 Token::Continue => "continue",
1020 Token::Cover => "cover",
1021 Token::Covergroup => "covergroup",
1022 Token::Coverpoint => "coverpoint",
1023 Token::Cross => "cross",
1024 Token::Dist => "dist",
1025 Token::Do => "do",
1026 Token::Endclass => "endclass",
1027 Token::Endclocking => "endclocking",
1028 Token::Endgroup => "endgroup",
1029 Token::Endinterface => "endinterface",
1030 Token::Endpackage => "endpackage",
1031 Token::Endprogram => "endprogram",
1032 Token::Endproperty => "endproperty",
1033 Token::Endsequence => "endsequence",
1034 Token::Enum => "enum",
1035 Token::Expect => "expect",
1036 Token::Export => "export",
1037 Token::Extends => "extends",
1038 Token::Extern => "extern",
1039 Token::Final => "final",
1040 Token::FirstMatch => "first_match",
1041 Token::Foreach => "foreach",
1042 Token::Forkjoin => "forkjoin",
1043 Token::Iff => "iff",
1044 Token::IgnoreBins => "ignore_bins",
1045 Token::IllegalBins => "illegal_bins",
1046 Token::Import => "import",
1047 Token::Inside => "inside",
1048 Token::Int => "int",
1049 Token::Interface => "interface",
1050 Token::Intersect => "intersect",
1051 Token::JoinAny => "join_any",
1052 Token::JoinNone => "join_none",
1053 Token::Local => "local",
1054 Token::Logic => "logic",
1055 Token::Longint => "longint",
1056 Token::Matches => "matches",
1057 Token::Modport => "modport",
1058 Token::New => "new",
1059 Token::Null => "null",
1060 Token::Package => "package",
1061 Token::Packed => "packed",
1062 Token::Priority => "priority",
1063 Token::Program => "program",
1064 Token::Property => "property",
1065 Token::Protected => "protected",
1066 Token::Pure => "pure",
1067 Token::Rand => "rand",
1068 Token::Randc => "randc",
1069 Token::Randcase => "randcase",
1070 Token::Randsequence => "randsequence",
1071 Token::Ref => "ref",
1072 Token::Return => "return",
1073 Token::Sequence => "sequence",
1074 Token::Shortint => "shortint",
1075 Token::Shortreal => "shortreal",
1076 Token::Solve => "solve",
1077 Token::Static => "static",
1078 Token::String => "string",
1079 Token::Struct => "struct",
1080 Token::Super => "super",
1081 Token::Tagged => "tagged",
1082 Token::This => "this",
1083 Token::Throughout => "throughout",
1084 Token::Timeprecision => "timeprecision",
1085 Token::Timeunit => "timeunit",
1086 Token::Type => "type",
1087 Token::Typedef => "typedef",
1088 Token::Union => "union",
1089 Token::Unique => "unique",
1090 Token::Var => "var",
1091 Token::Virtual => "virtual",
1092 Token::Void => "void",
1093 Token::WaitOrder => "wait_order",
1094 Token::Wildcard => "wildcard",
1095 Token::With => "with",
1096 Token::Within => "within",
1097 Token::AcceptOn => "accept_on",
1098 Token::Checker => "checker",
1099 Token::Endchecker => "endchecker",
1100 Token::Eventually => "eventually",
1101 Token::Global => "global",
1102 Token::Implies => "implies",
1103 Token::Let => "let",
1104 Token::Nexttime => "nexttime",
1105 Token::RejectOn => "reject_on",
1106 Token::Restrict => "restrict",
1107 Token::SAlways => "s_always",
1108 Token::SEventually => "s_eventually",
1109 Token::SNexttime => "s_nexttime",
1110 Token::SUntil => "s_until",
1111 Token::SUntilWith => "s_until_with",
1112 Token::Strong => "strong",
1113 Token::SyncAcceptOn => "sync_accept_on",
1114 Token::SyncRejectOn => "sync_reject_on",
1115 Token::Unique0 => "unique0",
1116 Token::Until => "until",
1117 Token::UntilWith => "until_with",
1118 Token::Untyped => "untyped",
1119 Token::Weak => "weak",
1120 Token::Implements => "implements",
1121 Token::Interconnect => "interconnect",
1122 Token::Nettype => "nettype",
1123 Token::Soft => "soft",
1124 Token::DirUnderscoreFile => "`__FILE__",
1125 Token::DirUnderscoreLine => "`__LINE__",
1126 Token::DirBeginKeywords => "`begin_keywords",
1127 Token::DirCelldefine => "`celldefine",
1128 Token::DirDefaultNettype => "`default_nettype",
1129 Token::DirDefine => "`define",
1130 Token::DirElse => "`else",
1131 Token::DirElsif => "`elsif",
1132 Token::DirEndKeywords => "`end_keywords",
1133 Token::DirEndcelldefine => "`endcelldefine",
1134 Token::DirEndif => "`endif",
1135 Token::DirIfdef => "`ifdef",
1136 Token::DirIfndef => "`ifndef",
1137 Token::DirInclude => "`include",
1138 Token::DirLine => "`line",
1139 Token::DirNounconnectedDrive => "`nounconnected_drive",
1140 Token::DirPragma => "`pragma",
1141 Token::DirResetall => "`resetall",
1142 Token::DirTimescale => "`timescale",
1143 Token::DirUnconnectedDrive => "`unconnected_drive",
1144 Token::DirUndef => "`undef",
1145 Token::DirUndefineall => "`undefineall",
1146 Token::Plus => "+",
1147 Token::Minus => "-",
1148 Token::Exclamation => "!",
1149 Token::Quest => "?",
1150 Token::Tilde => "~",
1151 Token::Amp => "&",
1152 Token::TildeAmp => "~&",
1153 Token::Pipe => "|",
1154 Token::TildePipe => "~|",
1155 Token::Caret => "^",
1156 Token::TildeCaret => "~^",
1157 Token::CaretTilde => "^~",
1158 Token::Star => "*",
1159 Token::Slash => "/",
1160 Token::Percent => "%",
1161 Token::EqEq => "==",
1162 Token::ExclEq => "!=",
1163 Token::PlusEq => "+=",
1164 Token::MinusEq => "-=",
1165 Token::StarEq => "*=",
1166 Token::SlashEq => "/=",
1167 Token::PercentEq => "%=",
1168 Token::AmpEq => "&=",
1169 Token::PipeEq => "|=",
1170 Token::CaretEq => "^=",
1171 Token::EqEqEq => "===",
1172 Token::ExclEqEq => "!==",
1173 Token::EqEqQuest => "==?",
1174 Token::ExclEqQuest => "!=?",
1175 Token::AmpAmp => "&&",
1176 Token::AmpAmpAmp => "&&&",
1177 Token::PipePipe => "||",
1178 Token::StarStar => "**",
1179 Token::Lt => "<",
1180 Token::LtEq => "<=",
1181 Token::Gt => ">",
1182 Token::GtEq => ">=",
1183 Token::GtGt => ">>",
1184 Token::LtLt => "<<",
1185 Token::GtGtEq => ">>=",
1186 Token::LtLtEq => "<<=",
1187 Token::GtGtGt => ">>>",
1188 Token::LtLtLt => "<<<",
1189 Token::GtGtGtEq => ">>>=",
1190 Token::LtLtLtEq => "<<<=",
1191 Token::MinusGt => "->",
1192 Token::MinusGtGt => "->>",
1193 Token::LtMinusGt => "<->",
1194 Token::PlusPlus => "++",
1195 Token::MinusMinus => "--",
1196 Token::PlusColon => "+:",
1197 Token::MinusColon => "-:",
1198 Token::PlusSlashMinus => "+/-",
1199 Token::PlusPercentMinus => "+%-",
1200 Token::Paren => "(",
1201 Token::EParen => ")",
1202 Token::Bracket => "[",
1203 Token::EBracket => "]",
1204 Token::Brace => "{",
1205 Token::EBrace => "}",
1206 Token::Colon => ":",
1207 Token::SColon => ";",
1208 Token::Apost => "'",
1209 Token::Comma => "a comma",
1210 Token::Period => ".",
1211 Token::Pound => "#",
1212 Token::Dollar => "$",
1213 Token::At => "@",
1214 Token::AtAt => "@@",
1215 Token::Eq => "=",
1216 Token::ColonColon => "::",
1217 Token::ColonEq => ":=",
1218 Token::ColonSlash => ":/",
1219 Token::PoundPound => "##",
1220 Token::PoundMinusPound => "#-#",
1221 Token::PoundEqPound => "#=#",
1222 Token::EqGt => "=>",
1223 Token::StarGt => "*>",
1224 Token::PipeMinusGt => "|->",
1225 Token::PipeEqGt => "|=>",
1226 Token::Bslash => r"\",
1227 Token::Std => "std",
1228 Token::PathpulseDollar => "PATHPULSE$",
1229 Token::Option => "option",
1230 Token::TypeOption => "type_option",
1231 Token::Randomize => "randomize",
1232 Token::Sample => "sample",
1233 Token::OneStep => "1step",
1234 Token::DollarSetup => "$setup",
1235 Token::DollarHold => "$hold",
1236 Token::DollarSetuphold => "$setuphold",
1237 Token::DollarRecovery => "$recovery",
1238 Token::DollarRemoval => "$removal",
1239 Token::DollarRecrem => "$recrem",
1240 Token::DollarSkew => "$skew",
1241 Token::DollarTimeskew => "$timeskew",
1242 Token::DollarFullskew => "$fullskew",
1243 Token::DollarPeriod => "$period",
1244 Token::DollarWidth => "$width",
1245 Token::DollarNochange => "$nochange",
1246 Token::DollarRoot => "$root",
1247 Token::DollarUnit => "$unit",
1248 Token::DollarFatal => "$fatal",
1249 Token::DollarError => "$error",
1250 Token::DollarWarning => "$warning",
1251 Token::DollarInfo => "$info",
1252 Token::OnelineComment(_text) => "<oneline comment>",
1253 Token::BlockComment(_text) => "<block comment>",
1254 Token::UnsignedNumber(_text) => "<unsigned number>",
1255 Token::FixedPointNumber(_text) => "<real number>",
1256 Token::BinaryNumber(_text) => "<binary number>",
1257 Token::OctalNumber(_text) => "<octal number>",
1258 Token::DecimalNumber(_text) => "<decimal number>",
1259 Token::HexNumber(_text) => "<hex number>",
1260 Token::ScientificNumber(_text) => "<scientific number>",
1261 Token::UnbasedUnsizedLiteral(_text) => "<unsized literal>",
1262 Token::SystemTfIdentifier(_text) => "<system tf identifier>",
1263 Token::SimpleIdentifier(_text) => "<simple identifier>",
1264 Token::EscapedIdentifier(_text) => "<escaped identifier>",
1265 Token::PreprocessorIdentifier(_text) => "<preprocessor identifier>",
1266 Token::TextMacro(_text) => "<text macro>",
1267 Token::ConcatenatedTextMacro(_text) => "<concatenated text macro>",
1268 Token::StringLiteral(_text) => "<string>",
1269 Token::PreprocessorStringLiteral(_text) => "<preprocessor string>",
1270 Token::TripleQuoteStringLiteral(_text) => "<triple-quote string>",
1271 Token::PreprocessorTripleQuoteStringLiteral(_text) => {
1272 "<preprocessor triple-quote string>"
1273 }
1274 Token::Newline => "newline",
1275 }
1276 }
1277}
1278
1279impl<'a> fmt::Display for Token<'a> {
1280 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1281 let temp_str: String;
1282 let str_repr = match self {
1283 Token::OnelineComment(text) => {
1284 temp_str = format!("comment '{}'", text);
1285 temp_str.as_str()
1286 }
1287 Token::BlockComment(text) => {
1288 temp_str = format!("block comment '{}'", text);
1289 temp_str.as_str()
1290 }
1291 Token::UnsignedNumber(text) => {
1292 temp_str = format!("number '{}' ", text);
1293 temp_str.as_str()
1294 }
1295 Token::FixedPointNumber(text) => {
1296 temp_str = format!("real number '{}' ", text);
1297 temp_str.as_str()
1298 }
1299 Token::BinaryNumber(text) => {
1300 temp_str = format!("binary number '{}' ", text);
1301 temp_str.as_str()
1302 }
1303 Token::OctalNumber(text) => {
1304 temp_str = format!("octal number '{}' ", text);
1305 temp_str.as_str()
1306 }
1307 Token::DecimalNumber(text) => {
1308 temp_str = format!("decimal number '{}' ", text);
1309 temp_str.as_str()
1310 }
1311 Token::HexNumber(text) => {
1312 temp_str = format!("hexadecimal number '{}' ", text);
1313 temp_str.as_str()
1314 }
1315 Token::ScientificNumber(text) => {
1316 temp_str = format!("real number '{}' ", text);
1317 temp_str.as_str()
1318 }
1319 Token::UnbasedUnsizedLiteral(text) => {
1320 temp_str = format!("unsized literal '{}' ", text);
1321 temp_str.as_str()
1322 }
1323 Token::SystemTfIdentifier(text) => {
1324 temp_str = format!("{}", text);
1325 temp_str.as_str()
1326 }
1327 Token::SimpleIdentifier(text) => {
1328 temp_str = format!("identifier '{}'", text);
1329 temp_str.as_str()
1330 }
1331 Token::EscapedIdentifier(text) => {
1332 temp_str = format!("escaped identifier '{}'", text);
1333 temp_str.as_str()
1334 }
1335 Token::PreprocessorIdentifier(text) => {
1336 temp_str = format!("preprocessor identifier '{}'", text);
1337 temp_str.as_str()
1338 }
1339 Token::TextMacro(text) => {
1340 temp_str = format!("text macro '{}'", text);
1341 temp_str.as_str()
1342 }
1343 Token::ConcatenatedTextMacro(text) => {
1344 temp_str = format!("concatenated text macro '{}'", text);
1345 temp_str.as_str()
1346 }
1347 Token::StringLiteral(text) => {
1348 temp_str = format!("string \"{}\"", text);
1349 temp_str.as_str()
1350 }
1351 Token::PreprocessorStringLiteral(text) => {
1352 temp_str = format!("preprocessor string `\"{}`\"", text);
1353 temp_str.as_str()
1354 }
1355 Token::TripleQuoteStringLiteral(text) => {
1356 temp_str = format!("string \"\"\"{}\"\"\"", text);
1357 temp_str.as_str()
1358 }
1359 Token::PreprocessorTripleQuoteStringLiteral(text) => {
1360 temp_str =
1361 format!("preprocessor string `\"\"\"{}`\"\"\"", text);
1362 temp_str.as_str()
1363 }
1364 _ => self.as_str(),
1365 };
1366 write!(f, "{}", str_repr)
1367 }
1368}