How compilation works
The compiler reads a .cherri file, builds the full source, turns it into tokens, turns the tokens into Shortcut actions, and writes the result as a signed Shortcut.
Table of contents
Pipeline
flowchart TD
source[".cherri file"] --> read["Read the file<br/>handleFile"]
read --> pre["Build the full source<br/>preParse"]
pre --> parse["Turn characters into tokens<br/>parse"]
parse --> gen["Turn tokens into Shortcut actions<br/>generateShortcut"]
gen --> write["Encode the property list<br/>createShortcut"]
write --> skip{"--skip-sign?"}
skip -- yes --> unsigned["NAME_unsigned.shortcut"]
skip -- no --> sign["Sign the Shortcut"]
sign --> signed["NAME.shortcut"]
| Stage | Function | File | What it does |
|---|---|---|---|
| Read | handleFile() | main.go | Reads the file and sets the Shortcut name from the file name. |
| Build the full source | preParse() | parser.go | Resolves packages and includes, then expands imports, copy and paste, action definitions and functions. |
| Parse | parse() | parser.go | Reads the source one character at a time and collects tokens. See Parsing. |
| Generate | generateShortcut() | shortcutgen.go | Fills in the Shortcut header, then generates actions from the tokens. |
| Write | createShortcut() | output.go | Encodes the Shortcut as a property list and signs it. See Signing. |
Building the full source
preParse() rewrites the file contents before any parsing happens, in this order:
- Install and include packages, if there is an
info.plistin the current directory. - Add
#include 'actions/basic'to the top. - Resolve every
#include. - Collect import actions.
- Expand copy and paste macros.
- Collect action definitions.
- Process functions.
With --debug, the result is written to NAME_processed.cherri.
Tokens to actions
generateActions() walks the tokens in order and creates the actions for each one. Variables and control flow are tokens like any other, so they produce actions too.
| Token | Generates |
|---|---|
Variable, +=, -=, *=, /= | Variable actions |
| Action call | The action |
repeat | A repeat action group |
for | A repeat with each action group |
menu and item | A menu action group |
if | A conditional action group |
| Comment | A comment action, only with --comments |
The property list itself is covered in Property List Generation.