Code Monkey home page Code Monkey logo

roundtrip_ini's Introduction

roundtrip_ini

PkgGoDev

Decode, structural edit (replace, insert, delete) and encode the INI file format, preserving comments and blank lines.

Humans care about comments and blank lines and are confused when comments disappear or lines change place for no reason.

Module roundtrip_ini is useful when you need to do round trip editing and

  • the diff is meant to be presented to a human for review.
  • the output is meant to be read or written again by a human.

At the same time, roundtrip_ini acts also as a formatter / pretty-printer, introducing uniformity. Like gofmt, the formatting is not tunable.

Status

Unstable, in development, version 0.x, the API will very likely change in a breaking way.

Conformity and completeness

The INI file is an informal format and reaching conformity or completeness is not a goal of this project.

Usage and examples

The idea is to have two packages:

  • Package roundtrip_ini performs high-level decoding, editing and encoding of the INI format, preserving comments and blank lines.
  • Package ast performs low-level decoding, editing and encoding of the INI format, preserving comments and blank lines.

One would normally use package roundtrip_ini, reserving package ast to special cases, but currently only package ast is implemented.

  • See the examples in ast/example_test.go.
  • See the tests.
  • See the godoc-ast API documentation for package ast, which has also the runnable examples.

Formatting

  • Spurious leading newlines are removed.
  • A trailing newline is added if missing.
  • Leading and trailing whitespace is removed from section names: [ hello ] becomes [hello].
  • Properties are written as foo = 42 (one space around the equal sign).

See TestRoundTripCornerCases and TestRoundTripPrettyPrint for details.

Comments and blank lines

Comments and blank lines are preserved as follows.

  • A comment is just above a section title or above a property. A comment can be multi-line.
  • Blank lines are just below a section title or below a property.

See the tests for details.

Contributing

Please, before working on a PR, open an issue to discuss your use case.

This helps to better understand the pros and cons of a change and not to waste your time (and mine) developing a feature that for some reason doesn't fit well with the spirit of the project or could be implemented differently.

This is in the spirit of minimalism and talk, then code.

Credits

Thanks to participle, a parser and lexer generator.

License

This code is released under the MIT license, see file LICENSE.

roundtrip_ini's People

Contributors

marco-m avatar

Watchers

 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.