Reserved Keyword Validation

Reserved Keyword Validation

Cade reserves a fixed set of identifiers for its built-in vocabulary — block types, built-in functions, scope prefixes, and so on. Using a reserved name for a device, variable, or block can produce errors or warnings depending on the pragma mode. Two CLI commands help: cade validate checks for conflicts, and cade migrate can rename offenders automatically.

Keyword Categories

Every reserved identifier falls into one category. The category determines both its default severity and the kind of rename the migration tool will suggest.

CategoryExamplesTypical severity
block_typedevice, event, variable, modeError (strict conflict)
sub_typebutton, solenoid, score, timerError when used as a block qualifier
builtin_functionclamp, abs, min, maxError in variable or function names
special_valuetrue, false, nullError
scope_identifierself, parent, globalError as a block name
source_identifierdevice, event, variableContextual
path_prefixhw, sw, ioWarning by default
future_keywordNames reserved for planned featuresWarning — may become an error in a future release

Pragma Modes

The pragma block (or the --pragma-mode flag) controls how strictly reserved names are enforced.

ModeStrict keywordsContextual keywordsFuture keywords
strictErrorErrorError
normal (default)ErrorWarningWarning
relaxedWarningAllowAllow

cade validate --check-reserved-words

Reserved word validation is opt-in, so existing configs that happen to collide with a reserved name keep working until you enable the check.

cade validate --check-reserved-words                       # Run the checks
cade validate --check-reserved-words --strict              # All reserved words become errors
cade validate --check-reserved-words --pragma-mode=relaxed # Only strict keywords warn
cade validate --strict                                     # Shortcut: implies --check-reserved-words
FlagDefaultEffect
--check-reserved-wordsoffRun the reserved word stage.
--strictoffEnable strict mode; also enables --check-reserved-words.
--pragma-modenormalOverride the pragma mode (strict, normal, or relaxed).
--ignore-pragmaoffSkip the pragma block. Also skips reserved word checks.

Reserved word findings appear in all output formats (text, json, yaml), each tagged with its category and a list of suggested renames.

cade migrate --reserved-words

Use migrate to rewrite conflicting identifiers. Run it without --auto-fix first to preview the changes.

# Preview conflicts
cade migrate --reserved-words config.cade

# Rewrite in place (backs up each file as <file>.cade.bak)
cade migrate --reserved-words --auto-fix config.cade

# Scan a directory
cade migrate --reserved-words -d ./configs/

# Recursive scan
cade migrate --reserved-words -d ./configs/ -r

# Choose which severity tier to migrate
cade migrate --reserved-words --pragma-mode=strict config.cade

Preview output:

Reserved Word Conflicts: 3 found in 2 files

config.cade:12:3  device "score"  [block_type]
  Suggestions: my_score, game_score, custom_score

config.cade:18:1  variable "clamp"  [builtin_function]
  Suggestions: clamp_val, clamp_count

modes.cade:5:3  device "self"  [scope_identifier]
  Suggestions: my_self, this_device

With --auto-fix, the first suggestion from the suggestion engine replaces each conflicting name. A summary lists every rename applied, and each modified file is backed up as <file>.cade.bak before writing.

Exit codes:

CodeMeaning
0No conflicts found, or --auto-fix completed cleanly
1Conflicts found (preview) or error during fix
FlagDefaultEffect
--auto-fixoffRewrite files using suggestions (preview only when omitted).
--formattextOutput format — text or json.
-d <dir>Directory of .cade files to scan.
-roffRecurse into subdirectories.
--pragma-modenormalWhich severity tier gets migrated.

Suggestion Patterns

The migration tool picks a rename strategy based on where the name is used:

ContextTypical rename
Block namePrefix with my_, game_, or custom_
Variable nameSuffix with _val, _count, or _total
Function namePrefix with calc_ or compute_