Skip to content

Commit 61485f5

Browse files
committed
Ensure caret points at position of missing parameter
1 parent 40afe32 commit 61485f5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/parsing/parser.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,21 +858,23 @@ impl<'i> Parser<'i> {
858858

859859
(name, parameters)
860860
} else {
861-
// Check if the text contains multiple space-separated identifiers
862-
// which would indicate parameters without parentheses
861+
// Check if there are multiple words (procedure name + anything
862+
// else) which would indicates parameters without parentheses
863863
let words: Vec<&str> = text
864864
.trim()
865865
.split_whitespace()
866866
.collect();
867867
if words.len() > 1 {
868-
// Check if all words look like valid identifiers
869-
let all_valid_identifiers = words
870-
.iter()
871-
.all(|word| validate_identifier(word).is_some());
872-
873-
if all_valid_identifiers {
874-
return Err(ParsingError::InvalidParameters(self.offset));
875-
}
868+
// Calculate position of first mistaken parameter-ish thing
869+
let first_space_pos = text
870+
.find(' ')
871+
.unwrap_or(0);
872+
let first_param_pos = text[first_space_pos..]
873+
.trim_start()
874+
.as_ptr() as isize
875+
- text.as_ptr() as isize;
876+
let error_offset = self.offset + one.start() + first_param_pos as usize;
877+
return Err(ParsingError::InvalidParameters(error_offset));
876878
}
877879

878880
let name = validate_identifier(text).ok_or(ParsingError::InvalidIdentifier(

tests/broken/DeclartionParentheses.tq

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
make_coffee beans : Beans -> Espresso
44

55
make_coffee beans water : Beans, Water -> Cappuccino
6+
7+
make_coffee Beans, Water :

0 commit comments

Comments
 (0)