gura

Gura Configuration Language for Nim

Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version 0.1.1
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:26

Authors

  • Ward

Installation

nimble install gura
choosenim install gura
git clone https://github.com/khchen/gura

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
gura - - - - - - -

Dependencies

Package Version Optional
npeg >= 1.2.2 No

Source

Repository https://github.com/khchen/gura
Homepage https://github.com/khchen/gura
Registry Source nimble_official

README

Donate

Gura Configuration Language for Nim

Gura is a file format for configuration files. Gura is as flexible as YAML and simple and readable like TOML. Its syntax is clear and powerful, yet familiar for YAML/TOML users (from https://github.com/gura-conf/gura).

To learn more about Gura, you can read the Official Gura Documentation.

This Gura implementation in Nim emphasizes code that is easy to write and read (NPeg is used in both lexing and parsing), rather than optimizing for execution speed.

Examples

import gura, json, strutils

const guraString = """
  # This is a comment in a Gura configuration file.
  # Define a variable named `title` with string value "Gura Example"
  title: "Gura Example"

  # Define an object with fields `username` and `age`
  # with string and integer values, respectively
  # Indentation is used to indicate nesting
  person:
    username: "Stephen"
    age: 20

  # Define a list of values
  # Line breaks are OK when inside arrays
  hosts: [
    "alpha",
    "omega"
  ]

  # Variables can be defined and referenced to avoid repetition
  $foreground: "#FFAH84"
  color_scheme:
    editor: $foreground
    ui:     $foreground

""".unindent(2)

# Transforms to json node
let node = fromGura(guraString)

# Access a specific field
echo "Title -> ", node["title"]
echo "My username is ", node["person"]["username"]
for host in node["hosts"]:
  echo "Host -> ", host

Usage

  proc fromGura(input: string): JsonNode
    ## Transforms a Gura string into a JsonNode.

  proc fromGuraFile(path: string): JsonNode
    ## Transforms a Gura file into a JsonNode.

  proc toGura(node: JsonNode; indent: Positive = 4): string
    ## Transforms a JsonNode into Gura string.

  proc toGuraFile(node: JsonNode; path: string; indent: Positive = 4)
    ## Transforms a JsonNode into Gura file.

Differences from the original Gura

  • Indentation can use spaces in multiples of 2 (originally required multiples of 4).

  • The use of Tab (\t) is not allowed in syntax; it should be replaced with spaces.

  • Apart from control characters \x00..\x1f and characters used in syntax, such as (' ', ':', '$', '[', ']', ',', '"', ''', '#'), any other ASCII or UTF-8 characters can be used as key names or variable names.

  • Commas separating items in an array are optional regardless of their placement (both [1 2 3] and [1, 2, 3,] are acceptable). However, a comma after an object always indicates the end of the object definition.

  • Strings (basic, literal, multi-line, etc.) from any Gura can be used for importing.

  • Imports always use the current file location as the current directory (similar to Nim import).

License

Copyright (c) Chen Kai-Hung, Ward. All rights reserved.

Donate

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal