From c2982e418a3007e17f9673ef2d439f2f33be0b97 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Mon, 10 Mar 2025 14:54:10 +0000 Subject: [PATCH 1/2] support dash in path --- aiscript-runtime/src/parser.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aiscript-runtime/src/parser.rs b/aiscript-runtime/src/parser.rs index 37daebb..8d081df 100644 --- a/aiscript-runtime/src/parser.rs +++ b/aiscript-runtime/src/parser.rs @@ -443,6 +443,10 @@ impl<'a> Parser<'a> { path.push_str(self.current.lexeme); self.advance(); } + TokenType::Minus => { + path.push('-'); + self.advance(); + } TokenType::OpenBrace | TokenType::Comma => break, _ => return Err(format!("Unexpected token in path: {:?}", self.current.kind)), } From c797bb8235ce5ad0bf353a6d28064dd6f1f61ba8 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Mon, 10 Mar 2025 15:06:04 +0000 Subject: [PATCH 2/2] test: test_path_with_dash --- aiscript-runtime/src/parser.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/aiscript-runtime/src/parser.rs b/aiscript-runtime/src/parser.rs index 8d081df..05c0a4e 100644 --- a/aiscript-runtime/src/parser.rs +++ b/aiscript-runtime/src/parser.rs @@ -934,4 +934,33 @@ mod tests { let result = parser.parse_route(); assert!(result.is_ok()); } + + #[test] + fn test_path_with_dash() { + let input = r#" + route /api { + get /get-messages { + return "Messages"; + } + + post /user-profile/update-settings { + return "Settings updated"; + } + } + "#; + + let mut parser = Parser::new(input); + let result = parser.parse_route(); + + let route = result.unwrap(); + assert_eq!(route.prefix, "/api"); + + let endpoint1 = &route.endpoints[0]; + assert_eq!(endpoint1.path_specs[0].method, HttpMethod::Get); + assert_eq!(endpoint1.path_specs[0].path, "/get-messages"); + + let endpoint2 = &route.endpoints[1]; + assert_eq!(endpoint2.path_specs[0].method, HttpMethod::Post); + assert_eq!(endpoint2.path_specs[0].path, "/user-profile/update-settings"); + } }