fileset: implement expect_no_arguments() as method

This commit is contained in:
Yuya Nishihara 2024-05-21 12:34:49 +09:00
parent c9b088c795
commit 7a230395c2
2 changed files with 12 additions and 10 deletions

View file

@ -396,11 +396,11 @@ static BUILTIN_FUNCTION_MAP: Lazy<HashMap<&'static str, FilesetFunction>> = Lazy
// code completion inside macro is quite restricted.
let mut map: HashMap<&'static str, FilesetFunction> = HashMap::new();
map.insert("none", |_ctx, function| {
fileset_parser::expect_no_arguments(function)?;
function.expect_no_arguments()?;
Ok(FilesetExpression::none())
});
map.insert("all", |_ctx, function| {
fileset_parser::expect_no_arguments(function)?;
function.expect_no_arguments()?;
Ok(FilesetExpression::all())
});
map

View file

@ -342,14 +342,16 @@ pub fn parse_program_or_bare_string(text: &str) -> FilesetParseResult<Expression
Ok(ExpressionNode::new(expr, span))
}
pub fn expect_no_arguments(function: &FunctionCallNode) -> FilesetParseResult<()> {
if function.args.is_empty() {
Ok(())
} else {
Err(FilesetParseError::invalid_arguments(
function,
"Expected 0 arguments",
))
impl<'i> FunctionCallNode<'i> {
pub fn expect_no_arguments(&self) -> FilesetParseResult<()> {
if self.args.is_empty() {
Ok(())
} else {
Err(FilesetParseError::invalid_arguments(
self,
"Expected 0 arguments",
))
}
}
}