Classes

General

final class Bytes

A reference to a specific slice of a source file, with start and end byte offsets

start: int

The byte-offset of the start of the slice (inclusive)

end: int

The byte-offset of the end of the slice (exclusive)

class Define

A preprocessor definition

Users will likely want to use the helper functions define_empty() and define_text() to create Define instances

name: str

The name being defined

body: list[SpannedToken] | None

The replacement tokens, if any, to use

class Expectation

An expectation of what to find (instead of what was found while parsing)

final class EOI(Expectation)

The end of a file

final class Label(Expectation)

A verbose human-readable label

property label: str

The label text

final class Token(Expectation)

A specific token

property token: Token

The expected token

final class Node

A single CST node

In addition to providing information about itself, Nodes are also iterable (i.e. support the for node in node: syntax), which will produce both the original node, as well as all children nodes in the tree (recursively, depth-first)

name: str

The name of the Node

See the corresponding Rust documentation to see the possible names

span: Span

The span of the Node

property text: str

The text in the source code that the Node corresponds to

This is the same as getting Span.text from the Node.span

children: list[Node]

All direct children of the Node in the CST

final class Span

Provides a location in the source code where a Node was found

file: str

The name of the file containing the source code

bytes: Bytes

The byte-span of the Span within the file

property text: str

The exact text in the source file that the Span refers to (retrieved lazily for each access)

final class SpannedToken

A source Token with an associated Span

token: Token
span: Span
class Token

A single semantic token

Child Variants
class AcceptOn(Token)
class Alias(Token)
class Always(Token)
class AlwaysComb(Token)
class AlwaysFf(Token)
class AlwaysLatch(Token)
class Amp(Token)
class AmpAmp(Token)
class AmpAmpAmp(Token)
class AmpEq(Token)
class And(Token)
class Apost(Token)
class Assert(Token)
class Assign(Token)
class Assume(Token)
class At(Token)
class AtAt(Token)
class Automatic(Token)
class Before(Token)
class Begin(Token)
class BinaryNumber(Token)
property text: str

The text referenced by the token

class Bind(Token)
class Bins(Token)
class Binsof(Token)
class Bit(Token)
class BlockComment(Token)
property text: str

The text referenced by the token

class Brace(Token)
class Bracket(Token)
class Break(Token)
class Bslash(Token)
class Buf(Token)
class Bufif0(Token)
class Bufif1(Token)
class Byte(Token)
class Caret(Token)
class CaretEq(Token)
class CaretTilde(Token)
class Case(Token)
class Casex(Token)
class Casez(Token)
class Cell(Token)
class Chandle(Token)
class Checker(Token)
class Class(Token)
class Clocking(Token)
class Cmos(Token)
class Colon(Token)
class ColonColon(Token)
class ColonEq(Token)
class ColonSlash(Token)
class Comma(Token)
class Config(Token)
class Const(Token)
class Constraint(Token)
class Context(Token)
class Continue(Token)
class Cover(Token)
class Covergroup(Token)
class Coverpoint(Token)
class Cross(Token)
class Deassign(Token)
class DecimalNumber(Token)
property text: str

The text referenced by the token

class Default(Token)
class Defparam(Token)
class Design(Token)
class DirBeginKeywords(Token)
class DirCelldefine(Token)
class DirDefaultNettype(Token)
class DirDefine(Token)
class DirElse(Token)
class DirElsif(Token)
class DirEndKeywords(Token)
class DirEndcelldefine(Token)
class DirEndif(Token)
class DirIfdef(Token)
class DirIfndef(Token)
class DirInclude(Token)
class DirLine(Token)
class DirNounconnectedDrive(Token)
class DirPragma(Token)
class DirResetall(Token)
class DirTimescale(Token)
class DirUnconnectedDrive(Token)
class DirUndef(Token)
class DirUndefineall(Token)
class DirUnderscoreFile(Token)
class DirUnderscoreLine(Token)
class Disable(Token)
class Dist(Token)
class Do(Token)
class Dollar(Token)
class DollarError(Token)
class DollarFatal(Token)
class DollarFullskew(Token)
class DollarHold(Token)
class DollarInfo(Token)
class DollarNochange(Token)
class DollarPeriod(Token)
class DollarRecovery(Token)
class DollarRecrem(Token)
class DollarRemoval(Token)
class DollarRoot(Token)
class DollarSetup(Token)
class DollarSetuphold(Token)
class DollarSkew(Token)
class DollarTimeskew(Token)
class DollarUnit(Token)
class DollarWarning(Token)
class DollarWidth(Token)
class EBrace(Token)
class EBracket(Token)
class EParen(Token)
class Edge(Token)
class Else(Token)
class End(Token)
class Endcase(Token)
class Endchecker(Token)
class Endclass(Token)
class Endclocking(Token)
class Endconfig(Token)
class Endfunction(Token)
class Endgenerate(Token)
class Endgroup(Token)
class Endinterface(Token)
class Endmodule(Token)
class Endpackage(Token)
class Endprimitive(Token)
class Endprogram(Token)
class Endproperty(Token)
class Endsequence(Token)
class Endspecify(Token)
class Endtable(Token)
class Endtask(Token)
class Enum(Token)
class Eq(Token)
class EqEq(Token)
class EqEqEq(Token)
class EqEqQuest(Token)
class EqGt(Token)
class Error(Token)

