From 0a80f6d13d7b31e610d4bfa28098c736d0cafc38 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 8 Oct 2025 17:30:30 -0700 Subject: [PATCH] works better --- .gitattributes | 2 - .gitignore | 2 + CLAUDE.md | 306 +++++++++++++++----- README.md | 32 +- build.ts | 149 ---------- bun-env.d.ts | 17 -- src/parser/example.shrimp => example.shrimp | 0 package.json | 3 +- src/bin/shrimp | 35 --- src/compiler/treeHelper.ts | 31 -- src/editor/editor.css | 57 ++++ src/editor/editor.tsx | 100 ++++--- src/editor/plugins/debugTags.ts | 13 +- src/editor/plugins/keymap.ts | 28 -- src/editor/plugins/keymap.tsx | 89 ++++++ src/editor/plugins/persistence.ts | 29 ++ src/editor/plugins/theme.tsx | 1 - src/parser/contextTracker.ts | 26 -- src/parser/{highlight.js => highlight.ts} | 0 src/parser/parser.test.ts | 8 +- src/parser/shrimp.grammar | 10 +- src/parser/shrimp.ts | 6 +- src/parser/{tokenizers.ts => tokenizer.ts} | 0 src/server/index.css | 31 -- src/testSetup.ts | 2 +- tsconfig.json | 1 - 26 files changed, 514 insertions(+), 464 deletions(-) delete mode 100644 .gitattributes delete mode 100644 build.ts delete mode 100644 bun-env.d.ts rename src/parser/example.shrimp => example.shrimp (100%) delete mode 100755 src/bin/shrimp delete mode 100644 src/compiler/treeHelper.ts create mode 100644 src/editor/editor.css delete mode 100644 src/editor/plugins/keymap.ts create mode 100644 src/editor/plugins/keymap.tsx create mode 100644 src/editor/plugins/persistence.ts delete mode 100644 src/parser/contextTracker.ts rename src/parser/{highlight.js => highlight.ts} (100%) rename src/parser/{tokenizers.ts => tokenizer.ts} (100%) diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.gitignore b/.gitignore index a14702c..2486e5a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # Finder (MacOS) folder config .DS_Store + +/tmp \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index b5a267e..a9564d0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,107 +1,261 @@ -I am using the lezer grammar [System Guide](https://lezer.codemirror.net/docs/guide/) [api](https://lezer.codemirror.net/docs/ref/). +# CLAUDE.md -Default to using Bun instead of Node.js. +This file provides guidance to Claude Code (claude.ai/code) when working with the Shrimp programming language. -- Use `bun ` instead of `node ` or `ts-node ` -- Use `bun test` instead of `jest` or `vitest` -- Use `bun build ` instead of `webpack` or `esbuild` -- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install` -- Use `bun run - - +### Common Grammar Gotchas + +**EOF infinite loops**: Using `@eof` in repeating patterns can match EOF multiple times. Current approach uses explicit statement/newline alternatives. + +**Token precedence**: Use `@precedence` to resolve conflicts between similar tokens. + +**External tokenizers**: Custom logic in `tokenizers.ts` handles complex cases like identifier vs word distinction. + +**Empty line parsing**: The grammar structure `(statement | newlineOrSemicolon)+ eof?` allows proper empty line and EOF handling. + +## Testing Strategy + +### Parser Tests (`src/parser/parser.test.ts`) + +- **Token types**: Identifier vs Word distinction +- **Function calls**: With and without arguments +- **Expressions**: Binary operations, parentheses, precedence +- **Functions**: Single-line and multiline definitions +- **Whitespace**: Empty lines, mixed delimiters +- **Edge cases**: Ambiguous parsing, incomplete input + +Test structure: + +```typescript +describe('feature area', () => { + test('specific case', () => { + expect(input).toMatchTree(expectedCST) + }) +}) ``` -With the following `frontend.tsx`: +When adding language features: -```tsx#frontend.tsx -import React from "react"; +1. Write grammar tests first showing expected CST structure +2. Update grammar rules to make tests pass +3. Add integration tests showing real usage +4. Test edge cases and error conditions -// import .css files directly and it works -import './index.css'; +## Bun Usage -import { createRoot } from "react-dom/client"; +Default to Bun over Node.js/npm: -const root = createRoot(document.body); +- Use `bun ` instead of `node ` or `ts-node ` +- Use `bun test` instead of `jest` or `vitest` +- Use `bun install` instead of `npm install` +- Use `bun run