Git Product home page Git Product logo

clop's Introduction

CLOP - Common Lisp tOml Parser

Overview

Tom’s Obvious Minimal Language (TOML) is a human friendly configuration file format. This library implements a parser (decoder) for it.

Clop strictly follows TOML 1.0 specification and is fully compatible with it. It passes all 296 tests defined in BurntSushi/toml-test.

Installation

Once it gets into Quicklisp, you can load it by:

;; Load it.
(ql:quickload "clop")

;; Run some basic tests.
(asdf:test-system "clop")

If you want to run comprehensive tests, you need to first clone toml-test and set it up locally.

Use the following command to test it:

cd /path/to/clop/roswell
ros build decoder.ros

/path/to/toml-test/toml-test ./decoder

You should now see a line of:

toml-test [/path/to/clop/roswell/decoder]: using embedded tests: 296 passed,  0 failed

Usage

Functions

The main entry point of Clop is parse function.

  (defparameter +toml-text+ "
[server]
port = 5000
print-access-log = false
")
  
  (clop:parse +toml-text+)
  ; => (("server" ("port" . 5000) ("print-access-log")))

This function takes an optional keyword argument style that controls the output style:

  • :alist. The default. TOML tables are transformed to alists.
  • :jsown. TOML tables are transformed to jsown style (:obj "key" "value").
  • :raw. TOML tables are transformed to Clop internal representations, i.e. classes table, table-array and inline-table.

Configurations

The behavior of Clop can be tuned by settings configuration variables. Wrap them in a let lexical context or change their values globally to make it work.

VariableDefault ValueMeaning
value-+inf:+INFThe value of +inf
value–inf:-INFThe value of -inf
value-+nan:+NANThe value of +nan
value–nan:-NANThe value of -nan
value-trueTThe value of boolean true
value-falseNILThe value of boolean false

Extending Clop

Clop implementation has 2 concepts: value parser and block parser.

  • Value parser is used for handling basic values, i.e. string, integer, float, bool, datetime, datetime-local, date-local, time-local.
  • Block parser is used for handling TOML blocks, i.e. key-value-pair, table, inline-table and table-array.

Tuning Value Parser

For basic values, you may:

  1. Define your own value parser function that takes 2 arguments: type and value, and return the resulting value.
  2. Set clop.config:*value-parser* variable to your own function.

You may refer to roswell/decoder.ros for an example. toml-test requires values to be a JSON object like:

{
  "type": "integer",
  "value": 123
}

Code in roswell/decoder.ros tunes value parser to return such jsown object.

Tuning Block Parser

Instead of implementing your own block parser, you may pass a :raw style to clop:parse function and start from the return value. Check docstrings in src/toml-block-parser for more detail.

clop's People

Contributors

sheepduke avatar

Watchers

 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.