summaryrefslogtreecommitdiff
path: root/src/chomp/check/shallow.rs
diff options
context:
space:
mode:
authorGreg Brown <gmb60@cam.ac.uk>2021-01-08 18:00:11 +0000
committerGreg Brown <gmb60@cam.ac.uk>2021-01-08 18:00:11 +0000
commite1452227b8bd9ad3805480f8a5a66a75fb8370dd (patch)
treeb02c9dfdc157d753e3f1c8a09bbd2ffb0bbfcc36 /src/chomp/check/shallow.rs
parentfe2eac31d9dbec772796c3ea75be32e9cd01b810 (diff)
Do more restructuring.
Diffstat (limited to 'src/chomp/check/shallow.rs')
-rw-r--r--src/chomp/check/shallow.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/chomp/check/shallow.rs b/src/chomp/check/shallow.rs
new file mode 100644
index 0000000..e5cc1a1
--- /dev/null
+++ b/src/chomp/check/shallow.rs
@@ -0,0 +1,47 @@
+use super::super::{
+ ast::{Alt, Call, Cat, Epsilon, Fix, Literal, Parameter, Variable},
+ visit::{Mapper, Visitable},
+};
+
+#[derive(Clone, Copy, Debug, Default)]
+pub struct ShallowVars {
+ depth: usize,
+}
+
+impl Mapper for ShallowVars {
+ type Out = ();
+
+ fn map_epsilon(&mut self, _: &mut Epsilon) -> Self::Out {}
+
+ fn map_literal(&mut self, _: &mut Literal) -> Self::Out {}
+
+ fn map_cat(&mut self, cat: &mut Cat) -> Self::Out {
+ cat.first_mut().map(self);
+ cat.second_mut().map(self);
+ }
+
+ fn map_alt(&mut self, alt: &mut Alt) -> Self::Out {
+ alt.left_mut().map(self);
+ alt.right_mut().map(self);
+ }
+
+ fn map_fix(&mut self, fix: &mut Fix) -> Self::Out {
+ self.depth += 1;
+ fix.inner_mut().map(self);
+ self.depth -= 1;
+ }
+
+ fn map_variable(&mut self, bind: &mut Variable) -> Self::Out {
+ if bind.index() > self.depth {
+ *bind.index_mut() -= 1;
+ }
+ }
+
+ fn map_parameter(&mut self, _param: &mut Parameter) -> Self::Out {}
+
+ fn map_call(&mut self, call: &mut Call) -> Self::Out {
+ for arg in call.args_mut() {
+ arg.map(self);
+ }
+ }
+}