https://github.com/tgrassl/sweet-syntax
Add syntactic sugar to any language!
https://github.com/tgrassl/sweet-syntax
arnold code-style custom-syntax emoji markdown sugar sweet syntax
Last synced: 2 months ago
JSON representation
Add syntactic sugar to any language!
- Host: GitHub
- URL: https://github.com/tgrassl/sweet-syntax
- Owner: tgrassl
- License: mit
- Created: 2019-10-29T20:54:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-07T21:58:25.000Z (about 6 years ago)
- Last Synced: 2025-10-28T06:03:44.731Z (5 months ago)
- Topics: arnold, code-style, custom-syntax, emoji, markdown, sugar, sweet, syntax
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://www.npmjs.com/package/sweet-syntax)
[](https://packagephobia.now.sh/result?p=sweet-syntax)
Add syntactic sugar to any language!
## Install
Install `sweet-syntax` globally using npm:
```bash
npm install sweet-syntax -g
```
## Usage
Once the installation is done, you can run the command inside your project's directory with your input and output file.
```bash
sweet-syntax input.myts output.ts
```
By default `sweet-syntax` will search the root of the current directory for a `sweet-syntax.json` file that contains your syntax configuration.
If the config file is located somewhere else, use the `--config` or `-c` argument with its path.
```bash
sweet-syntax input.myjs output.js -c configs/sweet-syntax.json
```
Finally, run this command to see a list of all available options:
```bash
sweet-syntax --help
```
### As a loadable module
You can also use `sweet-syntax` as a module in your code.
First install it locally using npm:
```bash
npm install --save sweet-syntax
```
Then `require` and use it in your code:
```javascript
const sweetSyntax = require('sweet-syntax');
const config = {
objects: {
HELLO: 'console.log'
},
keywords: {
END: ';'
}
}
const input = 'HELLO("Hello World")END';
const output = sweetSyntax.sweeten(config, input);
console.log(output);
// Output:
// console.log("Hello World");
```
## Config
The config file should be named `sweet-syntax.json` and adopt the following structure:
```
{
"keywords": {
"LOOP": "for",
"CHECK": "if",
...
},
"objects": {
"LOG": "console.log",
...
},
"operators": {
"EQL": "===",
"NQL": "!==",
...
},
"characters": {
"{{": "",
"}}": "",
...
}
}
```
At least one object e.g. keywords must be provided by the config.
## Examples
You can see examples of custom syntactic sugar under the examples folder:
* [Emoji Markdown](https://github.com/tgrassl/sweet-syntax/tree/master/examples/emojiMarkdown)
* [ArnoldJS](https://github.com/tgrassl/sweet-syntax/tree/master/examples/arnoldJS)
## License
Code released under the [MIT License](https://github.com/tgrassl/sweet-syntax/blob/master/LICENSE).
Enjoy ⭐️