A lexer error (unrecognized input)

class EscapedIdentifier(Token)
property text: str

The text referenced by the token

class Event(Token)
class Eventually(Token)
class ExclEq(Token)
class ExclEqEq(Token)
class ExclEqQuest(Token)
class Exclamation(Token)
class Expect(Token)
class Export(Token)
class Extends(Token)
class Extern(Token)
class Final(Token)
class FirstMatch(Token)
class FixedPointNumber(Token)
property text: str

The text referenced by the token

class For(Token)
class Force(Token)
class Foreach(Token)
class Forever(Token)
class Fork(Token)
class Forkjoin(Token)
class Function(Token)
class Generate(Token)
class Genvar(Token)
class Global(Token)
class Gt(Token)
class GtEq(Token)
class GtGt(Token)
class GtGtEq(Token)
class GtGtGt(Token)
class GtGtGtEq(Token)
class HexNumber(Token)
property text: str

The text referenced by the token

class Highz0(Token)
class Highz1(Token)
class If(Token)
class Iff(Token)
class Ifnone(Token)
class IgnoreBins(Token)
class IllegalBins(Token)
class Implements(Token)
class Implies(Token)
class Import(Token)
class Incdir(Token)
class Include(Token)
class Initial(Token)
class Inout(Token)
class Input(Token)
class Inside(Token)
class Instance(Token)
class Int(Token)
class Integer(Token)
class Interconnect(Token)
class Interface(Token)
class Intersect(Token)
class Join(Token)
class JoinAny(Token)
class JoinNone(Token)
class Large(Token)
class Let(Token)
class Liblist(Token)
class Library(Token)
class Local(Token)
class Localparam(Token)
class Logic(Token)
class Longint(Token)
class Lt(Token)
class LtEq(Token)
class LtLt(Token)
class LtLtEq(Token)
class LtLtLt(Token)
class LtLtLtEq(Token)
class LtMinusGt(Token)
class Macromodule(Token)
class Matches(Token)
class Medium(Token)
class Minus(Token)
class MinusColon(Token)
class MinusEq(Token)
class MinusGt(Token)
class MinusGtGt(Token)
class MinusMinus(Token)
class Modport(Token)
class Module(Token)
class Nand(Token)
class Negedge(Token)
class Nettype(Token)
class New(Token)
class Newline(Token)
class Nexttime(Token)
class Nmos(Token)
class Nor(Token)
class Noshowcancelled(Token)
class Not(Token)
class Notif0(Token)
class Notif1(Token)
class Null(Token)
class OctalNumber(Token)
property text: str

The text referenced by the token

class OneStep(Token)
class OnelineComment(Token)
property text: str

The text referenced by the token

class Option(Token)
class Or(Token)
class Output(Token)
class Package(Token)
class Packed(Token)
class Parameter(Token)
class Paren(Token)
class PathpulseDollar(Token)
class Percent(Token)
class PercentEq(Token)
class Period(Token)
class Pipe(Token)
class PipeEq(Token)
class PipeEqGt(Token)
class PipeMinusGt(Token)
class PipePipe(Token)
class Plus(Token)
class PlusColon(Token)
class PlusEq(Token)
class PlusPercentMinus(Token)
class PlusPlus(Token)
class PlusSlashMinus(Token)
class Pmos(Token)
class Posedge(Token)
class Pound(Token)
class PoundEqPound(Token)
class PoundMinusPound(Token)
class PoundPound(Token)
class PreprocessorIdentifier(Token)
property text: str

The text referenced by the token

class PreprocessorStringLiteral(Token)
property text: str

The text referenced by the token

class PreprocessorTripleQuoteStringLiteral(Token)
property text: str

The text referenced by the token

