prettier-plugin-monkey
v0.11.1
Published
Prettier plugin for Monkey programming language
Maintainers
Readme
prettier-plugin-monkey
A Prettier plugin for the Monkey programming language.
Features
- 🚀 Fast parsing using WebAssembly (powered by @gengjiawen/monkey-wasm)
- 🎨 Automatic code formatting
- 🔧 Configurable formatting options
- 📦 Easy integration with existing Prettier setups
Installation
npm install --save-dev prettier prettier-plugin-monkey
# or
yarn add -D prettier prettier-plugin-monkey
# or
pnpm add -D prettier prettier-plugin-monkeyUsage
With Prettier CLI
prettier --write "**/*.monkey"With .prettierrc
{
"plugins": ["prettier-plugin-monkey"],
"printWidth": 80,
"tabWidth": 2
}Programmatic API
import prettier from 'prettier';
const code = `
let add = fn(a, b) {
a + b
};
`;
const formatted = await prettier.format(code, {
parser: 'monkey',
plugins: ['prettier-plugin-monkey'],
});
console.log(formatted);Supported File Extensions
.monkey
Configuration Options
This plugin supports all standard Prettier options:
printWidth(default: 80)tabWidth(default: 2)useTabs(default: false)trailingComma(default: "none")bracketSpacing(default: true)
Notes:
- Monkey strings currently use double quotes only, so
singleQuoteis intentionally ignored.
Examples
Before
let fibonacci=fn(x){if(x==0){0}else{if(x==1){return 1;}else{fibonacci(x-1)+fibonacci(x-2);}}};After
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};Development
# Install dependencies
npm install
# Build the plugin
npm run build
# Run tests
npm test
# Watch mode for development
npm run devContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Related Projects
- monkey-rust - Monkey interpreter in Rust
- @gengjiawen/monkey-wasm - Monkey parser WASM package
- Writing An Interpreter In Go - The original Monkey language book
