rip-lang 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules/rip-agent-onboarding.md +681 -0
- package/.github/ISSUE_TEMPLATE/bug_report.yml +98 -0
- package/.github/ISSUE_TEMPLATE/coffeescript_compatibility.yml +86 -0
- package/.github/ISSUE_TEMPLATE/config.yml +9 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +82 -0
- package/.github/ISSUE_TEMPLATE/question.yml +55 -0
- package/.github/pull_request_template.md +84 -0
- package/AGENT.md +623 -0
- package/CONTRIBUTING.md +331 -0
- package/LICENSE +21 -0
- package/README.md +1245 -0
- package/SETUP.md +144 -0
- package/bar.coffee +394 -0
- package/bin/rip +162 -0
- package/bunfig.toml +11 -0
- package/docs/BROWSER.md +983 -0
- package/docs/CODEGEN.md +1023 -0
- package/docs/COFFEESCRIPT-COMPARISON.md +740 -0
- package/docs/COMPREHENSIONS.md +572 -0
- package/docs/REGEX-PLUS.md +441 -0
- package/docs/SOLAR.md +846 -0
- package/docs/SPECIAL-OPERATORS.md +769 -0
- package/docs/STRING.md +363 -0
- package/docs/WHY-NOT-COFFEESCRIPT.md +184 -0
- package/docs/WHY-YES-RIP.md +690 -0
- package/docs/WORKFLOW.md +306 -0
- package/docs/dist/rip.browser.js +6798 -0
- package/docs/dist/rip.browser.min.js +242 -0
- package/docs/dist/rip.browser.min.js.br +0 -0
- package/docs/example.html +177 -0
- package/docs/examples/README.md +154 -0
- package/docs/examples/arrows.rip +84 -0
- package/docs/examples/async-await.rip +59 -0
- package/docs/examples/existential.rip +86 -0
- package/docs/examples/fibonacci.rip +12 -0
- package/docs/examples/module.rip +38 -0
- package/docs/examples/object-syntax.rip +74 -0
- package/docs/examples/prototype.rip +30 -0
- package/docs/examples/ranges.rip +45 -0
- package/docs/examples/switch.rip +50 -0
- package/docs/examples/ternary.rip +36 -0
- package/docs/examples/use-loader.js +9 -0
- package/docs/examples/utils.rip +20 -0
- package/docs/index.html +65 -0
- package/docs/repl.html +914 -0
- package/docs/rip-1280w.png +0 -0
- package/docs/rip.svg +4 -0
- package/package.json +52 -0
- package/rip-loader.ts +27 -0
- package/scripts/build-browser.js +76 -0
- package/scripts/serve.js +71 -0
- package/src/browser.js +97 -0
- package/src/codegen.js +4808 -0
- package/src/compiler.js +270 -0
- package/src/grammar/grammar.rip +801 -0
- package/src/grammar/solar.rip +1056 -0
- package/src/lexer.js +3145 -0
- package/src/parser.js +352 -0
- package/src/repl.js +423 -0
- package/test/rip/assignment.rip +115 -0
- package/test/rip/async.rip +361 -0
- package/test/rip/basic.rip +171 -0
- package/test/rip/classes.rip +167 -0
- package/test/rip/compatibility.rip +338 -0
- package/test/rip/comprehensions.rip +104 -0
- package/test/rip/control.rip +177 -0
- package/test/rip/data.rip +215 -0
- package/test/rip/errors.rip +129 -0
- package/test/rip/functions.rip +443 -0
- package/test/rip/guards.rip +247 -0
- package/test/rip/literals.rip +131 -0
- package/test/rip/loops.rip +117 -0
- package/test/rip/modules.rip +87 -0
- package/test/rip/operators.rip +158 -0
- package/test/rip/optional.rip +184 -0
- package/test/rip/properties.rip +94 -0
- package/test/rip/regex.rip +301 -0
- package/test/rip/stabilization.rip +825 -0
- package/test/rip/strings.rip +483 -0
- package/test/runner.js +329 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
# Rip Language - AI Agent Onboarding
|
|
2
|
+
|
|
3
|
+
**Welcome!** You're working on Rip, an elegant scripting language compiler. This guide gets you productive quickly.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🚀 Quick Start (5 Minutes)
|
|
8
|
+
|
|
9
|
+
### Step 1: Read These First (in order)
|
|
10
|
+
|
|
11
|
+
1. **AGENT.md** (10 min) - Complete architecture, commands, patterns
|
|
12
|
+
2. **README.md** - Skim for features and current status
|
|
13
|
+
3. **CONTRIBUTING.md** - GitHub workflow with real examples
|
|
14
|
+
4. **docs/WORKFLOW.md** - Quick command reference
|
|
15
|
+
|
|
16
|
+
### Step 2: Understand the Pipeline
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Rip Source → Lexer → Parser → S-Expressions → Codegen → JavaScript
|
|
20
|
+
(3,146) (340) (arrays!) (4,738) (ES2022)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Key insight:** S-expressions (simple arrays like `["=", "x", 42]`) are the IR, not complex AST nodes. This makes the compiler 50% smaller than CoffeeScript.
|
|
24
|
+
|
|
25
|
+
### Step 3: Essential Commands
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Debug any code
|
|
29
|
+
echo 'your code' | ./bin/rip -t # Tokens (lexer)
|
|
30
|
+
echo 'your code' | ./bin/rip -s # S-expressions (parser)
|
|
31
|
+
echo 'your code' | ./bin/rip -c # JavaScript (codegen)
|
|
32
|
+
|
|
33
|
+
# Run tests
|
|
34
|
+
bun run test # All 854 tests
|
|
35
|
+
bun test/runner.js test/rip/FILE.rip # Specific file
|
|
36
|
+
bun --no-cache test/runner.js test/rip # Clear Bun cache
|
|
37
|
+
|
|
38
|
+
# Rebuild parser (after grammar changes)
|
|
39
|
+
bun run parser # Regenerates src/parser.js from grammar.rip
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 🎯 What You're Working On
|
|
45
|
+
|
|
46
|
+
**Check for active issues/branches:**
|
|
47
|
+
```bash
|
|
48
|
+
gh issue list
|
|
49
|
+
git branch -a
|
|
50
|
+
cat ISSUE-*.md # Handoff docs for complex issues
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**If resuming Issue #11 (nested comprehension IIFEs):**
|
|
54
|
+
- Read `ISSUE-11.md` for complete analysis
|
|
55
|
+
- Branch: `fix/nested-comprehension-context`
|
|
56
|
+
- See "Recommended Approach" section
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🏗️ Architecture Essentials
|
|
61
|
+
|
|
62
|
+
### Files You'll Modify
|
|
63
|
+
|
|
64
|
+
| File | Purpose | Can Edit? | Rebuild? |
|
|
65
|
+
|------|---------|-----------|----------|
|
|
66
|
+
| `src/codegen.js` | Code generator | ✅ YES | No |
|
|
67
|
+
| `src/grammar/grammar.rip` | Grammar rules | ⚠️ Expert | `bun run parser` |
|
|
68
|
+
| `src/grammar/solar.rip` | Parser generator | ⚠️ Runtime only | `bun run parser` |
|
|
69
|
+
| `src/compiler.js` | Pipeline | ✅ YES | No |
|
|
70
|
+
| `src/lexer.js` | Tokenizer | ⚠️ Rewriter only | No |
|
|
71
|
+
| `src/parser.js` | Parser | ❌ NEVER | Generated |
|
|
72
|
+
| `test/rip/*.rip` | Tests | ✅ YES | No |
|
|
73
|
+
|
|
74
|
+
### The Golden Rule
|
|
75
|
+
|
|
76
|
+
**If it's generated, don't edit it directly!**
|
|
77
|
+
- `src/parser.js` is generated by solar.rip from grammar.rip
|
|
78
|
+
- After editing grammar.rip or solar.rip: `bun run parser`
|
|
79
|
+
|
|
80
|
+
### S-Expression Patterns
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
["=", "x", 42] // Assignment
|
|
84
|
+
["+", left, right] // Binary operator
|
|
85
|
+
["def", "fn", params, body] // Function definition
|
|
86
|
+
["comprehension", expr, iterators, guards] // Comprehension
|
|
87
|
+
["for-in", vars, iterable, step, guard, body] // For loop
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See `docs/CODEGEN.md` for complete catalog (110+ node types).
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 🧪 Testing Philosophy
|
|
95
|
+
|
|
96
|
+
### Always Write Tests First
|
|
97
|
+
|
|
98
|
+
```coffeescript
|
|
99
|
+
# test/rip/RELEVANT_FILE.rip
|
|
100
|
+
|
|
101
|
+
# Execute and compare result
|
|
102
|
+
test "name", "x = 42; x", 42
|
|
103
|
+
|
|
104
|
+
# Compare generated JavaScript
|
|
105
|
+
code "name", "x + y", "(x + y)"
|
|
106
|
+
|
|
107
|
+
# Expect compilation failure
|
|
108
|
+
fail "name", "invalid syntax"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Test Organization
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
test/rip/
|
|
115
|
+
├── assignment.rip (43 tests)
|
|
116
|
+
├── async.rip (29 tests)
|
|
117
|
+
├── comprehensions.rip (24 tests) ← Nested comprehension tests here
|
|
118
|
+
├── functions.rip (71 tests)
|
|
119
|
+
├── loops.rip (25 tests)
|
|
120
|
+
... 15 more files
|
|
121
|
+
Total: 854 tests (100% passing)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Test-Driven Development
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# 1. Add failing test
|
|
128
|
+
# 2. Run: bun test/runner.js test/rip/FILE.rip
|
|
129
|
+
# 3. Verify it fails
|
|
130
|
+
# 4. Implement fix
|
|
131
|
+
# 5. Run tests until they pass
|
|
132
|
+
# 6. Run ALL tests: bun run test
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 🔧 Common Tasks
|
|
138
|
+
|
|
139
|
+
### Fix a Bug in Codegen
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
# 1. Debug the pattern
|
|
143
|
+
echo 'failing code' | ./bin/rip -s # See s-expression
|
|
144
|
+
|
|
145
|
+
# 2. Find the case
|
|
146
|
+
grep -A 20 "case 'pattern':" src/codegen.js
|
|
147
|
+
|
|
148
|
+
# 3. Fix the generation logic
|
|
149
|
+
vim src/codegen.js
|
|
150
|
+
|
|
151
|
+
# 4. Test immediately
|
|
152
|
+
bun test/runner.js test/rip/RELEVANT.rip
|
|
153
|
+
|
|
154
|
+
# 5. Run all tests
|
|
155
|
+
bun run test
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Add a Grammar Rule
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# 1. Edit grammar
|
|
162
|
+
vim src/grammar/grammar.rip
|
|
163
|
+
|
|
164
|
+
# 2. Regenerate parser
|
|
165
|
+
bun run parser # ~200ms, instant feedback!
|
|
166
|
+
|
|
167
|
+
# 3. Add codegen case if needed
|
|
168
|
+
vim src/codegen.js
|
|
169
|
+
|
|
170
|
+
# 4. Test
|
|
171
|
+
bun run test
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Modify Parser Runtime Behavior
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Example: Improve error messages (Issue #7)
|
|
178
|
+
|
|
179
|
+
# 1. Edit solar.rip (NOT parser.js!)
|
|
180
|
+
vim src/grammar/solar.rip
|
|
181
|
+
# Edit the parseError function, parse function, etc.
|
|
182
|
+
|
|
183
|
+
# 2. Regenerate parser
|
|
184
|
+
bun run parser # Compiles solar.rip and regenerates parser.js
|
|
185
|
+
|
|
186
|
+
# 3. Test
|
|
187
|
+
bun run test
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 🎓 Key Concepts to Understand
|
|
193
|
+
|
|
194
|
+
### 1. Context-Aware Generation
|
|
195
|
+
|
|
196
|
+
**Most important concept in Rip!**
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
generate(sexpr, context = 'statement')
|
|
200
|
+
// context: 'statement' | 'value'
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Example - Comprehensions:**
|
|
204
|
+
```coffeescript
|
|
205
|
+
# Value context (result used) → IIFE
|
|
206
|
+
result = (x * 2 for x in arr)
|
|
207
|
+
|
|
208
|
+
# Statement context (result discarded) → Plain loop
|
|
209
|
+
for x in arr
|
|
210
|
+
x * 2
|
|
211
|
+
doMore() # ← comprehension not last, result unused
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Read:** `docs/COMPREHENSIONS.md` for complete rules
|
|
215
|
+
|
|
216
|
+
### 2. Block Unwrapping
|
|
217
|
+
|
|
218
|
+
Parser wraps statements in `["block", ...]` everywhere:
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
if (Array.isArray(body) && body[0] === 'block') {
|
|
222
|
+
const statements = body.slice(1); // ALWAYS unwrap!
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 3. String Object Metadata
|
|
227
|
+
|
|
228
|
+
Lexer attaches metadata to String objects (not primitives):
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
// Check BEFORE converting to primitive
|
|
232
|
+
if (sexpr instanceof String) {
|
|
233
|
+
const metadata = sexpr.quote || sexpr.heregex || sexpr.await;
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 4. Variable Scoping
|
|
238
|
+
|
|
239
|
+
CoffeeScript-style function scoping:
|
|
240
|
+
|
|
241
|
+
```javascript
|
|
242
|
+
// Program level
|
|
243
|
+
let a, b, fn;
|
|
244
|
+
|
|
245
|
+
// Function level - only NEW variables
|
|
246
|
+
fn = function() {
|
|
247
|
+
let x, y; // New vars
|
|
248
|
+
a = 1; // Uses outer 'a' (closure)
|
|
249
|
+
};
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Implementation:**
|
|
253
|
+
- `collectProgramVariables()` - Top-level
|
|
254
|
+
- `collectFunctionVariables()` - Function-local (excludes outer)
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## 🐛 Debugging Tips
|
|
259
|
+
|
|
260
|
+
### When Tests Fail
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
# 1. Run the specific test
|
|
264
|
+
bun test/runner.js test/rip/FILE.rip
|
|
265
|
+
|
|
266
|
+
# 2. Check generated code
|
|
267
|
+
echo 'test code' | ./bin/rip -c
|
|
268
|
+
|
|
269
|
+
# 3. Check s-expression
|
|
270
|
+
echo 'test code' | ./bin/rip -s
|
|
271
|
+
|
|
272
|
+
# 4. If Bun is caching old code
|
|
273
|
+
bun --no-cache test/runner.js test/rip
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### When Code Won't Compile
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# New improved error messages show line/column!
|
|
280
|
+
./bin/rip -c file.rip
|
|
281
|
+
# → Parse error at line 157, column 27 (token: ...)
|
|
282
|
+
|
|
283
|
+
# Check tokens
|
|
284
|
+
./bin/rip -t file.rip | grep -A 5 -B 5 "problem"
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### When Generated Code Looks Wrong
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Compare with CoffeeScript
|
|
291
|
+
coffee -c file.coffee # CoffeeScript output
|
|
292
|
+
./bin/rip -c file.coffee # Rip output
|
|
293
|
+
# Compare the two
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## 📋 GitHub Workflow
|
|
299
|
+
|
|
300
|
+
**Follow the 10-step workflow in `docs/WORKFLOW.md`**
|
|
301
|
+
|
|
302
|
+
### Quick Version
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
# 1-2. Find bug, create issue
|
|
306
|
+
gh issue create --title "..." --label "bug"
|
|
307
|
+
|
|
308
|
+
# 3. Create branch
|
|
309
|
+
git checkout -b fix/issue-name
|
|
310
|
+
|
|
311
|
+
# 4-6. Write tests, implement, verify
|
|
312
|
+
bun run test # Must pass!
|
|
313
|
+
|
|
314
|
+
# 7. Build browser (if code changed)
|
|
315
|
+
bun run browser
|
|
316
|
+
|
|
317
|
+
# 8-9. Commit with issue reference
|
|
318
|
+
git commit -m "Fix: ...
|
|
319
|
+
|
|
320
|
+
Fixes #N ← Auto-closes issue!
|
|
321
|
+
|
|
322
|
+
All tests passing: X/Y (100%)"
|
|
323
|
+
|
|
324
|
+
# 10. PR and merge
|
|
325
|
+
git push origin fix/issue-name
|
|
326
|
+
gh pr create --title "..." --body "Fixes #N"
|
|
327
|
+
gh pr merge <number> --squash --delete-branch
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**The magic:** `Fixes #N` in commit/PR auto-closes the issue when merged!
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
## ⚠️ Critical Don'ts
|
|
335
|
+
|
|
336
|
+
### Never Edit These Files Directly
|
|
337
|
+
|
|
338
|
+
- ❌ `src/parser.js` - Generated file
|
|
339
|
+
- ❌ `src/grammar/solar.rip` - Given (parser generator)
|
|
340
|
+
|
|
341
|
+
### Always Do These
|
|
342
|
+
|
|
343
|
+
- ✅ Run `bun run test` before committing
|
|
344
|
+
- ✅ Run `bun run browser` after codegen changes
|
|
345
|
+
- ✅ Include `Fixes #N` in commits
|
|
346
|
+
- ✅ Update test counts in README.md
|
|
347
|
+
- ✅ Follow existing code patterns
|
|
348
|
+
|
|
349
|
+
---
|
|
350
|
+
|
|
351
|
+
## 🎯 Current Project Status
|
|
352
|
+
|
|
353
|
+
**Version:** 1.0.0
|
|
354
|
+
**Tests:** 854/854 passing (100%)
|
|
355
|
+
**Status:** Production-ready, actively maintained
|
|
356
|
+
|
|
357
|
+
**Recent Achievements:**
|
|
358
|
+
- ✅ Postfix comprehensions with `by` step (Issue #1)
|
|
359
|
+
- ✅ Parser error locations (Issue #7)
|
|
360
|
+
- ✅ Range loops without variable (Issue #9)
|
|
361
|
+
- ✅ bar.coffee compiles successfully
|
|
362
|
+
- ✅ 48% smaller output than CoffeeScript
|
|
363
|
+
|
|
364
|
+
**Open Issues:**
|
|
365
|
+
- Issue #11: Nested comprehension IIFEs (in progress, see ISSUE-11.md)
|
|
366
|
+
|
|
367
|
+
**Active Branches:**
|
|
368
|
+
- `fix/nested-comprehension-context` - Issue #11 work
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## 📚 Documentation Map
|
|
373
|
+
|
|
374
|
+
**For Developers:**
|
|
375
|
+
- `AGENT.md` - Complete reference (read this first!)
|
|
376
|
+
- `CONTRIBUTING.md` - Workflow with examples
|
|
377
|
+
- `docs/WORKFLOW.md` - Quick command reference
|
|
378
|
+
- `ISSUE-*.md` - Complex issue handoffs
|
|
379
|
+
|
|
380
|
+
**Technical Reference:**
|
|
381
|
+
- `docs/CODEGEN.md` - All 110+ node types
|
|
382
|
+
- `docs/COMPREHENSIONS.md` - Context rules (CRITICAL for Issue #11!)
|
|
383
|
+
- `docs/SOLAR.md` - Parser generator guide
|
|
384
|
+
- `docs/STRING.md` - String metadata
|
|
385
|
+
- `docs/REGEX-PLUS.md` - Ruby-style regex
|
|
386
|
+
|
|
387
|
+
**User Docs:**
|
|
388
|
+
- `README.md` - User guide with examples
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## 🎨 Code Style Principles
|
|
393
|
+
|
|
394
|
+
From today's session:
|
|
395
|
+
|
|
396
|
+
1. **Keep it clean** - No ugly hacks, readable code
|
|
397
|
+
2. **Keep it simple** - S-expressions over complex AST
|
|
398
|
+
3. **Keep it tested** - 100% test coverage
|
|
399
|
+
4. **Keep it efficient** - Optimize hot paths
|
|
400
|
+
5. **Keep it documented** - Update docs with changes
|
|
401
|
+
|
|
402
|
+
**Example of clean code:**
|
|
403
|
+
```javascript
|
|
404
|
+
// ✅ Good - clear, simple
|
|
405
|
+
case '+': {
|
|
406
|
+
const [left, right] = rest;
|
|
407
|
+
return `(${this.generate(left, 'value')} + ${this.generate(right, 'value')})`;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ❌ Bad - overly complex
|
|
411
|
+
case '+': return this.buildBinaryExpression(rest[0], rest[1], '+', {precedence: 5});
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
---
|
|
415
|
+
|
|
416
|
+
## 🏆 Session History
|
|
417
|
+
|
|
418
|
+
**Today (2025-10-31):** Completed 5 full GitHub workflows
|
|
419
|
+
- Issue #1/PR #2: Postfix `by` step support
|
|
420
|
+
- Issue #3/PR #4: Refactor step handling
|
|
421
|
+
- Issue #5/PR #6: Comprehension context fix
|
|
422
|
+
- Issue #7+#9/PR #10: Parser errors + range loops
|
|
423
|
+
- Issue #11: Analysis complete, implementation pending
|
|
424
|
+
|
|
425
|
+
**All issues auto-closed via `Fixes #N` in PR descriptions!**
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## 💡 Pro Tips
|
|
430
|
+
|
|
431
|
+
### Understand Before Changing
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
# Don't guess - inspect!
|
|
435
|
+
echo 'code' | ./bin/rip -s # See what parser emits
|
|
436
|
+
grep -A 30 "case 'pattern':" src/codegen.js # See current implementation
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Use Existing Patterns
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
# Find similar cases
|
|
443
|
+
grep -r "similar pattern" src/codegen.js
|
|
444
|
+
# Copy and adapt, don't reinvent
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Test Edge Cases
|
|
448
|
+
|
|
449
|
+
```coffeescript
|
|
450
|
+
# Don't just test the happy path
|
|
451
|
+
test "normal", "x = 1", 1
|
|
452
|
+
test "with null", "x = null", null
|
|
453
|
+
test "with undefined", "x = undefined", undefined
|
|
454
|
+
test "empty array", "x = []", []
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### Commit Often
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
# Small, focused commits are better
|
|
461
|
+
git commit -m "Add grammar rule for X"
|
|
462
|
+
git commit -m "Add codegen for X"
|
|
463
|
+
git commit -m "Add tests for X"
|
|
464
|
+
# vs one huge commit
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## 🔍 Finding Your Way Around
|
|
470
|
+
|
|
471
|
+
### Where to Look for Specific Things
|
|
472
|
+
|
|
473
|
+
**Syntax/Grammar Issues:**
|
|
474
|
+
- Check: `src/grammar/grammar.rip`
|
|
475
|
+
- Regenerate: `bun run parser`
|
|
476
|
+
|
|
477
|
+
**Code Generation Issues:**
|
|
478
|
+
- Check: `src/codegen.js`
|
|
479
|
+
- Search: `grep "case 'node-type':" src/codegen.js`
|
|
480
|
+
|
|
481
|
+
**Parser Runtime Issues:**
|
|
482
|
+
- Check: `src/grammar/solar.rip`
|
|
483
|
+
- Functions: `parseError`, `parse`
|
|
484
|
+
- Regenerate: `bun run parser`
|
|
485
|
+
|
|
486
|
+
**Test Failures:**
|
|
487
|
+
- Check: `test/rip/CATEGORY.rip`
|
|
488
|
+
- Categories: assignment, async, comprehensions, functions, loops, etc.
|
|
489
|
+
|
|
490
|
+
**Context Rules:**
|
|
491
|
+
- Read: `docs/COMPREHENSIONS.md`
|
|
492
|
+
- This is CRITICAL for understanding statement vs value context
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## 🚨 Common Pitfalls (Avoid These!)
|
|
497
|
+
|
|
498
|
+
### ❌ Editing Generated Files
|
|
499
|
+
```bash
|
|
500
|
+
vim src/parser.js # WRONG - will be overwritten!
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### ✅ Edit Source, Then Regenerate
|
|
504
|
+
```bash
|
|
505
|
+
vim src/grammar/grammar.rip # RIGHT
|
|
506
|
+
bun run parser # Regenerate parser.js
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### ❌ Forgetting to Test
|
|
510
|
+
```bash
|
|
511
|
+
git commit -m "fix bug" # WRONG - didn't run tests!
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### ✅ Always Test First
|
|
515
|
+
```bash
|
|
516
|
+
bun run test # MUST be 854/854 passing
|
|
517
|
+
git commit
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### ❌ Missing Issue Reference
|
|
521
|
+
```bash
|
|
522
|
+
git commit -m "Fix comprehension bug" # WRONG - issue won't auto-close!
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
### ✅ Always Reference Issue
|
|
526
|
+
```bash
|
|
527
|
+
git commit -m "Fix: Description
|
|
528
|
+
|
|
529
|
+
Fixes #11 # RIGHT - auto-closes issue!
|
|
530
|
+
"
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
### ❌ Breaking Existing Tests
|
|
534
|
+
```bash
|
|
535
|
+
# Made change, 1 test fails
|
|
536
|
+
git commit anyway # WRONG!
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
### ✅ Keep 100% Pass Rate
|
|
540
|
+
```bash
|
|
541
|
+
bun run test # Must be 854/854 passing
|
|
542
|
+
# If tests fail, fix them or revert your change
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
---
|
|
546
|
+
|
|
547
|
+
## 🎓 Understanding Rip's Design
|
|
548
|
+
|
|
549
|
+
### Why S-Expressions?
|
|
550
|
+
|
|
551
|
+
**Traditional AST:**
|
|
552
|
+
```javascript
|
|
553
|
+
class BinaryOp {
|
|
554
|
+
constructor(op, left, right) { ... }
|
|
555
|
+
compile() { /* 50+ lines */ }
|
|
556
|
+
}
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
**Rip's S-Expressions:**
|
|
560
|
+
```javascript
|
|
561
|
+
case '+': {
|
|
562
|
+
const [left, right] = rest;
|
|
563
|
+
return `(${this.generate(left)} + ${this.generate(right)})`;
|
|
564
|
+
}
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
**Result:** 50% less code, easier to maintain!
|
|
568
|
+
|
|
569
|
+
### Why Context Parameter?
|
|
570
|
+
|
|
571
|
+
**Same syntax, different output:**
|
|
572
|
+
```coffeescript
|
|
573
|
+
# Source (identical)
|
|
574
|
+
for x in arr then x * 2
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
**Output depends on usage:**
|
|
578
|
+
```javascript
|
|
579
|
+
// Used: result = (for x in arr then x * 2)
|
|
580
|
+
(() => {
|
|
581
|
+
const result = [];
|
|
582
|
+
for (const x of arr) { result.push(x * 2); }
|
|
583
|
+
return result;
|
|
584
|
+
})()
|
|
585
|
+
|
|
586
|
+
// Unused: (for x in arr then x * 2); doMore()
|
|
587
|
+
for (const x of arr) { (x * 2); }
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
Context-aware generation = smarter, more efficient code!
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
## 📖 Extended Reading
|
|
595
|
+
|
|
596
|
+
**When you need deep knowledge:**
|
|
597
|
+
|
|
598
|
+
### For Comprehension Work (Issue #11)
|
|
599
|
+
1. `docs/COMPREHENSIONS.md` - Complete context rules
|
|
600
|
+
2. `ISSUE-11.md` - Nested IIFE problem analysis
|
|
601
|
+
3. `test/rip/comprehensions.rip` - All test cases
|
|
602
|
+
4. `src/codegen.js:2025-2230` - Comprehension IIFE generation
|
|
603
|
+
5. `src/codegen.js:4080-4250` - Plain loop generation
|
|
604
|
+
|
|
605
|
+
### For Grammar Work
|
|
606
|
+
1. `docs/SOLAR.md` - Parser generator guide
|
|
607
|
+
2. `src/grammar/grammar.rip` - Grammar specification
|
|
608
|
+
3. `src/grammar/solar.rip` - Parser generator source
|
|
609
|
+
|
|
610
|
+
### For General Development
|
|
611
|
+
1. `docs/CODEGEN.md` - All 110+ node types
|
|
612
|
+
2. `docs/STRING.md` - String metadata
|
|
613
|
+
3. `docs/REGEX-PLUS.md` - Ruby-style regex
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## 🎯 Your First Task
|
|
618
|
+
|
|
619
|
+
**Start here:**
|
|
620
|
+
|
|
621
|
+
1. ✅ Read AGENT.md (you're ready after this!)
|
|
622
|
+
2. ✅ Run `bun run test` (verify everything passes)
|
|
623
|
+
3. ✅ Check `gh issue list` (see what's open)
|
|
624
|
+
4. ✅ If Issue #11 exists, read `ISSUE-11.md`
|
|
625
|
+
5. ✅ Create branch: `git checkout fix/nested-comprehension-context`
|
|
626
|
+
6. ✅ Implement Solution B from ISSUE-11.md
|
|
627
|
+
7. ✅ Follow the workflow in `docs/WORKFLOW.md`
|
|
628
|
+
|
|
629
|
+
---
|
|
630
|
+
|
|
631
|
+
## 🌟 Success Criteria
|
|
632
|
+
|
|
633
|
+
**Before committing:**
|
|
634
|
+
- ✅ All tests pass (854/854 or higher)
|
|
635
|
+
- ✅ Code follows existing patterns
|
|
636
|
+
- ✅ Documentation updated
|
|
637
|
+
- ✅ Browser bundle rebuilt (if codegen changed)
|
|
638
|
+
- ✅ Commit message references issue
|
|
639
|
+
|
|
640
|
+
**Before merging PR:**
|
|
641
|
+
- ✅ PR description includes `Fixes #N`
|
|
642
|
+
- ✅ All checklist items complete
|
|
643
|
+
- ✅ Clean, readable code
|
|
644
|
+
- ✅ No regressions
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
## 💬 Getting Help
|
|
649
|
+
|
|
650
|
+
**Resources available:**
|
|
651
|
+
1. Read the docs (comprehensive!)
|
|
652
|
+
2. Check closed PRs (#2, #4, #6, #10) for examples
|
|
653
|
+
3. Review test files for patterns
|
|
654
|
+
4. Use debug flags extensively
|
|
655
|
+
|
|
656
|
+
**The docs are excellent** - trust them! Everything you need is documented.
|
|
657
|
+
|
|
658
|
+
---
|
|
659
|
+
|
|
660
|
+
## 🚀 Philosophy
|
|
661
|
+
|
|
662
|
+
**From AGENT.md:**
|
|
663
|
+
|
|
664
|
+
> Simplicity scales.
|
|
665
|
+
> - Keep the IR simple (s-expressions)
|
|
666
|
+
> - Keep the pipeline clear (lex → parse → generate)
|
|
667
|
+
> - Keep the code minimal (pattern matching)
|
|
668
|
+
> - Test everything (854/854 tests passing)
|
|
669
|
+
|
|
670
|
+
**From today's session:**
|
|
671
|
+
|
|
672
|
+
> Follow the workflow.
|
|
673
|
+
> Write tests first.
|
|
674
|
+
> Keep it clean.
|
|
675
|
+
> Document everything.
|
|
676
|
+
|
|
677
|
+
---
|
|
678
|
+
|
|
679
|
+
**You have everything you need. The codebase is well-tested, well-documented, and ready for you. Trust the process, follow the patterns, and keep those tests passing!** ✨
|
|
680
|
+
|
|
681
|
+
**Good luck!** 🎉
|