Skip to content

Commit

Permalink
fixed spacing issue of functional parameters while parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Heulitig committed Sep 13, 2023
1 parent eeecd4d commit 6677e75
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
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
}
}
]

0 comments on commit 6677e75

Please sign in to comment.