diff --git a/ftd/src/p1/parser.rs b/ftd/src/p1/parser.rs index 2f3e0ecd6f..e495a009a4 100644 --- a/ftd/src/p1/parser.rs +++ b/ftd/src/p1/parser.rs @@ -846,6 +846,21 @@ fn colon_separated_values( } fn get_name_and_kind(name_with_kind: &str) -> (String, Option) { + let mut name_with_kind = name_with_kind.to_owned(); + + // Fix spacing for functional parameters inside parenthesis (if user provides) + if let (Some(si), Some(ei)) = (name_with_kind.find('('), name_with_kind.find(')')) { + if si < ei { + // All Content before start ( bracket + let before_brackets = &name_with_kind[..si]; + // All content after start ( bracket and all inner content excluding ) bracket + let mut bracket_content_and_beyond = name_with_kind[si..ei].replace(' ', ""); + // Push any remaining characters including ) and after end bracket + bracket_content_and_beyond.push_str(&name_with_kind[ei..]); + name_with_kind = format!("{}{}", before_brackets, bracket_content_and_beyond); + } + } + if let Some((kind, name)) = name_with_kind.rsplit_once(' ') { return (name.to_string(), Some(kind.to_string())); } diff --git a/ftd/t/ast/14-function.ftd b/ftd/t/ast/14-function.ftd index f1974bfaf9..f7cba19bb4 100644 --- a/ftd/t/ast/14-function.ftd +++ b/ftd/t/ast/14-function.ftd @@ -2,4 +2,10 @@ integer a: integer b: -a + b \ No newline at end of file +a + b + +-- string join(a, b) : +string a: +string b: + +a + " " + b diff --git a/ftd/t/ast/14-function.json b/ftd/t/ast/14-function.json index afac83f2db..236fa9cada 100644 --- a/ftd/t/ast/14-function.json +++ b/ftd/t/ast/14-function.json @@ -32,10 +32,49 @@ ], "line_number": 1, "definition": { - "line_number": 5, + "line_number": 6, "value": "a + b" }, "js": null } + }, + { + "FunctionDefinition": { + "name": "join", + "kind": { + "modifier": null, + "kind": "string" + }, + "arguments": [ + { + "name": "a", + "kind": { + "modifier": null, + "kind": "string" + }, + "mutable": false, + "value": null, + "line_number": 8, + "access_modifier": "Public" + }, + { + "name": "b", + "kind": { + "modifier": null, + "kind": "string" + }, + "mutable": false, + "value": null, + "line_number": 9, + "access_modifier": "Public" + } + ], + "line_number": 7, + "definition": { + "line_number": 11, + "value": "a + \" \" + b" + }, + "js": null + } } ] \ No newline at end of file