1use crate::{Pattern, SurfaceExpr};
6
7#[allow(dead_code)]
9#[allow(missing_docs)]
10#[derive(Debug, Clone)]
11pub struct PatternMatrixRow {
12 pub patterns: Vec<String>,
14 pub body: String,
16}
17impl PatternMatrixRow {
18 #[allow(dead_code)]
20 pub fn new(patterns: Vec<&str>, body: &str) -> Self {
21 PatternMatrixRow {
22 patterns: patterns.into_iter().map(|s| s.to_string()).collect(),
23 body: body.to_string(),
24 }
25 }
26 #[allow(dead_code)]
28 pub fn is_wildcard_row(&self) -> bool {
29 self.patterns.iter().all(|p| p == "_")
30 }
31}
32#[derive(Debug, Clone)]
34pub struct PatternRow {
35 pub patterns: Vec<Pattern>,
37 pub body: SurfaceExpr,
39 pub guard: Option<SurfaceExpr>,
41}
42#[derive(Debug, Clone)]
44pub struct TypeConstructors {
45 pub type_name: String,
47 pub constructors: Vec<ConstructorInfo>,
49}
50#[allow(dead_code)]
52#[allow(missing_docs)]
53#[derive(Debug, Clone, PartialEq, Eq)]
54pub enum PatternTagExt {
55 Wild,
57 Var,
59 Ctor,
61 Lit,
63 Or,
65 As,
67 Guard,
69}
70#[allow(dead_code)]
72#[allow(missing_docs)]
73#[derive(Debug, Clone)]
74pub struct MatchArmExt {
75 pub pattern: String,
77 pub body: String,
79 pub guard: Option<String>,
81}
82impl MatchArmExt {
83 #[allow(dead_code)]
85 pub fn new(pattern: &str, body: &str) -> Self {
86 MatchArmExt {
87 pattern: pattern.to_string(),
88 body: body.to_string(),
89 guard: None,
90 }
91 }
92 #[allow(dead_code)]
94 pub fn with_guard(mut self, guard: &str) -> Self {
95 self.guard = Some(guard.to_string());
96 self
97 }
98}
99#[derive(Debug, Clone, PartialEq)]
101pub struct CaseBranch {
102 pub ctor: String,
104 pub num_fields: usize,
106 pub subtree: CaseTree,
108}
109#[derive(Debug, Clone, PartialEq)]
111pub struct InaccessiblePattern {
112 pub inner: Box<Pattern>,
114}
115#[derive(Debug, Clone, PartialEq)]
117pub struct AsPattern {
118 pub pattern: Box<Pattern>,
120 pub name: String,
122}
123#[derive(Debug, Clone, PartialEq)]
125pub struct SpecializedPattern {
126 pub patterns: Vec<Pattern>,
128 pub applies: bool,
130}
131#[derive(Debug, Clone)]
133pub struct MatchClause {
134 pub pattern: Pattern,
136 pub body: SurfaceExpr,
138}
139#[allow(dead_code)]
141#[allow(missing_docs)]
142#[derive(Debug, Clone)]
143pub struct PatternBinding {
144 pub name: String,
146 pub position: usize,
148 pub ty: Option<String>,
150}
151impl PatternBinding {
152 #[allow(dead_code)]
154 pub fn new(name: &str, position: usize) -> Self {
155 PatternBinding {
156 name: name.to_string(),
157 position,
158 ty: None,
159 }
160 }
161 #[allow(dead_code)]
163 pub fn with_type(mut self, ty: &str) -> Self {
164 self.ty = Some(ty.to_string());
165 self
166 }
167}
168#[derive(Debug, Clone, PartialEq)]
170pub enum CaseTree {
171 Leaf {
173 body_idx: usize,
175 },
176 Switch {
178 scrutinee: usize,
180 branches: Vec<CaseBranch>,
182 default: Option<Box<CaseTree>>,
184 },
185 Failure,
187}
188#[derive(Debug, Clone, PartialEq)]
190pub struct ArrayPattern {
191 pub prefix: Vec<crate::Located<Pattern>>,
193 pub rest: bool,
195 pub suffix: Vec<crate::Located<Pattern>>,
197}
198#[allow(dead_code)]
200#[allow(missing_docs)]
201pub struct PatternCoverageExt {
202 pub arm_count: usize,
204 pub has_wildcard: bool,
206}
207impl PatternCoverageExt {
208 #[allow(dead_code)]
210 pub fn new() -> Self {
211 PatternCoverageExt {
212 arm_count: 0,
213 has_wildcard: false,
214 }
215 }
216 #[allow(dead_code)]
218 pub fn add_arm(&mut self, tag: PatternTagExt) {
219 self.arm_count += 1;
220 if tag == PatternTagExt::Wild || tag == PatternTagExt::Var {
221 self.has_wildcard = true;
222 }
223 }
224 #[allow(dead_code)]
226 pub fn is_complete(&self) -> bool {
227 self.has_wildcard
228 }
229}
230#[derive(Debug, Clone)]
232pub struct ConstructorInfo {
233 pub name: String,
235 pub arity: usize,
237}
238#[derive(Debug, Clone)]
240pub struct PatternCoverage {
241 pub covered: Vec<Pattern>,
243 pub uncovered: Vec<Pattern>,
245}
246#[allow(dead_code)]
248#[allow(missing_docs)]
249pub struct PatternRenamer {
250 pub renaming: std::collections::HashMap<String, String>,
252}
253impl PatternRenamer {
254 #[allow(dead_code)]
256 pub fn new() -> Self {
257 PatternRenamer {
258 renaming: std::collections::HashMap::new(),
259 }
260 }
261 #[allow(dead_code)]
263 pub fn add(&mut self, from: &str, to: &str) {
264 self.renaming.insert(from.to_string(), to.to_string());
265 }
266 #[allow(dead_code)]
268 pub fn rename(&self, pattern: &str) -> String {
269 self.renaming
270 .get(pattern)
271 .cloned()
272 .unwrap_or_else(|| pattern.to_string())
273 }
274}