1#![warn(missing_docs)]
2
3use nargo_types::Error;
8use serde::{Deserialize, Serialize};
9use std::fmt;
10
11pub use nargo_types::Span;
13
14#[derive(Debug, Clone, PartialEq)]
18pub enum IRError {
19 InvalidInput(String),
23 InconsistentStructure(String),
27 SizeLimitExceeded(String),
31 CircularReference(String),
35 InvalidExpression(String),
39 Other(String),
43}
44
45impl fmt::Display for IRError {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 IRError::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
49 IRError::InconsistentStructure(msg) => write!(f, "Inconsistent structure: {}", msg),
50 IRError::SizeLimitExceeded(msg) => write!(f, "Size limit exceeded: {}", msg),
51 IRError::CircularReference(msg) => write!(f, "Circular reference: {}", msg),
52 IRError::InvalidExpression(msg) => write!(f, "Invalid expression: {}", msg),
53 IRError::Other(msg) => write!(f, "{}", msg),
54 }
55 }
56}
57
58impl From<IRError> for Error {
59 fn from(err: IRError) -> Self {
60 Error::external_error("nargo-ir".to_string(), err.to_string(), Span::unknown())
61 }
62}
63
64pub const MAX_STRING_LENGTH: usize = 1024 * 1024; pub const MAX_ARRAY_LENGTH: usize = 10000;
67pub const MAX_OBJECT_SIZE: usize = 1000;
68pub const MAX_RECURSION_DEPTH: usize = 100;
69
70#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
72pub struct Trivia {
73 pub leading_whitespace: String,
75 pub leading_comments: Vec<Comment>,
77 pub trailing_comments: Vec<Comment>,
79}
80
81impl Trivia {
82 pub fn new() -> Self {
84 Self::default()
85 }
86
87 pub fn is_empty(&self) -> bool {
89 self.leading_whitespace.is_empty() && self.leading_comments.is_empty() && self.trailing_comments.is_empty()
90 }
91}
92
93#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
95pub struct Comment {
96 pub content: String,
98 pub is_block: bool,
100 pub span: Span,
102}
103
104impl Comment {
105 pub fn new(content: String, is_block: bool, span: Span) -> Self {
107 Self { content, is_block, span }
108 }
109
110 pub fn is_empty(&self) -> bool {
112 self.content.trim().is_empty()
113 }
114}