Skip to content

Code (or Text) formatter inspired from grammar in syntax highlighter

License

Notifications You must be signed in to change notification settings

DrSensor/universal-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Universal Formatter

An experimental code/text formatter that utilize Rosie Pattern Language

still just an idea

Usage

Given this json5.rpl and json5.yml

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) ","?
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

$ echo '{"a":123,"b":null}' | ufmt --grammar json5.yml --enable null_first,no_comma
{
  "b": null
  "a": 123
}

Inspiration

About

Code (or Text) formatter inspired from grammar in syntax highlighter

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published