|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with |
| 4 | +code in this repository. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +YAMLScript (YS) is a functional programming language that uses YAML syntax and |
| 9 | +compiles to Clojure. |
| 10 | +It provides: |
| 11 | +- A YAML loader library for 15+ programming languages |
| 12 | +- A standalone `ys` command-line tool |
| 13 | +- Native shared library `libys.so` for language bindings |
| 14 | + |
| 15 | +## Coding style |
| 16 | + |
| 17 | +* **Wrap lines at exactly 80 characters** - This is strictly enforced |
| 18 | +* Use 2 spaces for indentation in most languages |
| 19 | +* Use styles already established in the file |
| 20 | +* Prefer single quotes over double quotes when possible and appropriate |
| 21 | +* In yaml files: |
| 22 | + * Don't over-indent sequences in block mappings |
| 23 | + * Don't quote scalar values that don't need to be quoted |
| 24 | +* Use `ReadMe.md`, not `README.md` |
| 25 | +* For markdown files: |
| 26 | + * **Start each sentence on a new line** |
| 27 | + * **Wrap lines at exactly 80 characters** - count carefully |
| 28 | + * Put 2 blank lines before a section heading |
| 29 | + |
| 30 | +## Common Development Commands |
| 31 | + |
| 32 | +GNU Make is used for all dev tasks. |
| 33 | +Almost every directory has a Makefile, and they use the `common/*.mk` files |
| 34 | +for shared logic. |
| 35 | +They also automatically install the https://github.com/makeplus/makes project |
| 36 | +into the `.cache/makes` directory. |
| 37 | +The makes project has a file for each language dependency and it automatically |
| 38 | +installs them for you locally (languages are never assumed to be installed on |
| 39 | +the system). |
| 40 | +As long as a machine has `bash`, `curl`, `git` and `make`, it can build and test |
| 41 | +YS and every language binding. |
| 42 | + |
| 43 | +### Building |
| 44 | +```bash |
| 45 | +# Build everything (uses Docker on Linux x86_64) with ubuntu:20.04 to support |
| 46 | +# older glibc versions. |
| 47 | +make build |
| 48 | + |
| 49 | +# Build specific components |
| 50 | +make build-ys # Build ys CLI tool |
| 51 | +make build-libys # Build libys shared library |
| 52 | + |
| 53 | +# Build from source (requires: bash, curl, git, make) |
| 54 | +make build |
| 55 | +make install # Installs to ~/.local/{bin,lib} by default |
| 56 | +make install PREFIX=/custom/path |
| 57 | +``` |
| 58 | + |
| 59 | +### Testing |
| 60 | +```bash |
| 61 | +# Run all tests (takes several minutes) |
| 62 | +make test |
| 63 | + |
| 64 | +# Test specific components |
| 65 | +make test-core # Test core Clojure code |
| 66 | +make test-ys # Test ys CLI |
| 67 | +make test-bindings # Test all language bindings |
| 68 | +make test-nodejs # Test specific binding (replace nodejs with any binding) |
| 69 | +make -C <lang-dir> test # Test specific binding |
| 70 | + |
| 71 | +# Run tests with verbose output |
| 72 | +make test v=1 |
| 73 | +``` |
| 74 | + |
| 75 | +### Installing |
| 76 | +```bash |
| 77 | +# Install ys and libys binaries |
| 78 | +make install # To ~/.local/{bin,lib} |
| 79 | +make install PREFIX=/usr/local # Custom location |
| 80 | +``` |
| 81 | + |
| 82 | +## High-Level Architecture |
| 83 | + |
| 84 | +### Repository Structure |
| 85 | +This is a monorepo containing: |
| 86 | + |
| 87 | +- **core/** - Core YAMLScript compiler written in Clojure (compiles YS to |
| 88 | + Clojure AST) |
| 89 | +- **libys/** - Native shared library built from core using GraalVM native-image |
| 90 | +- **ys/** - Command-line tool for running/loading/compiling YS programs |
| 91 | +- **Language bindings** (clojure/, crystal/, go/, java/, nodejs/, perl/, php/, |
| 92 | + python/, raku/, ruby/, rust/, etc.) |
| 93 | + - Each binding wraps libys to provide native language integration |
| 94 | + |
| 95 | +### Build System |
| 96 | +- Uses GNU Make with custom Makefile infrastructure |
| 97 | +- common/*.mk files provide shared build logic |
| 98 | +- GraalVM native-image compiles Clojure to native binaries (ys and libys.so) |
| 99 | +- Docker is used for consistent Linux x86_64 builds |
| 100 | + |
| 101 | +### Compilation Pipeline |
| 102 | +1. YS source → Parser (YAML → data structure) |
| 103 | +2. Data → Composer (applies YS language rules) |
| 104 | +3. Composed data → Compiler (generates Clojure code) |
| 105 | +4. Clojure code → SCI runtime (executes without JVM) |
| 106 | + |
| 107 | +### Testing |
| 108 | +- Core tests use Leiningen (`lein test`) |
| 109 | +- CLI tests use Perl's `prove` with BPAN framework |
| 110 | +- Language bindings have their own test suites |
| 111 | + |
| 112 | +## Key Technical Details |
| 113 | + |
| 114 | +- YS files use `.ys` extension |
| 115 | +- Programs starting with `!YS-v0` tag have functional capabilities |
| 116 | +- `YS-v0` starts in code mode, `YS-v0:` data mode, neither implies bare mode |
| 117 | +- Without the tag, YS loads standard YAML 1.2 Core Schema |
| 118 | +- Version format: 0.2.3 (semantic versioning) |
| 119 | +- API version: v0 (for backward compatibility) |
| 120 | + |
| 121 | +## Language Binding Development |
| 122 | + |
| 123 | +Each binding requires: |
| 124 | +- Wrapper around libys.so FFI calls |
| 125 | +- load() and eval() methods minimum |
| 126 | +- Tests matching the core test suite |
| 127 | +- Package manager integration (npm, pip, gem, etc.) |
| 128 | + |
| 129 | +## Important Files |
| 130 | + |
| 131 | +- Makefile - Main build orchestration |
| 132 | +- core/src/yamlscript/*.clj - Compiler implementation |
| 133 | +- core/src/ys/*.clj - YS runtime libraries |
| 134 | +- ys/src/yamlscript/cli.clj - CLI implementation |
| 135 | +- sample/**/*.ys - Example YS programs |
0 commit comments