c3d / xl

A minimalist, general-purpose programming language based on meta-programming and parse tree rewrites
GNU General Public License v3.0
270 stars 15 forks source link

Process `syntax` statements during scanning (in `import` / `use`) #25

Open c3d opened 4 years ago

c3d commented 4 years ago

A syntax statement within an imported file will not currently change the syntax in the importing file, only locally.

In order for the syntax extensions to propagate to the importing file, we need the scanner and parser to recognize that there is a syntax statement, mark it so that import will be aware of it. That, in turn, may require import to be processed early, e.g. during scanning.

Example:

// imported.xl
module IMPORTED with
    syntax { POSTFIX 130 cm mm km dm m }
    type distance is matching (D:real m)
    D:real km as distance is (D * 1000) m
    D:real mm as distance is (D * 0.001) m

// Importing file
use IMPORTED

D : distance := 3.2km