Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed spacing issue of function parameters while parsing #1305

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ftd/src/p1/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,21 @@ fn colon_separated_values(
}

fn get_name_and_kind(name_with_kind: &str) -> (String, Option<String>) {
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()));
}
Expand Down
8 changes: 7 additions & 1 deletion ftd/t/ast/14-function.ftd
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
integer a:
integer b:

a + b
a + b

-- string join(a, b) :
string a:
string b:

a + " " + b
41 changes: 40 additions & 1 deletion ftd/t/ast/14-function.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
]
Loading