Skip to content

datatypevoid/wren-toml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wren-toml

TOML parser for Wren. Parses TOML v0.5.0

Features

Supports the TOML v0.5.0 specification.

The following features of TOML are not yet supported:

Getting Started

The source files should be dropped into an existing project and the top module imported:

import "./relative/path/to/wren-toml/module" for TOML

Additionally, the dependencies listed in the package.toml file should be cloned/downloaded and dropped in a directory named wren_modules (create it if it doesn't exist).

The wren-test dependency is only needed if you intend on running the tests.

Alternatively, if utilizing wrenpm for package management in your project, you can add wren-toml to your package.toml file and install wren-toml from within your project root directory with:

$ wrenpm install

Usage

Tokenize and Parse

// Import module.
import "./relative/path/to/wren-toml/module" for TOML

// Load TOML input.
var input = . . .

System.print("Creating TOML instance...")

var toml = TOML.new()

System.print("Tokenizing...")

var tokens = toml.tokenize(input)

System.print("...tokenizing complete... token count: %(tokens.count).")

System.print("Parsing...")

var output = toml.parse(tokens, input)

System.print("Printing output...")

System.print(output)

You can also tokenize and parse in one call:

// Load TOML input.
var input = . . .

System.print("Creating TOML instance...")

var toml = TOML.new()

System.print("Parsing...")

var output = toml.parse(input)

System.print("Printing output...")

System.print(output)

Stringify

var input = {
  "products": [{
    "name": "Hammer",
    "sku": 738594937
  }, {
    "name": "Plank",
    "sku": 637984168,
    "variety": [{
      "type": "birch"
    }, {
      "type": "maple"
    }]
  }, {
    "name": "Nail",
    "color": "gray",
    "sku": 284758393
  }]
}

System.print("Creating TOML instance...")

var toml = TOML.new()

System.print("Stringifying...")

var output = toml.stringify(input)

System.print("Printing output...")

System.print(output)

Options

The stringify method accepts an optional Map which may contain any of the following configuration options:

  • appendTrailingNewLine {Bool} - Appends a trailing new line character to the stringified output. Defaults to true.
  • tabChar {String} - Character sequence to use when generating tabs. Defaults to a single space.
  • tabDepth {Num} - How many tab character sequences should be used per tab. Defaults to 2.
var input = { . . . }

System.print("Creating TOML instance...")

var toml = TOML.new()

System.print("Stringifying...")

var output = toml.stringify(input, {
  "appendTrailingNewLine": false,
  "tabChar": "\t",
  "tabDepth": 1
})

System.print("Printing output...")

System.print(output)

Dependencies

  • wren - The best way to get wren up and running on your machine is to build from source. You can find more details here.
  • git - Get git from here.

Testing

Test scripts utilize the wren-test framework and are stored in the tests/ directory. You can launch the tests with:

$ wren ./tests/module.wren

Note that you must have the wren-test framework installed for the tests to run. The fastest way to do this is to build wrenpm and do:

# from within the root directory of this project:
$ wrenpm install

Examples

Examples live in the examples/ directory. You can run an example with:

# `file` is the filename of the example you'd like to run.
$ wren ./examples/file.wren

Wren

Use a Wren-aware editor

We have good experience using these editors:

Versioning

We use SemVer for versioning. For the versions available, see the releases on this repository.

Authors

  • David Newman - Initial development and ongoing maintenance - datatypevoid

See also the list of contributors who participated in this project.

License

This project is licensed under the ISC License - see the LICENSE file for details

Acknowledgments

  • Thanks to Bob and friends for giving us Wren.
  • Hat tip to anyone whose code was used.

About

TOML parser for Wren. Parses TOML v0.5.0

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published