Skip to main content

scarf_parser/lexer/
tokens.rs

1// =======================================================================
2// tokens.rs
3// =======================================================================
4// The tokens that a SystemVerilog source file is parsed into
5
6use crate::callbacks::*;
7use logos::Logos;
8use std::fmt;
9
10/// A single syntactic token for a SystemVerilog source file
11///
12/// Most variants don't carry data, and represent a specific
13/// keyword, directive, or other literal token of the language.
14/// Those that can vary in content (such as identifiers, strings,
15/// etc.) contain a reference to that content in the source file.
16#[derive(Logos, Debug, Clone, PartialEq, Eq, Copy)]
17#[logos(skip r"[ \t\f]+")]
18#[logos(error = String)]
19pub enum Token<'a> {
20    /// A lexer error
21    Error,
22    // 1364-1995
23    #[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    // 1364-2001
228    #[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    // 1364-2005
271    #[token("uwire")]
272    Uwire,
273    // 1800-2005
274    #[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    // 1800-2009
469    #[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    // 1800-2012
516    #[token("implements")]
517    Implements,
518    #[token("interconnect")]
519    Interconnect,
520    #[token("nettype")]
521    Nettype,
522    #[token("soft")]
523    Soft,
524    // Directives
525    #[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    // Operators
570    #[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    // Symbols
679    #[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    // Other Language Grammar
734    #[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    // Comments
785    #[regex(r"//[^\r\n]*", oneline_comment, allow_greedy = true)]
786    OnelineComment(&'a str),
787    #[token(r"/*", block_comment)]
788    BlockComment(&'a str),
789    // Numbers
790    #[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]?(b|B)[0-1xXzZ\?][0-1xXzZ\?_]*", |lex| lex.slice())]
795    BinaryNumber(&'a str),
796    #[regex(r"([0-9][0-9_]*)?'[s|S]?(o|O)[0-7xXzZ\?][0-7xXzZ\?_]*", |lex| lex.slice())]
797    OctalNumber(&'a str),
798    #[regex(r"([0-9][0-9_]*)?'[s|S]?(d|D)[0-9][0-9_]*", |lex| lex.slice())]
799    #[regex(r"([0-9][0-9_]*)?'[s|S]?(d|D)(x|X|z|Z)_*", |lex| lex.slice())]
800    DecimalNumber(&'a str),
801    #[regex(r"([0-9][0-9_]*)?'[s|S]?(h|H)[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    // Literals
808    #[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"\\[!-~]+", |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    #[token(r#"""#, string_literal)]
820    StringLiteral(&'a str),
821    #[token(r#"`""#, preprocessor_string_literal)]
822    PreprocessorStringLiteral(&'a str),
823    #[token(r#"""""#, multiline_string_literal)]
824    TripleQuoteStringLiteral(&'a str),
825    #[token(r#"`""""#, preprocessor_multiline_string_literal)]
826    PreprocessorTripleQuoteStringLiteral(&'a str),
827    #[token("\n")]
828    #[token("\r")]
829    #[token("\r\n")]
830    #[token("\u{0085}")]
831    #[token("\u{2028}")]
832    #[token("\u{2029}")]
833    Newline,
834}
835
836impl<'a> Token<'a> {
837    /// Whether the token represents a compiler directive
838    pub fn is_directive(&self) -> bool {
839        match self {
840            Token::DirUnderscoreFile
841            | Token::DirUnderscoreLine
842            | Token::DirBeginKeywords
843            | Token::DirCelldefine
844            | Token::DirDefaultNettype
845            | Token::DirDefine
846            | Token::DirElse
847            | Token::DirElsif
848            | Token::DirEndKeywords
849            | Token::DirEndcelldefine
850            | Token::DirEndif
851            | Token::DirIfdef
852            | Token::DirIfndef
853            | Token::DirInclude
854            | Token::DirLine
855            | Token::DirNounconnectedDrive
856            | Token::DirPragma
857            | Token::DirResetall
858            | Token::DirTimescale
859            | Token::DirUnconnectedDrive
860            | Token::DirUndef
861            | Token::DirUndefineall
862            | Token::TextMacro(_) => true,
863            _ => false,
864        }
865    }
866    /// A string representation of the token (usually the literal matching text)
867    pub fn as_str(&self) -> &'static str {
868        match self {
869            Token::Error => "a lexer error",
870            Token::Always => "always",
871            Token::And => "and",
872            Token::Assign => "assign",
873            Token::Begin => "begin",
874            Token::Buf => "buf",
875            Token::Bufif0 => "bufif0",
876            Token::Bufif1 => "bufif1",
877            Token::Case => "case",
878            Token::Casex => "casex",
879            Token::Casez => "casez",
880            Token::Cmos => "cmos",
881            Token::Deassign => "deassign",
882            Token::Default => "default",
883            Token::Defparam => "defparam",
884            Token::Disable => "disable",
885            Token::Edge => "edge",
886            Token::Else => "else",
887            Token::End => "end",
888            Token::Endcase => "endcase",
889            Token::Endfunction => "endfunction",
890            Token::Endmodule => "endmodule",
891            Token::Endprimitive => "endprimitive",
892            Token::Endspecify => "endspecify",
893            Token::Endtable => "endtable",
894            Token::Endtask => "endtask",
895            Token::Event => "event",
896            Token::For => "for",
897            Token::Force => "force",
898            Token::Forever => "forever",
899            Token::Fork => "fork",
900            Token::Function => "function",
901            Token::Highz0 => "highz0",
902            Token::Highz1 => "highz1",
903            Token::If => "if",
904            Token::Ifnone => "ifnone",
905            Token::Initial => "initial",
906            Token::Inout => "inout",
907            Token::Input => "input",
908            Token::Integer => "integer",
909            Token::Join => "join",
910            Token::Large => "large",
911            Token::Macromodule => "macromodule",
912            Token::Medium => "medium",
913            Token::Module => "module",
914            Token::Nand => "nand",
915            Token::Negedge => "negedge",
916            Token::Nmos => "nmos",
917            Token::Nor => "nor",
918            Token::Not => "not",
919            Token::Notif0 => "notif0",
920            Token::Notif1 => "notif1",
921            Token::Or => "or",
922            Token::Output => "output",
923            Token::Parameter => "parameter",
924            Token::Pmos => "pmos",
925            Token::Posedge => "posedge",
926            Token::Primitive => "primitive",
927            Token::Pull0 => "pull0",
928            Token::Pull1 => "pull1",
929            Token::Pulldown => "pulldown",
930            Token::Pullup => "pullup",
931            Token::Rcmos => "rcmos",
932            Token::Real => "real",
933            Token::Realtime => "realtime",
934            Token::Reg => "reg",
935            Token::Release => "release",
936            Token::Repeat => "repeat",
937            Token::Rnmos => "rnmos",
938            Token::Rpmos => "rpmos",
939            Token::Rtran => "rtran",
940            Token::Rtranif0 => "rtranif0",
941            Token::Rtranif1 => "rtranif1",
942            Token::Scalared => "scalared",
943            Token::Small => "small",
944            Token::Specify => "specify",
945            Token::Specparam => "specparam",
946            Token::Strong0 => "strong0",
947            Token::Strong1 => "strong1",
948            Token::Supply0 => "supply0",
949            Token::Supply1 => "supply1",
950            Token::Table => "table",
951            Token::Task => "task",
952            Token::Time => "time",
953            Token::Tran => "tran",
954            Token::Tranif0 => "tranif0",
955            Token::Tranif1 => "tranif1",
956            Token::Tri => "tri",
957            Token::Tri0 => "tri0",
958            Token::Tri1 => "tri1",
959            Token::Triand => "triand",
960            Token::Trior => "trior",
961            Token::Trireg => "trireg",
962            Token::Vectored => "vectored",
963            Token::Wait => "wait",
964            Token::Wand => "wand",
965            Token::Weak0 => "weak0",
966            Token::Weak1 => "weak1",
967            Token::While => "while",
968            Token::Wire => "wire",
969            Token::Wor => "wor",
970            Token::Xnor => "xnor",
971            Token::Xor => "xor",
972            Token::Automatic => "automatic",
973            Token::Cell => "cell",
974            Token::Config => "config",
975            Token::Design => "design",
976            Token::Endconfig => "endconfig",
977            Token::Endgenerate => "endgenerate",
978            Token::Generate => "generate",
979            Token::Genvar => "genvar",
980            Token::Incdir => "incdir",
981            Token::Include => "include",
982            Token::Instance => "instance",
983            Token::Liblist => "liblist",
984            Token::Library => "library",
985            Token::Localparam => "localparam",
986            Token::Noshowcancelled => "noshowcancelled",
987            Token::PulsestyleOndetect => "pulsestyle_ondetect",
988            Token::PulsestyleOnevent => "pulsestyle_onevent",
989            Token::Showcancelled => "showcancelled",
990            Token::Signed => "signed",
991            Token::Unsigned => "unsigned",
992            Token::Use => "use",
993            Token::Uwire => "uwire",
994            Token::Alias => "alias",
995            Token::AlwaysComb => "always_comb",
996            Token::AlwaysFf => "always_ff",
997            Token::AlwaysLatch => "always_latch",
998            Token::Assert => "assert",
999            Token::Assume => "assume",
1000            Token::Before => "before",
1001            Token::Bind => "bind",
1002            Token::Bins => "bins",
1003            Token::Binsof => "binsof",
1004            Token::Bit => "bit",
1005            Token::Break => "break",
1006            Token::Byte => "byte",
1007            Token::Chandle => "chandle",
1008            Token::Class => "class",
1009            Token::Clocking => "clocking",
1010            Token::Const => "const",
1011            Token::Constraint => "constraint",
1012            Token::Context => "context",
1013            Token::Continue => "continue",
1014            Token::Cover => "cover",
1015            Token::Covergroup => "covergroup",
1016            Token::Coverpoint => "coverpoint",
1017            Token::Cross => "cross",
1018            Token::Dist => "dist",
1019            Token::Do => "do",
1020            Token::Endclass => "endclass",
1021            Token::Endclocking => "endclocking",
1022            Token::Endgroup => "endgroup",
1023            Token::Endinterface => "endinterface",
1024            Token::Endpackage => "endpackage",
1025            Token::Endprogram => "endprogram",
1026            Token::Endproperty => "endproperty",
1027            Token::Endsequence => "endsequence",
1028            Token::Enum => "enum",
1029            Token::Expect => "expect",
1030            Token::Export => "export",
1031            Token::Extends => "extends",
1032            Token::Extern => "extern",
1033            Token::Final => "final",
1034            Token::FirstMatch => "first_match",
1035            Token::Foreach => "foreach",
1036            Token::Forkjoin => "forkjoin",
1037            Token::Iff => "iff",
1038            Token::IgnoreBins => "ignore_bins",
1039            Token::IllegalBins => "illegal_bins",
1040            Token::Import => "import",
1041            Token::Inside => "inside",
1042            Token::Int => "int",
1043            Token::Interface => "interface",
1044            Token::Intersect => "intersect",
1045            Token::JoinAny => "join_any",
1046            Token::JoinNone => "join_none",
1047            Token::Local => "local",
1048            Token::Logic => "logic",
1049            Token::Longint => "longint",
1050            Token::Matches => "matches",
1051            Token::Modport => "modport",
1052            Token::New => "new",
1053            Token::Null => "null",
1054            Token::Package => "package",
1055            Token::Packed => "packed",
1056            Token::Priority => "priority",
1057            Token::Program => "program",
1058            Token::Property => "property",
1059            Token::Protected => "protected",
1060            Token::Pure => "pure",
1061            Token::Rand => "rand",
1062            Token::Randc => "randc",
1063            Token::Randcase => "randcase",
1064            Token::Randsequence => "randsequence",
1065            Token::Ref => "ref",
1066            Token::Return => "return",
1067            Token::Sequence => "sequence",
1068            Token::Shortint => "shortint",
1069            Token::Shortreal => "shortreal",
1070            Token::Solve => "solve",
1071            Token::Static => "static",
1072            Token::String => "string",
1073            Token::Struct => "struct",
1074            Token::Super => "super",
1075            Token::Tagged => "tagged",
1076            Token::This => "this",
1077            Token::Throughout => "throughout",
1078            Token::Timeprecision => "timeprecision",
1079            Token::Timeunit => "timeunit",
1080            Token::Type => "type",
1081            Token::Typedef => "typedef",
1082            Token::Union => "union",
1083            Token::Unique => "unique",
1084            Token::Var => "var",
1085            Token::Virtual => "virtual",
1086            Token::Void => "void",
1087            Token::WaitOrder => "wait_order",
1088            Token::Wildcard => "wildcard",
1089            Token::With => "with",
1090            Token::Within => "within",
1091            Token::AcceptOn => "accept_on",
1092            Token::Checker => "checker",
1093            Token::Endchecker => "endchecker",
1094            Token::Eventually => "eventually",
1095            Token::Global => "global",
1096            Token::Implies => "implies",
1097            Token::Let => "let",
1098            Token::Nexttime => "nexttime",
1099            Token::RejectOn => "reject_on",
1100            Token::Restrict => "restrict",
1101            Token::SAlways => "s_always",
1102            Token::SEventually => "s_eventually",
1103            Token::SNexttime => "s_nexttime",
1104            Token::SUntil => "s_until",
1105            Token::SUntilWith => "s_until_with",
1106            Token::Strong => "strong",
1107            Token::SyncAcceptOn => "sync_accept_on",
1108            Token::SyncRejectOn => "sync_reject_on",
1109            Token::Unique0 => "unique0",
1110            Token::Until => "until",
1111            Token::UntilWith => "until_with",
1112            Token::Untyped => "untyped",
1113            Token::Weak => "weak",
1114            Token::Implements => "implements",
1115            Token::Interconnect => "interconnect",
1116            Token::Nettype => "nettype",
1117            Token::Soft => "soft",
1118            Token::DirUnderscoreFile => "`__FILE__",
1119            Token::DirUnderscoreLine => "`__LINE__",
1120            Token::DirBeginKeywords => "`begin_keywords",
1121            Token::DirCelldefine => "`celldefine",
1122            Token::DirDefaultNettype => "`default_nettype",
1123            Token::DirDefine => "`define",
1124            Token::DirElse => "`else",
1125            Token::DirElsif => "`elsif",
1126            Token::DirEndKeywords => "`end_keywords",
1127            Token::DirEndcelldefine => "`endcelldefine",
1128            Token::DirEndif => "`endif",
1129            Token::DirIfdef => "`ifdef",
1130            Token::DirIfndef => "`ifndef",
1131            Token::DirInclude => "`include",
1132            Token::DirLine => "`line",
1133            Token::DirNounconnectedDrive => "`nounconnected_drive",
1134            Token::DirPragma => "`pragma",
1135            Token::DirResetall => "`resetall",
1136            Token::DirTimescale => "`timescale",
1137            Token::DirUnconnectedDrive => "`unconnected_drive",
1138            Token::DirUndef => "`undef",
1139            Token::DirUndefineall => "`undefineall",
1140            Token::Plus => "+",
1141            Token::Minus => "-",
1142            Token::Exclamation => "!",
1143            Token::Quest => "?",
1144            Token::Tilde => "~",
1145            Token::Amp => "&",
1146            Token::TildeAmp => "~&",
1147            Token::Pipe => "|",
1148            Token::TildePipe => "~|",
1149            Token::Caret => "^",
1150            Token::TildeCaret => "~^",
1151            Token::CaretTilde => "^~",
1152            Token::Star => "*",
1153            Token::Slash => "/",
1154            Token::Percent => "%",
1155            Token::EqEq => "==",
1156            Token::ExclEq => "!=",
1157            Token::PlusEq => "+=",
1158            Token::MinusEq => "-=",
1159            Token::StarEq => "*=",
1160            Token::SlashEq => "/=",
1161            Token::PercentEq => "%=",
1162            Token::AmpEq => "&=",
1163            Token::PipeEq => "|=",
1164            Token::CaretEq => "^=",
1165            Token::EqEqEq => "===",
1166            Token::ExclEqEq => "!==",
1167            Token::EqEqQuest => "==?",
1168            Token::ExclEqQuest => "!=?",
1169            Token::AmpAmp => "&&",
1170            Token::AmpAmpAmp => "&&&",
1171            Token::PipePipe => "||",
1172            Token::StarStar => "**",
1173            Token::Lt => "<",
1174            Token::LtEq => "<=",
1175            Token::Gt => ">",
1176            Token::GtEq => ">=",
1177            Token::GtGt => ">>",
1178            Token::LtLt => "<<",
1179            Token::GtGtEq => ">>=",
1180            Token::LtLtEq => "<<=",
1181            Token::GtGtGt => ">>>",
1182            Token::LtLtLt => "<<<",
1183            Token::GtGtGtEq => ">>>=",
1184            Token::LtLtLtEq => "<<<=",
1185            Token::MinusGt => "->",
1186            Token::MinusGtGt => "->>",
1187            Token::LtMinusGt => "<->",
1188            Token::PlusPlus => "++",
1189            Token::MinusMinus => "--",
1190            Token::PlusColon => "+:",
1191            Token::MinusColon => "-:",
1192            Token::PlusSlashMinus => "+/-",
1193            Token::PlusPercentMinus => "+%-",
1194            Token::Paren => "(",
1195            Token::EParen => ")",
1196            Token::Bracket => "[",
1197            Token::EBracket => "]",
1198            Token::Brace => "{",
1199            Token::EBrace => "}",
1200            Token::Colon => ":",
1201            Token::SColon => ";",
1202            Token::Apost => "'",
1203            Token::Comma => "a comma",
1204            Token::Period => ".",
1205            Token::Pound => "#",
1206            Token::Dollar => "$",
1207            Token::At => "@",
1208            Token::AtAt => "@@",
1209            Token::Eq => "=",
1210            Token::ColonColon => "::",
1211            Token::ColonEq => ":=",
1212            Token::ColonSlash => ":/",
1213            Token::PoundPound => "##",
1214            Token::PoundMinusPound => "#-#",
1215            Token::PoundEqPound => "#=#",
1216            Token::EqGt => "=>",
1217            Token::StarGt => "*>",
1218            Token::PipeMinusGt => "|->",
1219            Token::PipeEqGt => "|=>",
1220            Token::Bslash => r"\",
1221            Token::Std => "std",
1222            Token::PathpulseDollar => "PATHPULSE$",
1223            Token::Option => "option",
1224            Token::TypeOption => "type_option",
1225            Token::Randomize => "randomize",
1226            Token::Sample => "sample",
1227            Token::OneStep => "1step",
1228            Token::DollarSetup => "$setup",
1229            Token::DollarHold => "$hold",
1230            Token::DollarSetuphold => "$setuphold",
1231            Token::DollarRecovery => "$recovery",
1232            Token::DollarRemoval => "$removal",
1233            Token::DollarRecrem => "$recrem",
1234            Token::DollarSkew => "$skew",
1235            Token::DollarTimeskew => "$timeskew",
1236            Token::DollarFullskew => "$fullskew",
1237            Token::DollarPeriod => "$period",
1238            Token::DollarWidth => "$width",
1239            Token::DollarNochange => "$nochange",
1240            Token::DollarRoot => "$root",
1241            Token::DollarUnit => "$unit",
1242            Token::DollarFatal => "$fatal",
1243            Token::DollarError => "$error",
1244            Token::DollarWarning => "$warning",
1245            Token::DollarInfo => "$info",
1246            Token::OnelineComment(_text) => "<oneline comment>",
1247            Token::BlockComment(_text) => "<block comment>",
1248            Token::UnsignedNumber(_text) => "<unsigned number>",
1249            Token::FixedPointNumber(_text) => "<real number>",
1250            Token::BinaryNumber(_text) => "<binary number>",
1251            Token::OctalNumber(_text) => "<octal number>",
1252            Token::DecimalNumber(_text) => "<decimal number>",
1253            Token::HexNumber(_text) => "<hex number>",
1254            Token::ScientificNumber(_text) => "<scientific number>",
1255            Token::UnbasedUnsizedLiteral(_text) => "<unsized literal>",
1256            Token::SystemTfIdentifier(_text) => "<system tf identifier>",
1257            Token::SimpleIdentifier(_text) => "<simple identifier>",
1258            Token::EscapedIdentifier(_text) => "<escaped identifier>",
1259            Token::PreprocessorIdentifier(_text) => "<preprocessor identifier>",
1260            Token::TextMacro(_text) => "<text macro>",
1261            Token::StringLiteral(_text) => "<string>",
1262            Token::PreprocessorStringLiteral(_text) => "<preprocessor string>",
1263            Token::TripleQuoteStringLiteral(_text) => "<triple-quote string>",
1264            Token::PreprocessorTripleQuoteStringLiteral(_text) => {
1265                "<preprocessor triple-quote string>"
1266            }
1267            Token::Newline => "newline",
1268        }
1269    }
1270}
1271
1272impl<'a> fmt::Display for Token<'a> {
1273    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1274        let temp_str: String;
1275        let str_repr = match self {
1276            Token::OnelineComment(text) => {
1277                temp_str = format!("comment '{}'", text);
1278                temp_str.as_str()
1279            }
1280            Token::BlockComment(text) => {
1281                temp_str = format!("block comment '{}'", text);
1282                temp_str.as_str()
1283            }
1284            Token::UnsignedNumber(text) => {
1285                temp_str = format!("number '{}' ", text);
1286                temp_str.as_str()
1287            }
1288            Token::FixedPointNumber(text) => {
1289                temp_str = format!("real number '{}' ", text);
1290                temp_str.as_str()
1291            }
1292            Token::BinaryNumber(text) => {
1293                temp_str = format!("binary number '{}' ", text);
1294                temp_str.as_str()
1295            }
1296            Token::OctalNumber(text) => {
1297                temp_str = format!("octal number '{}' ", text);
1298                temp_str.as_str()
1299            }
1300            Token::DecimalNumber(text) => {
1301                temp_str = format!("decimal number '{}' ", text);
1302                temp_str.as_str()
1303            }
1304            Token::HexNumber(text) => {
1305                temp_str = format!("hexadecimal number '{}' ", text);
1306                temp_str.as_str()
1307            }
1308            Token::ScientificNumber(text) => {
1309                temp_str = format!("real number '{}' ", text);
1310                temp_str.as_str()
1311            }
1312            Token::UnbasedUnsizedLiteral(text) => {
1313                temp_str = format!("unsized literal '{}' ", text);
1314                temp_str.as_str()
1315            }
1316            Token::SystemTfIdentifier(text) => {
1317                temp_str = format!("{}", text);
1318                temp_str.as_str()
1319            }
1320            Token::SimpleIdentifier(text) => {
1321                temp_str = format!("identifier '{}'", text);
1322                temp_str.as_str()
1323            }
1324            Token::EscapedIdentifier(text) => {
1325                temp_str = format!("escaped identifier '{}'", text);
1326                temp_str.as_str()
1327            }
1328            Token::PreprocessorIdentifier(text) => {
1329                temp_str = format!("preprocessor identifier '{}'", text);
1330                temp_str.as_str()
1331            }
1332            Token::TextMacro(text) => {
1333                temp_str = format!("text macro '{}'", text);
1334                temp_str.as_str()
1335            }
1336            Token::StringLiteral(text) => {
1337                temp_str = format!("string \"{}\"", text);
1338                temp_str.as_str()
1339            }
1340            Token::PreprocessorStringLiteral(text) => {
1341                temp_str = format!("preprocessor string `\"{}`\"", text);
1342                temp_str.as_str()
1343            }
1344            Token::TripleQuoteStringLiteral(text) => {
1345                temp_str = format!("string \"\"\"{}\"\"\"", text);
1346                temp_str.as_str()
1347            }
1348            Token::PreprocessorTripleQuoteStringLiteral(text) => {
1349                temp_str =
1350                    format!("preprocessor string `\"\"\"{}`\"\"\"", text);
1351                temp_str.as_str()
1352            }
1353            _ => self.as_str(),
1354        };
1355        write!(f, "{}", str_repr)
1356    }
1357}