Add a location symbol for include specifiers #354
Labels
proposed feature
A proposed new feature
semantics
Issues related to semantics
spec
Issues related to the FPP language specification
syntax
Issues related to syntax
Currently the path in an include specifier is resolved relative to the location of the include specifier. This makes it hard to "drop in" library code that uses include specifiers, because the location of the specifier may not be known by the author of the specifier. For example, a file that says
include "../../foo/bar.fppi"
must be two directories down from the start of the relative pathfoo/bar.fppi
. But a user may want to put the file in a different place.The proposal is as follows:
Add a new kind of symbol called a location symbol. For example
Add a new location specifier for location symbols:
In an include specifier, allow a location symbol to be specified. For example:
In item 1,
L
is the name of a location definition. To simplify the name resolution, location definitions may occur only at the top level (not inside a module or any other scoped construct). The name may be a qualified name, e.g.,A.B.C
, and the qualification is unrelated to the qualification implied by the nesting of scoped constructs. This approach is similar to Java and Scala package names.In item 2, the location specifier says that the definition of location
L
is located in the file[absolute path]/foo.fpp
, where[absolute path]
is the absolute path of the directory containing the file containing the specifier.In item 3, the include path
bar/baz.fppi
is relative to the location of the symbolL
. The user can put the file with the include specifier anywhere; the location specifier forL
will say where the root of the pathbar/baz.fppi
is. In the example in item 2, the root is[absolute path]
.The
at
construct for instance definitions could work similarly:To make the analysis deterministic, we can use the following algorithm:
include
specifiers in the modelinclude
specifiers that have no location specifier.include
specifiers that have location specifiers.For example, consider the following input:
a.fpp
:include b.fppi
b.fppi
:location L
c.fpp
:include L d.fppi
d.fppi
: EmptyWe would resolve
include b.fppi
; then we would resolve the use ofL
ininclude L d.fppi
; then we would resolveinclude L d.fppi
.An attempt to include a location specifier through another location specifier would fail. For example, this input would fail, because the symbols
L
andM
would be undefined in step 2:a.fpp
:include M b.fppi
b.fppi
:location L
c.fpp
:include L d.fppi
d.fppi
:location M
The text was updated successfully, but these errors were encountered: