nu-cmd-lang cleanup (#12609)

# Description
This PR does miscellaneous cleanup in some of the commands from
`nu-cmd-lang`.

# User-Facing Changes
None.

# After Submitting
Cleanup the other commands in `nu-cmd-lang`.
This commit is contained in:
Ian Manske
2024-04-25 14:16:12 +00:00
committed by GitHub
parent 530162b4c4
commit b6d765a2d8
10 changed files with 125 additions and 186 deletions

View File

@ -1,5 +1,5 @@
use crate::{
ast::{Argument, Block, Expr, ExternalArgument, ImportPattern, RecordItem},
ast::{Argument, Block, Expr, ExternalArgument, ImportPattern, MatchPattern, RecordItem},
engine::StateWorkingSet,
BlockId, DeclId, Signature, Span, Type, VarId, IN_VARIABLE_ID,
};
@ -79,6 +79,13 @@ impl Expression {
}
}
pub fn as_match_block(&self) -> Option<&[(MatchPattern, Expression)]> {
match &self.expr {
Expr::MatchBlock(matches) => Some(matches),
_ => None,
}
}
pub fn as_signature(&self) -> Option<Box<Signature>> {
match &self.expr {
Expr::Signature(sig) => Some(sig.clone()),