Skip to content

Commit 4e4f773

Browse files
committed
Add width to identifier errors
1 parent 1c2c1ba commit 4e4f773

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/parsing/parser.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ impl<'i> Parser<'i> {
891891
let before = before.trim();
892892
let name = validate_identifier(before).ok_or(ParsingError::InvalidIdentifier(
893893
self.offset,
894-
0,
894+
before.len(),
895895
before.to_string(),
896896
))?;
897897

@@ -909,7 +909,8 @@ impl<'i> Parser<'i> {
909909
let param = validate_identifier(item.trim_ascii()).ok_or(
910910
ParsingError::InvalidIdentifier(
911911
self.offset,
912-
0,
912+
item.trim_ascii()
913+
.len(),
913914
item.trim_ascii()
914915
.to_string(),
915916
),
@@ -937,12 +938,13 @@ impl<'i> Parser<'i> {
937938
.as_ptr() as isize
938939
- text.as_ptr() as isize;
939940
let error_offset = self.offset + one.start() + first_param_pos as usize;
940-
return Err(ParsingError::InvalidParameters(error_offset, 0));
941+
let param_width = text.len() - first_param_pos as usize;
942+
return Err(ParsingError::InvalidParameters(error_offset, param_width));
941943
}
942944

943945
let name = validate_identifier(text).ok_or(ParsingError::InvalidIdentifier(
944946
self.offset,
945-
0,
947+
text.len(),
946948
text.to_string(),
947949
))?;
948950
(name, None)
@@ -1655,7 +1657,7 @@ impl<'i> Parser<'i> {
16551657

16561658
let identifier = validate_identifier(possible).ok_or(ParsingError::InvalidIdentifier(
16571659
self.offset,
1658-
0,
1660+
possible.len(),
16591661
possible.to_string(),
16601662
))?;
16611663

@@ -2370,9 +2372,12 @@ impl<'i> Parser<'i> {
23702372
.get(1)
23712373
.ok_or(ParsingError::Expected(inner.offset, 0, "role name after @"))?
23722374
.as_str();
2373-
let identifier = validate_identifier(role_name).ok_or(
2374-
ParsingError::InvalidIdentifier(inner.offset, 0, role_name.to_string()),
2375-
)?;
2375+
let identifier =
2376+
validate_identifier(role_name).ok_or(ParsingError::InvalidIdentifier(
2377+
inner.offset,
2378+
role_name.len(),
2379+
role_name.to_string(),
2380+
))?;
23762381
attributes.push(Attribute::Role(identifier));
23772382
}
23782383
// Check if it's a place '^'
@@ -2385,9 +2390,12 @@ impl<'i> Parser<'i> {
23852390
"place name after ^",
23862391
))?
23872392
.as_str();
2388-
let identifier = validate_identifier(place_name).ok_or(
2389-
ParsingError::InvalidIdentifier(inner.offset, 0, place_name.to_string()),
2390-
)?;
2393+
let identifier =
2394+
validate_identifier(place_name).ok_or(ParsingError::InvalidIdentifier(
2395+
inner.offset,
2396+
place_name.len(),
2397+
place_name.to_string(),
2398+
))?;
23912399
attributes.push(Attribute::Place(identifier));
23922400
} else {
23932401
return Err(ParsingError::InvalidStep(inner.offset, 0));

tests/parsing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
mod samples;
21
mod broken;
2+
mod samples;

0 commit comments

Comments
 (0)