Skip to content

Commit 8b4e6d5

Browse files
Copilot0xrinegade
andcommitted
fix(clippy): fix all lint errors in ovsm crate and main binary
Co-authored-by: 0xrinegade <[email protected]>
1 parent 18f7832 commit 8b4e6d5

File tree

6 files changed

+68
-87
lines changed

6 files changed

+68
-87
lines changed

crates/ovsm/src/lexer/sexpr_scanner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ impl SExprScanner {
283283
"nil" | "null" => TokenKind::Null,
284284
_ => {
285285
// Check if it's a keyword argument (starts with :)
286-
if text.starts_with(':') {
287-
TokenKind::Identifier(text[1..].to_string()) // Remove the :
286+
if let Some(stripped) = text.strip_prefix(':') {
287+
TokenKind::Identifier(stripped.to_string()) // Remove the :
288288
} else {
289289
// Otherwise it's an identifier or symbol
290290
TokenKind::Identifier(text)

crates/ovsm/src/parser/sexpr_parser.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,9 @@ impl SExprParser {
655655

656656
while !self.check(&TokenKind::RightParen) {
657657
if let TokenKind::Identifier(name) = &self.peek().kind {
658-
// Handle &optional, &rest, &key markers
659-
if name == "&optional" || name == "&rest" || name == "&key" {
660-
params.push(name.clone());
661-
self.advance();
662-
} else {
663-
params.push(name.clone());
664-
self.advance();
665-
}
658+
// Handle &optional, &rest, &key markers and regular params
659+
params.push(name.clone());
660+
self.advance();
666661
} else if self.check(&TokenKind::LeftParen) {
667662
// Handle (param-name default-value) form
668663
self.advance(); // consume (
@@ -1058,7 +1053,7 @@ impl SExprParser {
10581053
Ok(self.advance())
10591054
} else {
10601055
let token = self.peek();
1061-
let message = self.build_error_message(&kind, &token);
1056+
let message = self.build_error_message(&kind, token);
10621057

10631058
Err(Error::SyntaxError {
10641059
line: token.line,

crates/ovsm/src/runtime/lisp_evaluator.rs

Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl LispEvaluator {
7171

7272
Statement::Assignment { name, value } => {
7373
let val = self.evaluate_expression(value)?;
74-
self.env.set(&name, val.clone())?;
74+
self.env.set(name, val.clone())?;
7575
Ok(val)
7676
}
7777

@@ -235,8 +235,7 @@ impl LispEvaluator {
235235
if name.starts_with(':') {
236236
Ok(Value::String(name.clone()))
237237
} else {
238-
let result = self.env.get(name);
239-
result
238+
self.env.get(name)
240239
}
241240
}
242241

@@ -2069,8 +2068,8 @@ impl LispEvaluator {
20692068

20702069
// Execute body expressions in sequence, return last
20712070
let mut result = Value::Null;
2072-
for i in 2..args.len() {
2073-
result = self.evaluate_expression(&args[i].value)?;
2071+
for arg in &args[2..] {
2072+
result = self.evaluate_expression(&arg.value)?;
20742073
}
20752074

20762075
self.env.exit_scope();
@@ -2954,7 +2953,7 @@ impl LispEvaluator {
29542953
// ~A - Aesthetic (any value)
29552954
if arg_index < format_args.len() {
29562955
result.push_str(
2957-
&self.value_to_format_string(&format_args[arg_index]),
2956+
&Self::value_to_format_string(&format_args[arg_index]),
29582957
);
29592958
arg_index += 1;
29602959
}
@@ -2966,7 +2965,7 @@ impl LispEvaluator {
29662965
result.push_str(&n.to_string());
29672966
} else {
29682967
result.push_str(
2969-
&self.value_to_format_string(&format_args[arg_index]),
2968+
&Self::value_to_format_string(&format_args[arg_index]),
29702969
);
29712970
}
29722971
arg_index += 1;
@@ -3007,7 +3006,7 @@ impl LispEvaluator {
30073006
}
30083007

30093008
/// Helper to convert value to string for format
3010-
fn value_to_format_string(&self, val: &Value) -> String {
3009+
fn value_to_format_string(val: &Value) -> String {
30113010
match val {
30123011
Value::String(s) => s.clone(),
30133012
Value::Int(n) => n.to_string(),
@@ -3016,7 +3015,7 @@ impl LispEvaluator {
30163015
Value::Null => "null".to_string(),
30173016
Value::Array(arr) => {
30183017
let items: Vec<String> =
3019-
arr.iter().map(|v| self.value_to_format_string(v)).collect();
3018+
arr.iter().map(Self::value_to_format_string).collect();
30203019
format!("[{}]", items.join(", "))
30213020
}
30223021
_ => format!("{}", val),
@@ -3117,11 +3116,9 @@ impl LispEvaluator {
31173116
let key_str = key_val.as_string()?;
31183117

31193118
// Strip leading colon from keywords (e.g., ":age" -> "age")
3120-
let key = if key_str.starts_with(':') {
3121-
&key_str[1..]
3122-
} else {
3123-
key_str
3124-
};
3119+
let key = key_str
3120+
.strip_prefix(':')
3121+
.unwrap_or(key_str);
31253122

31263123
Ok(obj.get(key).cloned().unwrap_or(Value::Null))
31273124
}
@@ -3172,7 +3169,7 @@ impl LispEvaluator {
31723169
})?;
31733170

31743171
// Convert serde_json::Value to OVSM Value
3175-
Ok(self.json_to_value(json_value))
3172+
Ok(Self::json_to_value(json_value))
31763173
}
31773174

31783175
/// json-stringify - Convert OVSM value to JSON string
@@ -3208,7 +3205,7 @@ impl LispEvaluator {
32083205
};
32093206

32103207
// Convert OVSM Value to serde_json::Value
3211-
let json_value = self.value_to_json(value)?;
3208+
let json_value = Self::value_to_json(value)?;
32123209

32133210
// Stringify with optional pretty printing
32143211
let json_str = if pretty {
@@ -3225,7 +3222,7 @@ impl LispEvaluator {
32253222
}
32263223

32273224
/// Helper: Convert serde_json::Value to OVSM Value
3228-
fn json_to_value(&self, json: serde_json::Value) -> Value {
3225+
fn json_to_value( json: serde_json::Value) -> Value {
32293226
use serde_json::Value as JV;
32303227
match json {
32313228
JV::Null => Value::Null,
@@ -3241,20 +3238,20 @@ impl LispEvaluator {
32413238
}
32423239
JV::String(s) => Value::String(s),
32433240
JV::Array(arr) => Value::Array(Arc::new(
3244-
arr.into_iter().map(|v| self.json_to_value(v)).collect(),
3241+
arr.into_iter().map(Self::json_to_value).collect(),
32453242
)),
32463243
JV::Object(map) => {
32473244
let mut obj = HashMap::new();
32483245
for (k, v) in map {
3249-
obj.insert(k, self.json_to_value(v));
3246+
obj.insert(k, Self::json_to_value(v));
32503247
}
32513248
Value::Object(Arc::new(obj))
32523249
}
32533250
}
32543251
}
32553252

32563253
/// Helper: Convert OVSM Value to serde_json::Value
3257-
fn value_to_json(&self, value: Value) -> Result<serde_json::Value> {
3254+
fn value_to_json(value: Value) -> Result<serde_json::Value> {
32583255
use serde_json::Value as JV;
32593256
Ok(match value {
32603257
Value::Null => JV::Null,
@@ -3267,14 +3264,14 @@ impl LispEvaluator {
32673264
Value::Array(arr) => {
32683265
let mut json_arr = Vec::new();
32693266
for item in arr.iter() {
3270-
json_arr.push(self.value_to_json(item.clone())?);
3267+
json_arr.push(Self::value_to_json(item.clone())?);
32713268
}
32723269
JV::Array(json_arr)
32733270
}
32743271
Value::Object(obj) => {
32753272
let mut json_obj = serde_json::Map::new();
32763273
for (k, v) in obj.iter() {
3277-
json_obj.insert(k.clone(), self.value_to_json(v.clone())?);
3274+
json_obj.insert(k.clone(), Self::value_to_json(v.clone())?);
32783275
}
32793276
JV::Object(json_obj)
32803277
}
@@ -3764,11 +3761,9 @@ impl LispEvaluator {
37643761
let prop_name = prop_val.as_string()?;
37653762

37663763
// Strip leading colon from keywords
3767-
let prop = if prop_name.starts_with(':') {
3768-
&prop_name[1..]
3769-
} else {
3770-
prop_name
3771-
};
3764+
let prop = prop_name
3765+
.strip_prefix(':')
3766+
.unwrap_or(prop_name);
37723767

37733768
let mut result = Vec::new();
37743769

@@ -3844,7 +3839,7 @@ impl LispEvaluator {
38443839

38453840
groups
38463841
.entry(key)
3847-
.or_insert_with(Vec::new)
3842+
.or_default()
38483843
.push(elem.clone());
38493844
}
38503845

@@ -4077,20 +4072,19 @@ impl LispEvaluator {
40774072
/// Evaluate a regular tool call
40784073
fn eval_tool_call(&mut self, name: &str, args: &[crate::parser::Argument]) -> Result<Value> {
40794074
// Check if this is a user-defined function first
4080-
if let Ok(func_val) = self.env.get(name) {
4081-
if let Value::Function {
4082-
params,
4083-
body,
4084-
closure,
4085-
is_flet,
4086-
} = func_val
4087-
{
4088-
// This is a function call!
4089-
4090-
// Evaluate arguments - handle both positional and keyword arguments
4091-
let mut evaluated_args = Vec::new();
4092-
for arg in args {
4093-
// If this is a keyword argument, include the keyword name with colon prefix
4075+
if let Ok(Value::Function {
4076+
params,
4077+
body,
4078+
closure,
4079+
is_flet,
4080+
}) = self.env.get(name)
4081+
{
4082+
// This is a function call!
4083+
4084+
// Evaluate arguments - handle both positional and keyword arguments
4085+
let mut evaluated_args = Vec::new();
4086+
for arg in args {
4087+
// If this is a keyword argument, include the keyword name with colon prefix
40944088
if let Some(ref keyword_name) = arg.name {
40954089
// Ensure keyword has colon prefix
40964090
let kw = if keyword_name.starts_with(':') {
@@ -4121,7 +4115,7 @@ impl LispEvaluator {
41214115
self.bind_function_parameters(&params, &evaluated_args, name)?;
41224116

41234117
// Evaluate function body
4124-
let result = self.evaluate_expression(&*body); // Explicit deref
4118+
let result = self.evaluate_expression(&body);
41254119

41264120
// Restore original environment
41274121
self.env = saved_env;
@@ -4135,14 +4129,13 @@ impl LispEvaluator {
41354129
self.bind_function_parameters(&params, &evaluated_args, name)?;
41364130

41374131
// Evaluate function body
4138-
let result = self.evaluate_expression(&*body); // Explicit deref
4132+
let result = self.evaluate_expression(&body);
41394133

41404134
// Exit function scope
41414135
self.env.exit_scope();
41424136

41434137
return result;
41444138
}
4145-
}
41464139
}
41474140

41484141
// Not a function, try tool registry
@@ -4401,11 +4394,9 @@ impl LispEvaluator {
44014394
match expr {
44024395
Expression::ToolCall { name, args } => {
44034396
// Check if this is a macro
4404-
if let Ok(value) = self.env.get(name) {
4405-
if let Value::Macro { params, body, .. } = value {
4406-
// This is a macro! Expand it
4407-
return Ok(Some(self.expand_macro(&params, &body, args)?));
4408-
}
4397+
if let Ok(Value::Macro { params, body, .. }) = self.env.get(name) {
4398+
// This is a macro! Expand it
4399+
return Ok(Some(self.expand_macro(&params, &body, args)?));
44094400
}
44104401
Ok(None)
44114402
}
@@ -4428,7 +4419,7 @@ impl LispEvaluator {
44284419
// Convert args to expression values first
44294420
let mut arg_values = Vec::new();
44304421
for arg in args {
4431-
arg_values.push(self.expression_to_value(&arg.value)?);
4422+
arg_values.push(Self::expression_to_value(&arg.value)?);
44324423
}
44334424
self.bind_function_parameters(params, &arg_values, "macro")?;
44344425

@@ -4439,11 +4430,11 @@ impl LispEvaluator {
44394430
self.env = old_env;
44404431

44414432
// Convert result back to an expression
4442-
self.value_to_expression(&result_value)
4433+
Self::value_to_expression(&result_value)
44434434
}
44444435

44454436
/// Convert an expression to a value (for macro parameter binding)
4446-
fn expression_to_value(&self, expr: &Expression) -> Result<Value> {
4437+
fn expression_to_value( expr: &Expression) -> Result<Value> {
44474438
// This is a simplified version - in full CL, expressions would be first-class
44484439
// For now, we store them as strings or structured data
44494440
match expr {
@@ -4455,7 +4446,7 @@ impl LispEvaluator {
44554446
Expression::Variable(name) => Ok(Value::String(name.clone())),
44564447
Expression::ArrayLiteral(exprs) => {
44574448
let vals: Result<Vec<_>> =
4458-
exprs.iter().map(|e| self.expression_to_value(e)).collect();
4449+
exprs.iter().map(Self::expression_to_value).collect();
44594450
Ok(Value::array(vals?))
44604451
}
44614452
_ => {
@@ -4466,7 +4457,7 @@ impl LispEvaluator {
44664457
}
44674458

44684459
/// Convert a value back to an expression (for macro expansion result)
4469-
fn value_to_expression(&self, value: &Value) -> Result<Expression> {
4460+
fn value_to_expression( value: &Value) -> Result<Expression> {
44704461
match value {
44714462
Value::Int(n) => Ok(Expression::IntLiteral(*n)),
44724463
Value::Float(f) => Ok(Expression::FloatLiteral(*f)),
@@ -4484,7 +4475,7 @@ impl LispEvaluator {
44844475
Value::Null => Ok(Expression::NullLiteral),
44854476
Value::Array(arr) => {
44864477
let exprs: Result<Vec<_>> =
4487-
arr.iter().map(|v| self.value_to_expression(v)).collect();
4478+
arr.iter().map(Self::value_to_expression).collect();
44884479
Ok(Expression::ArrayLiteral(exprs?))
44894480
}
44904481
_ => Err(Error::TypeError {
@@ -4561,7 +4552,7 @@ impl LispEvaluator {
45614552
Ok(Value::array(result))
45624553
}
45634554
// For other expressions, convert to values literally
4564-
_ => self.expression_to_value(expr),
4555+
_ => Self::expression_to_value(expr),
45654556
}
45664557
}
45674558

@@ -4693,8 +4684,8 @@ impl LispEvaluator {
46934684
if let Expression::Variable(name) = &list[0] {
46944685
param_names.push(name.clone());
46954686
// Serialize default expression
4696-
let default_val = self.expression_to_value(&list[1])?;
4697-
param_names.push(self.serialize_default_value(&default_val)?);
4687+
let default_val = Self::expression_to_value(&list[1])?;
4688+
param_names.push(Self::serialize_default_value(&default_val)?);
46984689
} else {
46994690
return Err(Error::ParseError(format!(
47004691
"{}: {} parameter name must be identifier",
@@ -4712,8 +4703,8 @@ impl LispEvaluator {
47124703
}
47134704
param_names.push(name.clone());
47144705
// Serialize default expression
4715-
let default_val = self.expression_to_value(&args[0].value)?;
4716-
param_names.push(self.serialize_default_value(&default_val)?);
4706+
let default_val = Self::expression_to_value(&args[0].value)?;
4707+
param_names.push(Self::serialize_default_value(&default_val)?);
47174708
}
47184709
_ => {
47194710
return Err(Error::ParseError(format!(
@@ -4740,7 +4731,7 @@ impl LispEvaluator {
47404731
}
47414732

47424733
/// Serialize a default value for storage in parameter list
4743-
fn serialize_default_value(&self, value: &Value) -> Result<String> {
4734+
fn serialize_default_value(value: &Value) -> Result<String> {
47444735
match value {
47454736
Value::Int(n) => Ok(n.to_string()),
47464737
Value::Float(f) => Ok(f.to_string()),
@@ -4753,14 +4744,14 @@ impl LispEvaluator {
47534744
Value::Array(arr) => {
47544745
let items: Result<Vec<_>> = arr
47554746
.iter()
4756-
.map(|v| self.serialize_default_value(v))
4747+
.map(Self::serialize_default_value)
47574748
.collect();
47584749
Ok(format!("[{}]", items?.join(" ")))
47594750
}
47604751
Value::Object(obj) => {
47614752
let mut pairs = Vec::new();
47624753
for (k, v) in obj.iter() {
4763-
pairs.push(format!(":{} {}", k, self.serialize_default_value(v)?));
4754+
pairs.push(format!(":{} {}", k, Self::serialize_default_value(v)?));
47644755
}
47654756
Ok(format!("{{{}}}", pairs.join(" ")))
47664757
}

0 commit comments

Comments
 (0)