Skip to main content
The axon check command performs full front-end validation of AXON source code, including lexical analysis, parsing, and semantic type checking.

Synopsis

axon check <file.axon> [--no-color]

Description

Validates an .axon source file through the complete compilation front-end pipeline:
  1. Lexer — Tokenizes source code and validates syntax
  2. Parser — Builds an Abstract Syntax Tree (AST)
  3. Type Checker — Performs semantic validation and type inference
This command does not execute code or make any API calls. It’s safe to run on untrusted input and perfect for CI/CD validation.

Arguments

file
string
required
Path to the .axon source file to validate

Options

--no-color
flag
Disable ANSI color codes in output (useful for log files or non-TTY environments)

Exit Codes

CodeMeaning
0Clean — no errors detected
1Errors detected (lexer, parser, or type errors)
2File not found or I/O error

Output Format

Success Output

$ axon check contract_analyzer.axon
 contract_analyzer.axon  87 tokens · 12 declarations · 0 errors
Success output includes:
  • ✓ Green checkmark
  • Filename in bold
  • Token count
  • Declaration count
  • Error count (always 0 on success)

Error Output

$ axon check broken.axon
 broken.axon:15:8  Unexpected token 'END'
Error output includes:
  • ✗ Red X mark
  • Filename with location (line:column)
  • Error message

Type Error Output

$ axon check invalid_types.axon
 invalid_types.axon 2 type error(s)
  error line 23: Cannot assign 'Opinion' to 'FactualClaim'
  error line 31: Undefined reference: 'UknownType'

Examples

Basic Validation

axon check program.axon
Validate a single AXON program.

CI/CD Integration

# Validate all .axon files in a project
find src -name "*.axon" -exec axon check {} \;

# With exit code checking
if axon check main.axon; then
  echo "Validation passed"
else
  echo "Validation failed"
  exit 1
fi

Non-Interactive Mode

axon check program.axon --no-color > validation.log 2>&1
Capture output without color codes for log processing.

Pre-Commit Hook

#!/bin/bash
# .git/hooks/pre-commit
for file in $(git diff --cached --name-only | grep '\.axon$'); do
  if ! axon check "$file" --no-color; then
    echo "Validation failed for $file"
    exit 1
  fi
done

Error Categories

Lexer Errors

Lexical errors occur during tokenization:
 program.axon:10:15  Unterminated string literal
Common causes:
  • Unterminated strings
  • Invalid characters
  • Malformed numbers

Parser Errors

Syntactic errors occur during AST construction:
 program.axon:23:1  Expected 'output:' but found 'END'
Common causes:
  • Missing required keywords
  • Incorrect block structure
  • Unbalanced braces

Type Errors

Semantic errors occur during type checking:
 program.axon 1 type error(s)
  error line 42: Type mismatch: expected 'CitedFact', got 'Opinion'
Common causes:
  • Type incompatibility
  • Undefined references
  • Invalid type assignments
  • Epistemic type violations (e.g., Opinion → FactualClaim)

Performance

The check command is optimized for fast feedback:
  • Small files (<100 lines): ~10-50ms
  • Medium files (100-500 lines): ~50-200ms
  • Large files (500+ lines): ~200-500ms
No network calls are made, so performance is purely CPU-bound.

compile

Compile to IR after validation

run

Execute after validation

Troubleshooting

File Not Found

 File not found: program.axon
Solution: Verify the file path and ensure the file exists.

Permission Denied

Solution: Check file permissions with ls -l and ensure read access.

Encoding Issues

Solution: AXON expects UTF-8 encoding. Convert files if necessary:
iconv -f ISO-8859-1 -t UTF-8 program.axon -o program_utf8.axon

Build docs developers (and LLMs) love