pub enum PreprocessorError<'a> {
Show 27 variants
Endif {
endif_span: Span<'a>,
},
NoEndif {
cond_token: Token<'a>,
cond_token_span: Span<'a>,
},
Elsif {
elsif_span: Span<'a>,
},
Else {
else_span: Span<'a>,
},
EndKeywords {
end_keywords_span: Span<'a>,
},
NoEndKeywords {
begin_keywords_span: Span<'a>,
},
InvalidDefineParameter {
other_token: Token<'a>,
other_span: Span<'a>,
},
InvalidDefineArgument {
other_token: Token<'a>,
other_span: Span<'a>,
},
InvalidVersionSpecifier {
invalid_version: Token<'a>,
invalid_version_span: Span<'a>,
},
IncompleteDirective {
directive_span: Span<'a>,
},
IncompleteDefine {
other_token: Token<'a>,
other_span: Span<'a>,
},
UndefinedMacro {
undefined_name: &'a str,
undefined_span: Span<'a>,
},
DuplicateMacroParameter {
define_name: &'a str,
param_name: &'a str,
dup_span: Span<'a>,
prev_span: Span<'a>,
},
NoDefaultAfterDefault {
default_param: &'a str,
default_param_span: Span<'a>,
non_default_param: &'a str,
non_default_param_span: Span<'a>,
},
NoMacroArguments {
macro_name: &'a str,
define_span: Span<'a>,
use_span: Span<'a>,
},
TooManyMacroArguments {
macro_name: &'a str,
define_span: Span<'a>,
use_span: Span<'a>,
expected: usize,
found: usize,
},
MissingMacroArgument {
define_span: Span<'a>,
use_span: Span<'a>,
param_name: &'a str,
},
InvalidIdentifierFormation {
param_name: &'a str,
arg_span: Span<'a>,
},
InvalidRelativeTimescales {
timescale_span: Span<'a>,
},
IncompleteMacroWithToken {
error_token: Token<'a>,
error_span: Span<'a>,
},
Include {
include_path: &'a str,
include_path_span: Span<'a>,
read_err: ErrorKind,
},
IncludeDepth {
include_span: Span<'a>,
},
VerboseError {
err: VerboseError<'a>,
},
NotPreviouslyDefinedMacro {
macro_name: &'a str,
macro_span: Span<'a>,
},
RedefinedMacro {
macro_name: &'a str,
redef_span: Span<'a>,
prev_def_span: Span<'a>,
},
NewlineInDefine(Span<'a>),
EndOfFunctionArgument(SpannedToken<'a>),
}Expand description
An error encountered during preprocessing
As preprocessing can affect the interpretation of later source code, these errors are often irrecoverable
Errors marked with INTERNAL are meant for use inside the preprocessor for passing information, and should not be returned
Variants§
Endif
An `endif encountered outside a conditional preprocessor block
let source = "
`endif
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Endif{ .. })));NoEndif
No terminating `endif for a conditional preprocessor block
let source = "
`ifdef TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoEndif{
cond_token: Token::DirIfdef,
..
})));Fields
cond_token: Token<'a>The conditional token (either Token::DirIfdef, Token::DirIfndef,
Token::DirElsif, or Token::DirElse) with no matching `endif
Elsif
An `elsif encountered outside a conditional preprocessor block
let source = "
`elsif
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Elsif{ .. })));Else
An `else encountered outside a conditional preprocessor block
let source = "
`else
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Else{ .. })));EndKeywords
An `end_keywords encountered outside a `begin_keywords block
let source = "
`end_keywords
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::EndKeywords{ .. })));NoEndKeywords
No terminating `end_keywords for a `begin_keywords block
let source = "
`begin_keywords \"1800-2009\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoEndKeywords{ .. })));InvalidDefineParameter
A missing parameter in a `define function declaration where one is expected
let source = "
`define TEST()
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidDefineParameter{
other_token: Token::EParen,
..
})));Fields
InvalidDefineArgument
A missing or invalid argument specification in a `define function
let source = "
`define TEST(a, b c)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidDefineArgument{
other_token: Token::SimpleIdentifier("c"),
..
})));Fields
InvalidVersionSpecifier
An invalid version specifier for a `begin_keywords directive
let source = "
`begin_keywords \"MyVersion\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidVersionSpecifier{
invalid_version: Token::StringLiteral("MyVersion"),
..
})));Fields
invalid_version: Token<'a>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
IncompleteDirective
A directive that doesn’t have all of the required components
In general, PreprocessorError::VerboseError is preferred, but may
not be suitable due to a lack of subsequent tokens
let source = "`line";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteDirective{ .. })));Fields
IncompleteDefine
An incomplete preprocessor definition, specifically with function macro arguments
let source = "
`define TEST(
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteDefine{
other_token: Token::Paren,
..
})));Fields
other_token: Token<'a>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
UndefinedMacro
Use of a text macro that wasn’t previously defined
let source = "
`TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::UndefinedMacro{
undefined_name: "TEST",
..
})));Fields
DuplicateMacroParameter
Specifying a macro parameter that was already specified
let source = "
`define TEST(a, b, a) a + b
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::DuplicateMacroParameter{
define_name: "TEST",
param_name: "a",
..
})));Fields
NoDefaultAfterDefault
Attempting to have a macro parameter with no default value after one that does
let source = "
`define TEST(a = 1, b) a + b
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoDefaultAfterDefault{
default_param: "a",
non_default_param: "b",
..
})));Fields
NoMacroArguments
Specifying no arguments for a macro function that takes arguments
let source = "
`define TEST(a, b) a + b
`TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NoMacroArguments{
macro_name: "TEST",
..
})));Fields
TooManyMacroArguments
Specifying too many arguments for a macro function
let source = "
`define TEST(a, b) a + b
`TEST(1, 2, 3)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::TooManyMacroArguments{
macro_name: "TEST",
expected: 2,
found: 3,
..
})));Fields
MissingMacroArgument
Missing an argument in a macro function use
let source = "
`define TEST(a, b) a + b
`TEST(1)
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::MissingMacroArgument{
param_name: "b",
..
})));Fields
InvalidIdentifierFormation
An invalid preprocessor identifier specification
let source = "
`define TEST(a, b) a``_with_``b
`TEST(\"one\", \"two\")
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidIdentifierFormation{
param_name: "a",
..
})));Fields
InvalidRelativeTimescales
A precision that is less precise than the unit in a `timescale directive
let source = "
`timescale 100 fs / 1 s
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::InvalidRelativeTimescales{ .. })));IncompleteMacroWithToken
An incomplete macro due to mismatching grouping tokens ([], (), or {})
let source = "
`define TEST(a, b) a + b
`TEST(a = 1, b = 2])
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncompleteMacroWithToken{
error_token: Token::EBracket,
..
})));Fields
error_token: Token<'a>The error-causing Token (either Token::EParen,
Token::EBracket, or Token::EBrace)
Include
An error reading a file specified by an `include macro
let source = "
`include \"other.v\"
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::Include{
include_path: "other.v",
..
})));Fields
read_err: ErrorKindThe io::ErrorKind raised when attempting to read the file
IncludeDepth
The maximum include depth was hit, likely as a result of a self-referential
`include sequence
let source = "
`include \"test.v\"
";
state.retain_file(
"test.v".to_string(),
source.to_string(),
&cache,
);
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::IncludeDepth{ .. })));VerboseError
A VerboseError detailing the expected and found tokens, for a case not covered above
This is most commonly used when we can provide the user with a bit more context
let source = "
`line
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
// Expects a line number
assert!(preprocess_result.is_err());
assert!(matches!(state.errors.first(), Some(PreprocessorError::VerboseError{
err: VerboseError{
found: Some(Token::Newline),
..
}
})));Fields
err: VerboseError<'a>The VerboseError for the preprocessor error
NotPreviouslyDefinedMacro
Attempted to `undef a macro that had no previous definition
let source = "
`undef TEST
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_ok());
assert!(matches!(state.errors.first(), Some(PreprocessorError::NotPreviouslyDefinedMacro{
macro_name: "TEST",
..
})))Fields
RedefinedMacro
A redefinition of a text macro that was previously defined
let source = "
`define TEST definition_one
`define TEST definition_two
";
let input = lex(source, "test.v").tokens();
let preprocess_result = preprocess(
input,
&mut state,
&cache,
);
assert!(preprocess_result.is_ok());
assert!(matches!(state.errors.first(), Some(PreprocessorError::RedefinedMacro{
macro_name: "TEST",
..
})))Fields
NewlineInDefine(Span<'a>)
INTERNAL: A newline encountered in a `define directive
EndOfFunctionArgument(SpannedToken<'a>)
INTERNAL: The end of a function argument was encountered
Implementations§
Source§impl<'a> PreprocessorError<'a>
impl<'a> PreprocessorError<'a>
Sourcepub fn is_warning(&self) -> bool
pub fn is_warning(&self) -> bool
Whether the given PreprocessorError is just a warning
Warnings reflect an irregularity in the source code, but are still well-defined and allow preprocessing to continue
Trait Implementations§
Source§impl<'a> Clone for PreprocessorError<'a>
impl<'a> Clone for PreprocessorError<'a>
Source§fn clone(&self) -> PreprocessorError<'a>
fn clone(&self) -> PreprocessorError<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for PreprocessorError<'a>
impl<'a> Debug for PreprocessorError<'a>
Source§impl<'s> From<&PreprocessorError<'s>> for Report
impl<'s> From<&PreprocessorError<'s>> for Report
Source§fn from(s: &PreprocessorError<'s>) -> Self
fn from(s: &PreprocessorError<'s>) -> Self
Source§impl<'a> PartialEq for PreprocessorError<'a>
impl<'a> PartialEq for PreprocessorError<'a>
impl<'a> StructuralPartialEq for PreprocessorError<'a>
Auto Trait Implementations§
impl<'a> Freeze for PreprocessorError<'a>
impl<'a> RefUnwindSafe for PreprocessorError<'a>
impl<'a> Send for PreprocessorError<'a>
impl<'a> Sync for PreprocessorError<'a>
impl<'a> Unpin for PreprocessorError<'a>
impl<'a> UnsafeUnpin for PreprocessorError<'a>
impl<'a> UnwindSafe for PreprocessorError<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);