@@ -1476,8 +1476,8 @@ impl<'i> Parser<'i> {
1476
1476
. source
1477
1477
. char_indices ( )
1478
1478
{
1479
- if ch. is_whitespace ( ) {
1480
- // Stop at whitespace
1479
+ if ch. is_whitespace ( ) || ch == ',' || ch == ')' {
1480
+ // Stop at whitespace, comma, or closing parameter boundary
1481
1481
break ;
1482
1482
} else if ch. is_ascii_alphabetic ( ) || ch == '°' || ch == '/' || ch == 'μ' {
1483
1483
// Valid character
@@ -1875,6 +1875,9 @@ impl<'i> Parser<'i> {
1875
1875
inner. parse_string_pieces ( inner. source )
1876
1876
} ) ?;
1877
1877
params. push ( Expression :: String ( parts) ) ;
1878
+ } else if is_numeric ( content) {
1879
+ let numeric = outer. read_numeric ( ) ?;
1880
+ params. push ( Expression :: Number ( numeric) ) ;
1878
1881
} else {
1879
1882
let name = outer. read_identifier ( ) ?;
1880
1883
params. push ( Expression :: Variable ( name) ) ;
@@ -3502,6 +3505,58 @@ echo "Done"```) }"#,
3502
3505
) ]
3503
3506
} ) )
3504
3507
) ;
3508
+
3509
+ // Test function with quantity parameter (like timer with duration)
3510
+ input. initialize ( "{ timer(3 hr) }" ) ;
3511
+ let result = input. read_code_block ( ) ;
3512
+ assert_eq ! (
3513
+ result,
3514
+ Ok ( Expression :: Execution ( Function {
3515
+ target: Identifier ( "timer" ) ,
3516
+ parameters: vec![ Expression :: Number ( Numeric :: Scientific ( Quantity {
3517
+ mantissa: Decimal {
3518
+ number: 3 ,
3519
+ precision: 0
3520
+ } ,
3521
+ uncertainty: None ,
3522
+ magnitude: None ,
3523
+ symbol: "hr"
3524
+ } ) ) ]
3525
+ } ) )
3526
+ ) ;
3527
+
3528
+ // Test function with integer quantity parameter
3529
+ input. initialize ( "{ measure(100) }" ) ;
3530
+ let result = input. read_code_block ( ) ;
3531
+ assert_eq ! (
3532
+ result,
3533
+ Ok ( Expression :: Execution ( Function {
3534
+ target: Identifier ( "measure" ) ,
3535
+ parameters: vec![ Expression :: Number ( Numeric :: Integral ( 100 ) ) ]
3536
+ } ) )
3537
+ ) ;
3538
+
3539
+ // Test function with decimal quantity parameter
3540
+ input. initialize ( "{ wait(2.5 s, \" yes\" ) }" ) ;
3541
+ let result = input. read_code_block ( ) ;
3542
+ assert_eq ! (
3543
+ result,
3544
+ Ok ( Expression :: Execution ( Function {
3545
+ target: Identifier ( "wait" ) ,
3546
+ parameters: vec![
3547
+ Expression :: Number ( Numeric :: Scientific ( Quantity {
3548
+ mantissa: Decimal {
3549
+ number: 25 ,
3550
+ precision: 1
3551
+ } ,
3552
+ uncertainty: None ,
3553
+ magnitude: None ,
3554
+ symbol: "s"
3555
+ } ) ) ,
3556
+ Expression :: String ( vec![ Piece :: Text ( "yes" ) ] )
3557
+ ]
3558
+ } ) )
3559
+ ) ;
3505
3560
}
3506
3561
3507
3562
#[ test]
0 commit comments