agentleFS
jordanhubbardjordanhubbard/nanolang/.cursor/rules/code-quality/RULE.md

nanolang / code-quality

Cursor rule628 starsChanged 4 months agoApache-2.0View on GitHub

Code quality standards, parser architecture patterns, and development conventions

We split this RULE.md into the rules it gives an agent

20 rules. About 0 are common, 10 are distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If you add a new language feature to nanolang:

    line 10
  2. Very specific:

    Add feature to src/parser.c first

    line 13
  3. Distinctive:

    Ensure C compiler handles it (100% support required)

    line 14
  4. Very specific:

    Add corresponding AST struct in parser_mvp.nano

    line 17
  5. Distinctive:

    Add token helpers if needed

    line 20
  6. Very specific:

    Run ./bin/nanoc src_nano/parser_mvp.nano - must pass ✅

    line 23
  7. Very specific:

    Run make examples - must build ✅

    line 25
  8. Distinctive:

    Update feature lists in markdown docs

    line 28
  9. Very specific:

    Add to ParseNodeType enum

    line 43
  10. Distinctive:

    Create AST struct definition

    line 44
  11. Distinctive:

    Add list field to Parser struct

    line 45
  12. Distinctive:

    Add count field to Parser struct

    line 46
  13. Very specific:

    Create parser_store_* function (copy pattern from existing)

    line 49
  14. Very specific:

    Add parsing logic to appropriate parse_* function

    line 50
  15. Distinctive:

    Use functional style (return new Parser)

    line 56
  16. Very specific:

    No mutations except with mut keyword

    line 57
  17. Very specific:

    Use parser_with_error for syntax errors

    line 72
  18. Distinctive:

    Must compile itself in < 10 seconds

    line 81
  19. Distinctive:

    Document WHY, not WHAT

    line 90
  20. Distinctive:

    NO commits that break tests, ever

    line 147

≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
RULE.md

Code Quality Standards

When Adding Language Features

If you add a new language feature to nanolang:

  1. Stage 0 (C Compiler):
    • Add feature to src/parser.c first
    • Ensure C compiler handles it (100% support required)
  2. Stage 2 (Self-Hosted Parser):
    • Add corresponding AST struct in parser_mvp.nano
    • Add parser_store_* function
    • Integrate into parsing logic (critical!)
    • Add token helpers if needed
  3. Testing:
    • Run ./bin/nanoc src_nano/parser_mvp.nano - must pass ✅
    • Run ./tests/run_all_tests.sh - must pass ✅
    • Run make examples - must build ✅
  4. Documentation:
    • Update feature lists in markdown docs
    • Update completion percentages

Parser Architecture

Current Status

The self-hosted parser has:

  • 31 node types (complete)
  • 29 AST structs (complete)
  • 67 Parser fields (complete)
  • 22+ parsing functions (production-ready)

Adding New Node Types

  1. Add to ParseNodeType enum
  2. Create AST struct definition
  3. Add list field to Parser struct
  4. Add count field to Parser struct
  5. Initialize in parser_init_ast_lists
  6. Initialize in parser_new
  7. Create parser_store_* function (copy pattern from existing)
  8. Add parsing logic to appropriate parse_* function
  9. Test immediately

Code Patterns

Follow existing patterns:

  • Use functional style (return new Parser)
  • No mutations except with mut keyword
  • Consistent error handling
  • Shadow tests for validation

Parser Changes

  1. Never break existing functionality
  2. Always add shadow tests for new functions
  3. Keep architecture consistent
  4. Document complex logic

Error Handling

Parser Errors

  • Use parser_with_error for syntax errors
  • Include line/column information
  • Provide clear error messages
  • Never silently fail

Performance Standards

Parser Performance

  • Must compile itself in < 10 seconds
  • No memory leaks
  • Reasonable file size (< 5000 lines preferred)
  • Clean compilation (no warnings)

Documentation Standards

Code Comments

  • Document WHY, not WHAT
  • Complex algorithms need explanation
  • Edge cases should be noted
  • TODOs must have tracking

Git Workflow

Branch Names

  • feat/* - New features
  • fix/* - Bug fixes
  • docs/* - Documentation only
  • test/* - Test additions

Commit Messages

Format:

type: Brief description

Detailed explanation if needed

- Changes made
- Tests: status
- Self-hosting: status

Types: feat, fix, docs, test, refactor, perf

Pre-Commit Checklist

# 1. Compile check
./bin/nanoc src_nano/parser_mvp.nano || exit 1

# 2. Test check  
./tests/run_all_tests.sh || exit 1

# 3. Self-hosting check
./bin/nanoc src_nano/lexer_complete.nano || exit 1

Future-Proofing

When at 100% Completion

Once parser reaches 100% feature coverage:

  1. Lock Feature Parity:
    Any C parser feature MUST have self-hosted equivalent
  2. Test Coverage:
    New features MUST include tests
  3. Documentation:
    Feature docs MUST be complete before merge
  4. Green Status:
    NO commits that break tests, ever

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.