Collecting Files

The first step decides what the program is: which source files, in which folders. A Refingere program has no list of its files and no imports - it's every .rfn file under the folder it's compiled from, the project's root (see Files and Folders). So the compiler starts by walking that folder.

Given a file or a folder. Gives the source files' paths, relative to the root, in a tree mirroring the folders - the folders matter later, since a name is seen by the rest of its folder and a path like `/pricing/total` is read from the root. In bootstrapping/0-collect; --files prints what it found.

How it works

It reads the root folder's entries, and each subfolder's in turn. A file is kept when its name ends in .rfn; anything else is left out. Two kinds of folder are never looked in: node_modules, which holds installed packages rather than the project's own code, and any folder whose name starts with a dot - .git, editor settings - which never hold sources and can be large to walk. A folder with no source file anywhere under it is left out of the tree too, so later steps never see empty folders.

Entries are sorted by name at each level, and a folder's own files come before its subfolders'. A file system promises no order of its own, and the compiler's results - which file's error is reported first, the order files are checked in - should be the same on every machine.

Files are only found here, not read - each is read when it's lexed. Given a single file instead of a folder, the program is that one file, and its folder is the root.

What it gives

What it reports

Only what stops it from reading the folder at all: a root that isn't a folder, or one that can't be listed. A folder with no source files is a program with nothing in it, not an error.

In the TypeScript compiler

src/0-readFiles does the same walk, and reads and parses each file as it's found, building one tree of folders and files that every later step adds its findings to.

Next: Lexing.