A single-file Jevko library for Lua. Inspired by rxi/json.lua.
Encodes and decodes plain Jevko.
- Simple
- Lightweight: ~3 KiB, < 100 SLOC
- Error messages with
line:columninformation, e.g.Invalid digraph (`x) at 1:10!
Copy the jevko.lua file into your project and require it:
jevko = require "jevko"You can now use the following functions:
Aliases: jevko.decode, jevko.fromString.
Turns a string into a Jevko parse tree, e.g.:
jevko.from_string([=[
id [10]
colors [
[red]
[yellow]
[blue]
]
]=])returns
{
subjevkos = {
{prefix = "id ", jevko = {subjevkos = {}, suffix = "10"}},
{prefix = "\ncolors ", jevko = {
subjevkos = {
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "red"}},
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "yellow"}},
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "blue"}},
},
suffix = "\n"
}},
},
suffix = "\n"
}Aliases: jevko.encode, jevko.toString.
Inverse of jevko.from_string.
Serializes a Jevko parse tree into a string, e.g.:
jevko.to_string({
subjevkos = {
{prefix = "id ", jevko = {subjevkos = {}, suffix = "10"}},
{prefix = "\ncolors ", jevko = {
subjevkos = {
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "red"}},
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "yellow"}},
{prefix = "\n ", jevko = {subjevkos = {}, suffix = "blue"}},
},
suffix = "\n"
}},
},
suffix = "\n"
})returns the string
id [10]
colors [
[red]
[yellow]
[blue]
]
A helper function which can be used with custom Jevko encoders.
Turns a string into a Jevko-safe string by escaping special characters, e.g.:
jevko.escape("Only these three are special: ` [ ]")returns the string
Only these three are special: `` `[ `]
easyjevko.lua -- a library for Easy Jevko, a simple format built on Jevko.