Giter VIP home page Giter VIP logo

toml's Introduction

Maven Central

Toml

// TomlTable has all of the same methods has HashMap. (computeIfAbsent, put, etc)
TomlTable table = Toml.from(new StringReader("key = \"value\""));

Features:

  • TOML 0.5 compliant
  • Fast
  • Memory Efficient
  • Zero dependencies
  • Simple inheritance model

The main goals are simple:
Remain fast and lightweight.

This library has no runtime dependencies.
It uses JUnit for tests, and JFlex at compile-time.

Usage

The API should be easy enough to follow.

The classes that most people will care about are: Toml, TomlTable, and TomlArray.

Toml

You can use Toml to read a TomlTable from an InputStream or Reader.
You can also provide an existing TomlTable to read into, meaning, you can chain multiple toml inputs together.

TomlTable

Very simply, a HashMap. It supports dotted keys, but other than that, it's more or less exactly what you'd find in a normal HashMap.

You can call asMap to get the underlying Map implementation. Any modifications to this map will reflect in the TomlTable instance.

TomlArray

Simply an ArrayList. You can perform all of the same actions. You can call the asList method to get the underlying List implementation. Any modifications to this list will reflect in the TomlArray instance.

Values/Objects

The values you can retrieve from the collections are as follows:

  1. Boolean/boolean
  2. Double/double
  3. Long/long
  4. String
  5. TomlArray
  6. TomlTable
  7. TemporalAccessor

The only one of note is the TemporalAccessor.

Using it is as simple as:

OffsetDateTime.from((TemporalAccessor) table.get("timestamp"));
LocalDateTime.from((TemporalAccessor) table.get("timestamp"));
LocalDate.from((TemporalAccessor) table.get("timestamp"));
LocalTime.from((TemporalAccessor) table.get("timestamp"));

Inheritance

The Toml class provides access to the underlying infrastructure.

Inheritance is as simple as:

StringReader first = new StringReader("value = \"Hello, World!\"");
StringReader second = new StringReader("value = \"Bye Bye, World!\"");

TomlTable table = Toml.from(first, second);

The inheritance model isn't perfect.
There's a couple of pain points with it I'd like to address, but it's not critical.
For example, you can't delete keys or array entries.
To reduce surprises, it's best to think of it as one big input, because that's how it acts.

Language (Parser/Lexer)

I've exported the lang package.
That contains the parser and the lexer, should you wish to utilise them.

Have fun!

Extension Mode

There is also a nonstandard mode, should you wish to utilise some non-standardised features. You need to opt in by setting a System property. You'll find the property inside of Toml.

  • Relative Table Paths.

By prepending a dot, you can refer to the previous table. Taking a lot of the tedium out when writing big headers.

[[items]]
id = "0"

# Is the same as [items.metadata]
[.metadata]
special = "0-0"

toml's People

Contributors

jezza avatar

Watchers

James Cloos 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.