class Primitive(Token)
class Priority(Token)
class Program(Token)
class Property(Token)
class Protected(Token)
class Pull0(Token)
class Pull1(Token)
class Pulldown(Token)
class Pullup(Token)
class PulsestyleOndetect(Token)
class PulsestyleOnevent(Token)
class Pure(Token)
class Quest(Token)
class Rand(Token)
class Randc(Token)
class Randcase(Token)
class Randomize(Token)
class Randsequence(Token)
class Rcmos(Token)
class Real(Token)
class Realtime(Token)
class Ref(Token)
class Reg(Token)
class RejectOn(Token)
class Release(Token)
class Repeat(Token)
class Restrict(Token)
class Return(Token)
class Rnmos(Token)
class Rpmos(Token)
class Rtran(Token)
class Rtranif0(Token)
class Rtranif1(Token)
class SAlways(Token)
class SColon(Token)
class SEventually(Token)
class SNexttime(Token)
class SUntil(Token)
class SUntilWith(Token)
class Sample(Token)
class Scalared(Token)
class ScientificNumber(Token)
property text: str

The text referenced by the token

class Sequence(Token)
class Shortint(Token)
class Shortreal(Token)
class Showcancelled(Token)
class Signed(Token)
class SimpleIdentifier(Token)
property text: str

The text referenced by the token

class Slash(Token)
class SlashEq(Token)
class Small(Token)
class Soft(Token)
class Solve(Token)
class Specify(Token)
class Specparam(Token)
class Star(Token)
class StarEq(Token)
class StarGt(Token)
class StarStar(Token)
class Static(Token)
class Std(Token)
class String(Token)
class StringLiteral(Token)
property text: str

The text referenced by the token

class Strong(Token)
class Strong0(Token)
class Strong1(Token)
class Struct(Token)
class Super(Token)
class Supply0(Token)
class Supply1(Token)
class SyncAcceptOn(Token)
class SyncRejectOn(Token)
class SystemTfIdentifier(Token)
property text: str

The text referenced by the token

class Table(Token)
class Tagged(Token)
class Task(Token)
class TextMacro(Token)
property text: str

The text referenced by the token

class This(Token)
class Throughout(Token)
class Tilde(Token)
class TildeAmp(Token)
class TildeCaret(Token)
class TildePipe(Token)
class Time(Token)
class Timeprecision(Token)
class Timeunit(Token)
class Tran(Token)
class Tranif0(Token)
class Tranif1(Token)
class Tri(Token)
class Tri0(Token)
class Tri1(Token)
class Triand(Token)
class Trior(Token)
class TripleQuoteStringLiteral(Token)
property text: str

The text referenced by the token

class Trireg(Token)
class Type(Token)
class TypeOption(Token)
class Typedef(Token)
class UnbasedUnsizedLiteral(Token)
property text: str

The text referenced by the token

class Union(Token)
class Unique(Token)
class Unique0(Token)
class Unsigned(Token)
class UnsignedNumber(Token)
property text: str

The text referenced by the token

class Until(Token)
class UntilWith(Token)
class Untyped(Token)
class Use(Token)
class Uwire(Token)
class Var(Token)
class Vectored(Token)
class Virtual(Token)
class Void(Token)
class Wait(Token)
class WaitOrder(Token)
class Wand(Token)
class Weak(Token)
class Weak0(Token)
class Weak1(Token)
class While(Token)
class Wildcard(Token)
class Wire(Token)
class With(Token)
class Within(Token)
class Wor(Token)
class Xnor(Token)
class Xor(Token)
final class VerboseError

An error describing a Token that was found and didn’t match expectations

found: Token | None

What token was found - None if the end of the file was reached

expected: list[Expectation]

What was expected instead (listing all possibilities)

span: Span

The Span that the error occurred at (where the found token is)

Preprocessing

class PreprocessorError

An error that arose during preprocessing

See the Rust documentation for the semantics of each variant

Child Variants
class DuplicateMacroParameter(PreprocessorError)
property define_name: str

The name of the macro for which duplicate parameters were specified

property dup_span: Span

The Span of the duplicate specification

property param_name: str

The name of the parameter that was specified multiple times

property prev_span: Span

The Span of the previous/original specification

class Else(PreprocessorError)
property else_span: Span

The Span of the else

class Elsif(PreprocessorError)
property elsif_span: Span

The Span of the elsif

class EndKeywords(PreprocessorError)
property end_keywords_span: Span

The Span of the end_keywords

class Endif(PreprocessorError)
property endif_span: Span

The Span of the endif

class Include(PreprocessorError)
property include_path: str

The path for the include directive

property include_path_span: Span

The Span of the include path

property read_err: str

The I/O error raised when attempting to read the file

class IncludeDepth(PreprocessorError)
property include_span: Span

The Span of the include directive that exceeded the limit

class IncompleteDefine(PreprocessorError)
property other_span: Span

The Span of the token found instead

property other_token: Token

If known, the Token found instead of a valid function macro argument specification

