https://github.com/drsensor/universal-formatter
Code (or Text) formatter inspired from grammar in syntax highlighter
https://github.com/drsensor/universal-formatter
concept formatter grammar-rules ideas
Last synced: 6 months ago
JSON representation
Code (or Text) formatter inspired from grammar in syntax highlighter
- Host: GitHub
- URL: https://github.com/drsensor/universal-formatter
- Owner: DrSensor
- License: apache-2.0
- Created: 2019-10-14T06:49:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-06-19T00:58:24.000Z (about 5 years ago)
- Last Synced: 2025-03-10T19:57:18.111Z (over 1 year ago)
- Topics: concept, formatter, grammar-rules, ideas
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Universal Formatter
An **experimental** code/text formatter that utilize [Rosie Pattern Language](https://rosie-lang.org)
> still just an idea
### Usage
Given this _json5.rpl_ and _json5.yml_
```dhall
package json5
import word, num
local true = "true"
local false = "false"
local null = "null"
string = word.q
number = num.signed_number
key = word.any / string
primitive_value = string / number / true / false / null
member = key ":" primitive_value ","?
member_non_null = key ":" (string / number / true / false) ","?
```
```yml
version: '1'
grammar: [json5.rpl]
rules:
no_comma:
scope: json5.key ":" json5.primitive ","
remove: ","
null_first:
scope: "{" json5.memeber "}"
match_and_place:
at_start: "{"
at_end: "}"
patterns:
- place: json5.key ":" json5.null ","?
before: json5.member_non_null
- match_and_place:
before_end: json5.member_non_null
```
then execute
```console
$ echo '{"a":123,"b":null}' | ufmt --grammar json5.yml --enable null_first,no_comma
{
"b": null
"a": 123
}
```
## Inspiration
- https://github.com/trishume/syntect
- https://github.com/ul/kak-tree