1+ """
2+ `MapExprFile(mapexpr, filename::String)` stores the arguments needed for
3+ `include(mapexpr, filename)`. `mapexpr` is a function mapping `Expr` to an
4+ `Expr`, which is applied to the parsed expressions from `filename` before
5+ evaluation. This is sometimes used for preprocessing files before they are
6+ loaded.
7+
8+ Otherwise, `MapExprFile` behaves like a string, allowing it to be used
9+ wherever a file path is expected.
10+ """
11+ struct MapExprFile <: AbstractString
12+ mapexpr
13+ filename:: String
14+ end
15+ MapExprFile (filename:: String ) = MapExprFile (identity, filename)
16+
17+ Base. show (io:: IO , mapfile:: MapExprFile ) =
18+ print (io, " MapExprFile(" , mapfile. mapexpr, " , \" " , mapfile. filename, " \" )" )
19+
20+ # AbstractString interface
21+ Base. iterate (mapfile:: MapExprFile ) = iterate (mapfile. filename)
22+ Base. iterate (mapfile:: MapExprFile , state:: Integer ) = iterate (mapfile. filename, state)
23+
24+ Base. getindex (mapfile:: MapExprFile , i:: Integer ) = getindex (mapfile. filename, i)
25+
26+ Base. ncodeunits (mapfile:: MapExprFile ) = ncodeunits (mapfile. filename)
27+ Base. codeunit (mapfile:: MapExprFile , i:: Integer ) = codeunit (mapfile. filename, i)
28+
29+ Base.:(== )(mapfile1:: MapExprFile , mapfile2:: MapExprFile ) =
30+ (mapfile1. mapexpr == mapfile2. mapexpr) & (mapfile1. filename == mapfile2. filename)
31+ Base.:(== )(mapfile1:: MapExprFile , file2:: AbstractString ) = false
32+ Base.:(== )(file1:: AbstractString , mapfile2:: MapExprFile ) = false
33+
34+ # Don't lose the `mapexpr` from common path operations
35+ Base.:(* )(mapfile:: MapExprFile , path:: AbstractString ) =
36+ MapExprFile (mapfile. mapexpr, mapfile. filename * path)
37+ Base.:(* )(path:: AbstractString , mapfile:: MapExprFile ) =
38+ MapExprFile (mapfile. mapexpr, path * mapfile. filename)
39+ # The above would be enough for `joinpath` except for its return-type assertion ::String
40+ function Base. joinpath (mapfile:: MapExprFile , path:: AbstractString )
41+ @assert ! isa (path, MapExprFile) " Cannot join MapExprFile with another MapExprFile"
42+ return MapExprFile (mapfile. mapexpr, joinpath (mapfile. filename, path))
43+ end
44+ function Base. joinpath (path:: AbstractString , mapfile:: MapExprFile )
45+ @assert ! isa (path, MapExprFile) " Cannot join MapExprFile with another MapExprFile"
46+ return MapExprFile (mapfile. mapexpr, joinpath (path, mapfile. filename))
47+ end
48+ Base. normpath (mapfile:: MapExprFile ) = MapExprFile (mapfile. mapexpr, normpath (mapfile. filename))
49+ Base. abspath (mapfile:: MapExprFile ) = MapExprFile (mapfile. mapexpr, abspath (mapfile. filename))
50+ function Base. relpath (mapfile:: MapExprFile , path:: AbstractString )
51+ @assert ! isa (path, MapExprFile) " Cannot get relative path from MapExprFile to another MapExprFile"
52+ return MapExprFile (mapfile. mapexpr, relpath (mapfile. filename, path))
53+ end
54+
155"""
256PkgFiles encodes information about the current location of a package.
357Fields:
@@ -10,7 +64,7 @@ Note that `basedir` may be subsequently updated by Pkg operations such as `add`
1064mutable struct PkgFiles
1165 id:: PkgId
1266 basedir:: String
13- files:: Vector{Any}
67+ files:: Vector{Any} # might contain `filename::String`, `::MapExprFile`, or custom file types (https://github.com/timholy/Revise.jl/pull/680)
1468end
1569
1670PkgFiles (id:: PkgId , path:: AbstractString ) = PkgFiles (id, path, Any[])
0 commit comments