@markw65/prettier-plugin-monkeyc 1.0.0 → 1.0.3
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/README.md +100 -0
- package/build/prettier-plugin-monkeyc.cjs +1 -1
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @markw65/prettier-plugin-monkeyc
|
|
2
|
+
|
|
3
|
+
A prettier plugin for formatting monkey-c code.
|
|
4
|
+
|
|
5
|
+
## Intro
|
|
6
|
+
|
|
7
|
+
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.
|
|
8
|
+
|
|
9
|
+
This plugin adds support for the monkey-c language to Prettier.
|
|
10
|
+
|
|
11
|
+
### Input
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
dc.drawText(_width/2, 3,Graphics.FONT_TINY, "Ax = "+_accel[0], Graphics.TEXT_JUSTIFY_CENTER);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Output
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
dc.drawText(
|
|
21
|
+
_width / 2,
|
|
22
|
+
3,
|
|
23
|
+
Graphics.FONT_TINY,
|
|
24
|
+
"Ax = " + _accel[0],
|
|
25
|
+
Graphics.TEXT_JUSTIFY_CENTER
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install --save-dev @markw65/prettier-plugin-monkeyc
|
|
33
|
+
|
|
34
|
+
# or globally
|
|
35
|
+
|
|
36
|
+
npm install --global @markw65/prettier-plugin-monkeyc
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Use
|
|
40
|
+
|
|
41
|
+
### With VSCode
|
|
42
|
+
|
|
43
|
+
Install the Prettier extension from https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode.
|
|
44
|
+
|
|
45
|
+
- if you installed the plugin globally, you need to enable `prettier.resolveGlobalModules` in your settings.
|
|
46
|
+
- if you installed locally, [the documentation](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) says it should just work, but I've found you need to tell the extension how to find the local copy of prettier. Put `"prettier.prettierPath": "./node_modules/prettier"` in your `.vscode/settings.json`.
|
|
47
|
+
|
|
48
|
+
Once configured as above, VSCode's `Format Document` command (`Option-Shift-F`) will reformat your .mc files for you.
|
|
49
|
+
|
|
50
|
+
### With Node.js
|
|
51
|
+
|
|
52
|
+
If you installed prettier as a local dependency, you can run it via
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx prettier path/to/code.mc --write
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
If you installed globally, run
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
prettier path/to/code.mc --write
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Options
|
|
65
|
+
|
|
66
|
+
The standard Prettier options (such as `tabWidth`) can be used.
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
To make a production build, run
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
npm run build-release
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
To develop, run
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
npm run watch
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This will keep your build up to date as you make changes. You can then execute Prettier with
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
npx prettier [ --write ] --plugin build/prettier-plugin-monkeyc.cjs ...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Code structure
|
|
89
|
+
|
|
90
|
+
`@markw65/prettier-plugin-monkeyc` uses a Peggy grammar (located in `peg/`)
|
|
91
|
+
to parse monkeyc. This grammar was originally copied from the Peggy sample javascript grammar, and still has some javascript features that aren't relevant to monkeyc. I'm planning to clean that up, but for now it shouldn't matter.
|
|
92
|
+
|
|
93
|
+
`@markw65/prettier-plugin-monkeyc` is written in native ES6 javascript, but uses webpack to dynamically compile to commonjs, because thats what prettier wants.
|
|
94
|
+
|
|
95
|
+
The plugin is organized as follows:
|
|
96
|
+
|
|
97
|
+
- `prettier-plugin-monkeyc.js` This file exports the objects required of a Prettier plugin.
|
|
98
|
+
- `peg/monkeyc.peggy` The Peggy grammar for monkey-c.
|
|
99
|
+
- `src/printer.js` Printers take an AST and produce a Doc (the intermediate
|
|
100
|
+
format that Prettier uses). The current implementation is a thin wrapper around Prettier's default, estree printer. It handles just the nodes that it needs to, and delegates to "javascript-like" behavior for everything else.
|