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