GithubHelp home page GithubHelp logo

drsensor / universal-formatter Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 9 KB

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

License: Apache License 2.0

formatter ideas concept grammar-rules

universal-formatter's Introduction

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

universal-formatter's People

Contributors

drsensor avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.