MCPcopy Index your code
hub / github.com/endbasic/endbasic / parse_bound_args

Function parse_bound_args

std/src/arrays.rs:33–67  ·  view source on GitHub ↗

Extracts array dimensions and the dimension number from args passed to `LBOUND` or `UBOUND`.

(scope: &Scope<'_>)

Source from the content-addressed store, hash-verified

31
32/// Extracts array dimensions and the dimension number from args passed to `LBOUND` or `UBOUND`.
33fn parse_bound_args(scope: &Scope<'_>) -> CallResult<(Vec<usize>, usize)> {
34 let array = scope.get_ref(0);
35 let dimensions = array.array_dimensions();
36
37 if scope.nargs() == 2 {
38 let i = scope.get_integer(1);
39
40 if i < 0 {
41 return Err(CallError::Syntax(
42 scope.get_pos(1),
43 format!("Dimension {} must be positive", i),
44 ));
45 }
46 let i = i as usize;
47
48 if i > dimensions.len() {
49 return Err(CallError::Syntax(
50 scope.get_pos(1),
51 format!("Array has only {} dimensions but asked for {}", dimensions.len(), i,),
52 ));
53 }
54 Ok((dimensions.to_vec(), i))
55 } else {
56 debug_assert_eq!(1, scope.nargs());
57
58 if dimensions.len() > 1 {
59 return Err(CallError::Syntax(
60 scope.get_pos(0),
61 "Requires a dimension for multidimensional arrays".to_owned(),
62 ));
63 }
64
65 Ok((dimensions.to_vec(), 1))
66 }
67}
68
69/// The `LBOUND` function.
70pub struct LboundFunction {

Callers 1

execMethod · 0.85

Calls 6

get_refMethod · 0.80
array_dimensionsMethod · 0.80
nargsMethod · 0.80
get_integerMethod · 0.80
get_posMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected