Skip to content

Commit

Permalink
last segment may not end in a dot either
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed May 13, 2024
1 parent 8552be6 commit ae8e3d3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/org/rascalmpl/library/lang/paths/Windows.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ lexical Slash = [\\/];

lexical Drive = [A-Za-z];

lexical WindowsFilePath = {PathSegment Slashes}* segments Slashes? [\ ] !<< (); // only the last segment must not end in spaces.
lexical WindowsFilePath = {PathSegment Slashes}* segments Slashes? [\ .] !<< (); // only the last segment must not end in spaces.

import ParseTree;

@synopsis{Convert a windows path literal to a source location URI}
@description{
Expand All @@ -50,14 +52,13 @@ hostname, share name and path segment names. Also all superfluous path separator
3. uses `loc + str` path concatenation with its builtin character encoding to construct the URI. Also
the right path separators are introduced.
}
loc parseWindowsPath(str input) = mapPathToLoc([WindowsPath] input);
loc parseWindowsPath(str input, loc src=|unknown:///|) = mapPathToLoc(parse(#WindowsPath, input, src));

@synopsis{UNC}
loc mapPathToLoc((WindowsPath) `<Slash _><Slash _><Slashes? _><PathChar* hostName><Slashes _><PathChar* shareName><Slashes _><WindowsFilePath path>`)
= (|file://<hostName>/| + "<shareName>" | it + "<segment>" | segment <- path.segments );

@synopsis{Absolute: given the drive and relative to its root.}
// loc mapPathToLoc((WindowsPath) `<[A-Za-z] drive>:<PathSep _><WindowsFilePath path>`)
loc mapPathToLoc((WindowsPath) `<Drive drive>:<Slashes _><WindowsFilePath path>`)
= (|file:///<drive>:/| | it + "<segment>" | segment <- path.segments);

Expand Down Expand Up @@ -85,6 +86,14 @@ test bool simpleDrivePathC()
= parseWindowsPath("C:\\Program Files\\Rascal")
== |file:///C:/Program%20Files/Rascal|;

test bool mixedSlashesDrivePathC()
= parseWindowsPath("C:\\Program Files/Rascal")
== |file:///C:/Program%20Files/Rascal|;

test bool trailingSlashesDrivePathC()
= parseWindowsPath("C:\\Program Files\\Rascal\\\\")
== |file:///C:/Program%20Files/Rascal|;

test bool simpleDrivePathD()
= parseWindowsPath("D:\\Program Files\\Rascal")
== |file:///D:/Program%20Files/Rascal|;

0 comments on commit ae8e3d3

Please sign in to comment.