TOML parser for Wren. Parses TOML v0.5.0
Supports the TOML v0.5.0 specification.
The following features of TOML are not yet supported:
- Binary Notation
- Dotted Keys
- Literal Strings
- Local Date-Time
- Local Date
- Local Time
- Octal Notation
- Offset Date-Time
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
// 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)
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)
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 totrue
.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 to2
.
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)
- 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.
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 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
We have good experience using these editors:
- Atom with the Wren language package
We use SemVer for versioning. For the versions available, see the releases on this repository.
- David Newman - Initial development and ongoing maintenance - datatypevoid
See also the list of contributors who participated in this project.
This project is licensed under the ISC License - see the LICENSE file for details