Skip to content

Commit

Permalink
Removing Capture.degrade()
Browse files Browse the repository at this point in the history
The provided `tests/builtin_ast_ondemand.tok` previously didn't work as expected.
  • Loading branch information
phorward committed Dec 3, 2023
1 parent fff4aa8 commit 91ea9e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/compiler/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,15 +1189,15 @@ fn traverse_node(compiler: &mut Compiler, node: &Dict) -> ImlOp {
"accept" => Op::LoadAccept.into(),
"break" => Op::LoadBreak.into(),
"exit" => Op::LoadExit.into(),
"push" => Op::LoadPush.into(),
"push" => Op::LoadPush.into(), // usecase?
_ => unreachable!(),
}
} else {
match parts[1] {
"accept" => Op::Accept.into(),
"break" => Op::Break.into(),
"exit" => Op::Exit.into(),
"push" => Op::Push.into(),
"push" => Op::Push.into(), // usecase?
_ => unreachable!(),
}
}
Expand Down
11 changes: 0 additions & 11 deletions src/vm/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ impl Capture {
_ => {}
}
}

// Degrades a capture to a severity to a capture with zero severity.
// This is done when a capture is read.
pub fn degrade(&mut self) {
match self {
Capture::Range(_, _, severity) | Capture::Value(_, _, severity) if *severity <= 5 => {
*severity = 0;
}
_ => {}
}
}
}

impl From<RefValue> for Capture {
Expand Down
2 changes: 0 additions & 2 deletions src/vm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ impl<'program, 'reader, 'thread, 'parselet> Context<'program, 'reader, 'thread,

let capture = &mut self.stack[pos];

capture.degrade(); // fixme: Can't extract do the degration?
Some(capture.extract(&self.thread.reader))
}

Expand All @@ -202,7 +201,6 @@ impl<'program, 'reader, 'thread, 'parselet> Context<'program, 'reader, 'thread,
let capture = &mut self.stack[capture_start + i];

if capture.alias(name) {
capture.degrade(); // fixme: Can't extract do the degration?
return Some(capture.extract(&self.thread.reader));
}
}
Expand Down
15 changes: 15 additions & 0 deletions tests/builtin_ast_ondemand.tok
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Trilli : Int _ ast("int")

Trollo : @{
Trilli+ if type($1) == "list" && $1.len > 1 ast("ints")
}

ast_print(Trollo)
#---
#1 2 3; 4
#---
#ints [start 1:1, end 1:6]
# int [start 1:1, end 1:3] => 1
# int [start 1:3, end 1:5] => 2
# int [start 1:5, end 1:6] => 3
#int [start 1:8, end 1:9] => 4

0 comments on commit 91ea9e0

Please sign in to comment.