sway_error/
parser_error.rs1use sway_types::ast::PunctKind;
2use sway_types::{Ident, Span};
3use thiserror::Error;
4
5#[derive(Debug, Error, Clone, PartialEq, Eq, Hash)]
6pub enum ParseErrorKind {
7 #[error("Expected an import name, group of imports, or `*`.")]
8 ExpectedImportNameGroupOrGlob,
9 #[error("Expected an item.")]
10 ExpectedAnItem,
11 #[error("Expected an item after doc comment.")]
12 ExpectedAnItemAfterDocComment,
13 #[error("Expected a comma or closing parenthesis in function arguments.")]
14 ExpectedCommaOrCloseParenInFnArgs,
15 #[error("Unknown assembly instruction.")]
16 UnrecognizedOpCode {
17 known_op_codes: &'static [&'static str],
18 },
19 #[error("Unexpected token in statement.")]
20 UnexpectedTokenInStatement,
21 #[error("This expression cannot be assigned to.")]
22 UnassignableExpression {
23 erroneous_expression_kind: &'static str,
27 erroneous_expression_span: Span,
32 },
33 #[error("Unexpected token after array index.")]
34 UnexpectedTokenAfterArrayIndex,
35 #[error("Invalid literal to use as a field name.")]
36 InvalidLiteralFieldName,
37 #[error("Invalid statement.")]
38 InvalidStatement,
39 #[error("Invalid item.")]
40 InvalidItem,
41 #[error("Integer field names cannot have type suffixes.")]
42 IntFieldWithTypeSuffix,
43 #[error("Expected a field name.")]
44 ExpectedFieldName,
45 #[error("Expected a comma or closing parenthesis in this tuple or parenthesized expression.")]
46 ExpectedCommaOrCloseParenInTupleOrParenExpression,
47 #[error("Expected an expression.")]
48 ExpectedExpression,
49 #[error("Unexpected token after array length.")]
50 UnexpectedTokenAfterArrayLength,
51 #[error("Expected a comma, semicolon or closing bracket when parsing this array.")]
52 ExpectedCommaSemicolonOrCloseBracketInArray,
53 #[error("Unexpected token after asm return type.")]
54 UnexpectedTokenAfterAsmReturnType,
55 #[error("Malformed asm immediate value.")]
56 MalformedAsmImmediate,
57 #[error("Expected an identifier.")]
58 ExpectedIdent,
59 #[error("Expected an pattern.")]
60 ExpectedPattern,
61 #[error("Unexpected token after str length.")]
62 UnexpectedTokenAfterStrLength,
63 #[error("Expected a type.")]
64 ExpectedType,
65 #[error("Unexpected token after array type length.")]
66 UnexpectedTokenAfterArrayTypeLength,
67 #[error("Expected an opening brace.")]
68 ExpectedOpenBrace,
69 #[error("Expected an opening parenthesis.")]
70 ExpectedOpenParen,
71 #[error("Expected an opening square bracket.")]
72 ExpectedOpenBracket,
73 #[error("Expected a literal.")]
74 ExpectedLiteral,
75 #[error("Expected a module kind (script, contract, predicate or library).")]
76 ExpectedModuleKind,
77 #[error("Expected `{}`.", kinds.iter().map(PunctKind::as_char).collect::<String>())]
78 ExpectedPunct { kinds: Vec<PunctKind> },
79 #[error("Expected `{}`.", word)]
80 ExpectedKeyword { word: &'static str },
81 #[error("Unexpected token after abi address.")]
82 UnexpectedTokenAfterAbiAddress,
83 #[error("Expected an attribute.")]
84 ExpectedAnAttribute,
85 #[error("Unexpected token after an attribute.")]
86 UnexpectedTokenAfterAttribute,
87 #[error("Identifiers cannot begin with a double underscore, as that naming convention is reserved for compiler intrinsics.")]
88 InvalidDoubleUnderscore,
89 #[error("Unexpected rest token, must be at the end of pattern.")]
90 UnexpectedRestPattern,
91 #[error("Identifiers cannot be a reserved keyword.")]
92 ReservedKeywordIdentifier,
93 #[error("Unnecessary visibility qualifier, `{}` is implied here.", visibility)]
94 UnnecessaryVisibilityQualifier { visibility: Ident },
95 #[error("Expected a doc comment.")]
96 ExpectedDocComment,
97 #[error("Top of file doc comments are reserved for module level documentation.\nTry using the `//!` syntax.")]
98 ExpectedModuleDocComment,
99 #[error("Use the `struct` keyword to define records, instead of `class`.")]
100 UnexpectedClass,
101 #[error("Field projections, e.g., `foo.bar` cannot have type arguments.")]
102 FieldProjectionWithGenericArgs,
103 #[error("Unexpected token after __ptr type.")]
104 UnexpectedTokenAfterPtrType,
105 #[error("Unexpected token after __slice type.")]
106 UnexpectedTokenAfterSliceType,
107 #[error("Expected a path type.")]
108 ExpectedPathType,
109 #[error("Expected ':'. Enum variants must be in the form `Variant: ()`, `Variant: <type>`, or `Variant: (<type1>, ..., <typeN>)`. E.g., `Foo: (), or `Bar: (bool, u32)`.")]
110 MissingColonInEnumTypeField,
111 #[error("Expected storage key of type U256.")]
112 ExpectedStorageKeyU256,
113}
114
115#[derive(Debug, Error, Clone, PartialEq, Eq, Hash)]
116#[error("{}", kind)]
117pub struct ParseError {
118 pub span: Span,
119 pub kind: ParseErrorKind,
120}