forked from AdaCore/langkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Langkit_Support.Slocs: add Value (string parsing) functions
For GitHub issue AdaCore#492
- Loading branch information
Showing
5 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
with Ada.Exceptions; use Ada.Exceptions; | ||
with Ada.Text_IO; use Ada.Text_IO; | ||
|
||
with Langkit_Support.Slocs; use Langkit_Support.Slocs; | ||
with Langkit_Support.Text; use Langkit_Support.Text; | ||
|
||
procedure Main is | ||
|
||
procedure Check_Sloc (S : String); | ||
procedure Check_Sloc_Range (S : String); | ||
|
||
---------------- | ||
-- Check_Sloc -- | ||
---------------- | ||
|
||
procedure Check_Sloc (S : String) is | ||
Sloc : Source_Location; | ||
begin | ||
Put ("""" & S & """ -> "); | ||
Sloc := Value (S); | ||
Put_Line (Image (Sloc)); | ||
exception | ||
when Exc : Constraint_Error => | ||
Put_Line ("error: " & Exception_Message (Exc)); | ||
end Check_Sloc; | ||
|
||
---------------------- | ||
-- Check_Sloc_Range -- | ||
---------------------- | ||
|
||
procedure Check_Sloc_Range (S : String) is | ||
SR : Source_Location_Range; | ||
begin | ||
Put ("""" & S & """ -> "); | ||
SR := Value (S); | ||
Put_Line (Image (SR)); | ||
exception | ||
when Exc : Constraint_Error => | ||
Put_Line ("error: " & Exception_Message (Exc)); | ||
end Check_Sloc_Range; | ||
|
||
begin | ||
Check_Sloc ("0:0"); | ||
Check_Sloc ("123:456"); | ||
Check_Sloc (""); | ||
Check_Sloc ("1"); | ||
Check_Sloc (":1"); | ||
Check_Sloc ("-1:2"); | ||
Check_Sloc ("a:2"); | ||
|
||
Check_Sloc_Range ("1:2-3:4"); | ||
Check_Sloc_Range ("1:2-3:"); | ||
Check_Sloc_Range (":2-3:4"); | ||
Check_Sloc_Range ("1:-3:4"); | ||
Check_Sloc_Range ("1:2-:4"); | ||
Check_Sloc_Range ("1:2-3:"); | ||
Check_Sloc_Range ("1:2-3:-1"); | ||
end Main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"0:0" -> 0:0 | ||
"123:456" -> 123:456 | ||
"" -> error: invalid source location | ||
"1" -> error: invalid source location | ||
":1" -> error: invalid line number: "" | ||
"-1:2" -> error: invalid line number: "-1" | ||
"a:2" -> error: invalid line number: "a" | ||
"1:2-3:4" -> 1:2-3:4 | ||
"1:2-3:" -> error: invalid column number: "" | ||
":2-3:4" -> error: invalid line number: "" | ||
"1:-3:4" -> error: invalid column number: "" | ||
"1:2-:4" -> error: invalid line number: "" | ||
"1:2-3:" -> error: invalid column number: "" | ||
"1:2-3:-1" -> error: invalid column number: "-1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
driver: langkit_support |
4ac75a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does source_location_range miss a check?
source_location has
Should one also add this for
Dash_Index
?4ac75a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be redundant with existing checks. I’ll extend the testcase to demonstrate this.
4ac75a7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that one get
Constraint_Error with "invalid source location";
in case that a
source location
range
doesn't contain a dash.