In the case that the token wasn’t tracked, the opening Token.Paren is referenced instead

class IncompleteDirective(PreprocessorError)
property directive_span: Span

The Span of the incomplete preprocessor directive

This is usually the primary directive, but can be other more indicative tokens as well, such as an unmatched opening parenthesis

class IncompleteMacroWithToken(PreprocessorError)
property error_span: Span

The error-causing Span

property error_token: Token

The error-causing Token (either Token::EParen, Token::EBracket, or Token::EBrace)

class InvalidDefineArgument(PreprocessorError)
property other_span: Span

The Span of the token found instead

property other_token: Token

The Token found instead of the valid define argument

class InvalidDefineParameter(PreprocessorError)
property other_span: Span

The Span of the token found instead

property other_token: Token

The Token found instead of the define parameter

class InvalidIdentifierFormation(PreprocessorError)
property arg_span: Span

The Span of the invalid argument

property param_name: str

The name of the parameter used in a preprocessor identifier

class InvalidRelativeTimescales(PreprocessorError)
property timescale_span: Span

The Span of the timescale directive

class InvalidVersionSpecifier(PreprocessorError)
property invalid_version: Token

The Token provided instead of a valid version specifier

If the token is a Token::StringLiteral, the string isn’t a version recognized by 1800-2023

property invalid_version_span: Span

The Span of the invalid version specifier

class MissingMacroArgument(PreprocessorError)
property define_span: Span

The Span of the macro definition

property param_name: str

The name of the missing parameter

property use_span: Span

The Span where the macro was used with a missing argument

class NoDefaultAfterDefault(PreprocessorError)
property default_param: str

The name of the previously-specified default parameter

property default_param_span: Span

The Span of the previously-specified default parameter

property non_default_param: str

The name of the non-default parameter

property non_default_param_span: Span

The Span of the non-default parameter

class NoEndKeywords(PreprocessorError)
property begin_keywords_span: Span

The Span of the unterminated begin_keywords

class NoEndif(PreprocessorError)
property cond_token: Token

The conditional token (either Token::DirIfdef, Token::DirIfndef, Token::DirElsif, or Token::DirElse) with no matching `` endif `

property cond_token_span: Span

The Span of the conditional token

class NoMacroArguments(PreprocessorError)
property define_span: Span

The Span of the macro definition (with arguments)

property macro_name: str

The name of the macro

property use_span: Span

The Span where the macro was used with no arguments

class NotPreviouslyDefinedMacro(PreprocessorError)
property macro_name: str

The name that wasn’t previously defined

property macro_span: Span

The Span where the not-previously-defined name was specified

class RedefinedMacro(PreprocessorError)
property macro_name: str

The name of the macro being redefined

property prev_def_span: Span

The Span where the macro was previously defined

property redef_span: Span

The Span of the redefinition

class TooManyMacroArguments(PreprocessorError)
property define_span: Span

The Span of the macro definition

property expected: int

How many arguments were expected

property found: int

How many arguments were found

property macro_name: str

The name of the macro

property use_span: Span

The Span where the macro was used with too many arguments

class UndefinedMacro(PreprocessorError)
property undefined_name: str

The name of the undefined macro

property undefined_span: Span

The Span of the undefined macro

class VerboseError(PreprocessorError)
property err: VerboseError

The [VerboseError] for the preprocessor error

class PreprocessorResult

The result of preprocessing a SystemVerilog source

final class Ok(PreprocessorResult)

A successfully preprocessed token stream

property tokens: list[SpannedToken]
final class Err(PreprocessorResult)

Error(s) that occurred during preprocessing

property errors: list[PreprocessorError]

Parsing

class ParserResult

The result of parsing a SystemVerilog source

final class Ok(ParserResult)

A successfully parsed CST

property root: Node

The root of the CST (representing the SourceText Node)

final class PreprocessorErr(ParserResult)

Error(s) that occurred during preprocessing

property errors: list[PreprocessorError]
final class ParserErr(ParserResult)

An error that resulted during parsing

property error: VerboseError

Reporting

class Report(kind: ReportKind, span: Span, code: String, msg: String)

A report detailing an error when consuming a source file, including a location in that file.

This does not label/print the location; to do so, use Report.label()

eprint()

Print the Report to stdout

include(file_name: str, file_content: str)

Include additional files to use when printing.

Use this when the Span.file used in a Report does not correspond to an actual file on the file system

label(span: Span, kind: ReportKind, msg: str)

Include a labeled section of source code in the Report

print()

Print the Report to stdout

class ReportKind

The type of report being generated, used for coloring output

class Advice(ReportKind)
class Error(ReportKind)
class Note(ReportKind)
class Warning(ReportKind)