Import Directives

John Horigan edited this page Mar 18, 2015 · 1 revision

An import directive inserts another CFDG file into the input stream right after the directive. Context Free/CFDG can handle imported files importing other files in turn with no real limit on import depth. An import directive looks like the keyword import followed by the name of the CFDG file to import. This name can either be one of the items in the Examples menu or a file on your hard disk. For files on your hard disk you supply the relative path from the directory where the importing CFDG file resides. This means that if a new CFDG file imports another CFDG file (not an example) then you need to save it to disk first so that Context Free/CFDG knows where to base the relative path.

If the file to import is in a different directory or has spaces in its relative path then you must put the relative path in quotes. Quotes are optional if the import file is in the same directory, has no spaces in its name, and ends in .cfdg

startshape TITLES
import i_pix.cfdg   // from the Examples menu
import "../lib/shapeLib.cfdg"
import "file name with gratuitous spaces.cfdg"
 
shape TITLES {
        TITLE1 [ x 0 y 4.5 ]
        TITLE2 [ x 0 y 3 ]
        TITLE3 [ x 0 y 1.5 ]
        TITLE4 [ x 0 y 0 ]
}
shape TITLE1 {
        O_5by5 [ x 0 ]
        N_5by5 [ x 1.2 ]
        E_5by5 [ x 2.4 ]
}
shape TITLE2 {
        T_5by5 [ x 0 ]
        W_5by5 [ x 1.2 ]
        O_5by5 [ x 2.4 ]
}
shape TITLE3 {
        T_5by5 [ x 0 ]
        H_5by5 [ x 1.2 ]
        R_5by5 [ x 2.4 ]
        E_5by5 [ x 3.6 ]
        E_5by5 [ x 4.8 ]
}
shape TITLE4 {
        F_5by5 [ x 0 ]
        O_5by5 [ x 1.2 ]
        U_5by5 [ x 2.4 ]
        R_5by5 [ x 3.6 ]
}

Importing into a Namespace

The shapes, paths, global variables, and functions imported via an import directive are imported into the same namespace as the importing cfdg file. The file can be imported into a namespace under the current namespace using the import@ feature.

startshape EITHER
 
import@foo mtree.cfdg
 
shape EITHER {
  foo::EITHER[]
}

The EITHER shape in this cfdg file is distinct from the EITHER shape in mtree.cfdg. import@foo imports mtree.cfdg into the foo namespace and the only way to invoke its shapes is to prepend foo:: to its shape names.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.