Skip to content

Commit 8961c62

Browse files
jonraclaude
andcommitted
Initial release: mathprog-editor v0.1.0
CodeMirror 6 extension library for MathProg/GMPL code editing with: - Lezer grammar with full MathProg syntax support - Syntax highlighting with 10 color themes (5 light + 5 dark) - Live math rendering panel (MathProg → LaTeX → KaTeX) - Rainbow brackets, scope highlighting, mismatch detection - Linting with human-friendly error messages - Autocomplete for keywords and built-in functions - ESM/CJS/UMD distribution bundles - Interactive demo page with theme switcher - GitHub Actions CI and publish workflows Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0 parents  commit 8961c62

34 files changed

Lines changed: 5600 additions & 0 deletions

.github/workflows/ci.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
node-version: [18, 20, 22]
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: npm
27+
28+
- run: npm ci
29+
- run: npm run grammar
30+
- run: npm run build
31+
- run: npm test
32+
33+
- name: Check bundle size
34+
run: |
35+
echo "ESM bundle: $(wc -c < dist/index.esm.js) bytes"
36+
echo "CJS bundle: $(wc -c < dist/index.cjs.js) bytes"
37+
echo "UMD bundle: $(wc -c < dist/index.umd.js) bytes"
38+
39+
publish-dry-run:
40+
runs-on: ubuntu-latest
41+
needs: build
42+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: actions/setup-node@v4
46+
with:
47+
node-version: 20
48+
cache: npm
49+
- run: npm ci
50+
- run: npm run grammar
51+
- run: npm run build
52+
- run: npm pack --dry-run

.github/workflows/publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
id-token: write
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: 20
20+
registry-url: https://registry.npmjs.org
21+
cache: npm
22+
23+
- run: npm ci
24+
- run: npm run grammar
25+
- run: npm run build
26+
- run: npm test
27+
28+
- run: npm publish --provenance --access public
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules/
2+
dist/
3+
demo/demo.bundle.js
4+
demo/demo.bundle.js.map
5+
src/language/mathprog.grammar.js
6+
src/language/mathprog.grammar.terms.js
7+
*.tsbuildinfo
8+
.DS_Store

.npmignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Source and dev files
2+
.github/
3+
demo/
4+
test/
5+
.claude/
6+
*.grammar
7+
rollup.config.mjs
8+
tsconfig.json
9+
10+
# Generated source maps for dev
11+
src/language/*.js
12+
13+
# IDE and OS files
14+
.vscode/
15+
.idea/
16+
*.swp
17+
*.swo
18+
.DS_Store
19+
Thumbs.db

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2026-03-03
9+
10+
### Added
11+
12+
- Full Lezer grammar for MathProg/GMPL syntax
13+
- Set, param, var declarations
14+
- Objectives (minimize/maximize)
15+
- Constraints with `s.t.` / `subject to`
16+
- Indexing expressions, aggregates (sum, prod, min, max)
17+
- Arithmetic, comparison, logical, set operations
18+
- Built-in functions (abs, sqrt, log, etc.)
19+
- Comments (line `#` and block `/* */`)
20+
- Data section, solve, display, printf, for
21+
- Syntax highlighting with CodeMirror 6
22+
- Light theme (GitHub-inspired)
23+
- Dark theme (GitHub Dark-inspired)
24+
- Rainbow bracket coloring (6 cycling colors by depth)
25+
- Scope highlighting (background highlight between matching brackets)
26+
- Bracket mismatch detection (red underline on unmatched brackets)
27+
- Live math rendering panel
28+
- MathProg to LaTeX conversion
29+
- KaTeX rendering with error fallback
30+
- Synchronized scrolling
31+
- Click-to-jump from math to source
32+
- Linting with human-friendly error messages
33+
- Autocomplete for keywords and built-in functions
34+
- Convenience `mathProgEditor()` setup function
35+
- Interactive demo page with battery optimization sample model
36+
- ESM, CJS, and UMD distribution bundles

CONTRIBUTING.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Contributing to mathprog-editor
2+
3+
Thank you for your interest in contributing to mathprog-editor! This guide will help you get started.
4+
5+
## Development Setup
6+
7+
1. **Clone the repository**
8+
```bash
9+
git clone https://github.com/jonra/MathProg.git
10+
cd mathprog-editor
11+
```
12+
13+
2. **Install dependencies**
14+
```bash
15+
npm install
16+
```
17+
18+
3. **Generate the parser**
19+
```bash
20+
npm run grammar
21+
```
22+
23+
4. **Build the project**
24+
```bash
25+
npm run build
26+
```
27+
28+
5. **Run tests**
29+
```bash
30+
npm test
31+
```
32+
33+
6. **Start the dev server**
34+
```bash
35+
npm run dev
36+
```
37+
Then open `demo/index.html` in your browser.
38+
39+
## Project Structure
40+
41+
- `src/language/` — Lezer grammar, tokenizer, syntax highlighting, autocomplete
42+
- `src/brackets/` — Rainbow brackets, scope highlighting, mismatch detection
43+
- `src/math-render/` — MathProg-to-LaTeX converter, KaTeX renderer, side panel
44+
- `src/lint/` — Error detection with human-friendly messages
45+
- `src/theme/` — Light and dark editor themes
46+
- `src/index.ts` — Main exports and convenience `mathProgEditor()` function
47+
- `demo/` — Interactive demo page
48+
- `test/` — Test suite
49+
50+
## How to Contribute
51+
52+
### Reporting Bugs
53+
54+
- Use the [GitHub issue tracker](../../issues)
55+
- Include the MathProg code that triggers the bug
56+
- Describe expected vs. actual behavior
57+
- Include browser/OS info if relevant
58+
59+
### Suggesting Features
60+
61+
- Open a discussion or issue describing the use case
62+
- Explain why existing features don't cover your need
63+
64+
### Submitting Pull Requests
65+
66+
1. Fork the repo and create a feature branch from `main`
67+
2. Write tests for new functionality
68+
3. Ensure all tests pass: `npm test`
69+
4. Ensure the build succeeds: `npm run build`
70+
5. Write clear commit messages
71+
6. Open a PR with a description of the changes
72+
73+
### Grammar Changes
74+
75+
The Lezer grammar (`src/language/mathprog.grammar`) is the foundation of the editor. Changes here affect everything downstream. When modifying the grammar:
76+
77+
1. Run `npm run grammar` to regenerate the parser
78+
2. Verify the grammar test suite passes
79+
3. Test with real MathProg/GMPL models in the demo page
80+
4. Check that highlighting, autocomplete, and linting still work
81+
82+
## Code Style
83+
84+
- TypeScript with strict mode
85+
- No unnecessary abstractions — keep it simple
86+
- Follow existing patterns in the codebase
87+
88+
## License
89+
90+
By contributing, you agree that your contributions will be licensed under the MIT License.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)