Code Monkey home page Code Monkey logo

cl-yaml's Introduction

cl-yaml

Build Status Coverage Status Quicklisp

A YAML parser and emitter built on top of libyaml. Uses the cl-libyaml library.

Usage

The yaml package exports three functions:

  • (parse string-or-pathname): Parses a string or a pathname into Lisp values.
  • (emit value stream): Emit a Lisp value into a stream.
  • (emit-to-string value): Emit a Lisp value into a string.

Parsing

CL-USER> (yaml:parse "[1, 2, 3]")
(1 2 3)

CL-USER> (yaml:parse "{ a: 1, b: 2 }")
{"a" => 1, "b" => 2}

CL-USER> (yaml:parse "- Mercury
- Venus
- Earth
- Mars")
("Mercury" "Venus" "Earth" "Mars")

CL-USER> (yaml:parse "foo
---
bar" :multi-document-p t)
(:DOCUMENTS "foo" "bar")

Emitting

CL-USER> (yaml:emit-to-string (list 1 2 3))
"[1, 2, 3]"

CL-USER> (yaml:emit-to-string
           (alexandria:alist-hash-table '(("a" . 1)
                                          ("b" . 2))))
"{ b: 2, a: 1 }"

CL-USER> (yaml:emit (list t 123 3.14) *standard-output*)
[true, 123, 3.14]

Documentation

Type Mapping

cl-yaml uses YAML's Core Schema to map YAML values to Lisp types an vice versa. A table showing the correspondence of values and types is shown below:

YAML type Lisp type
Null nil
Boolean t and nil
Integer Integer
Float Double float
String String
List List
Map Hash table
Document (:document ...)

IEEE Floating Point Support

Common Lisp doesn't natively support the IEEE special floating point values: NaN (Not a number), positive infinity and negative infinity are unrepresentable in portable Common Lisp. Since YAML allows documents to include these values, we have to figure out what to do with them. cl-yaml supports multiple float strategies.

The default strategy is :keyword, which uses keywords to represent these values. The strategy can be customized by setting the value of yaml.float:*float-strategy* to one of the following keywords:

  1. :error: The simplest approach, simply signal the condition yaml.error:unsupported-float-value whenever a NaN or infinity value is encountered.

  2. :keyword: Use keywords to represent the different values, i.e.: :NaN for NaN, :+Inf for positive infinity and :-Inf for negative infinity.

  3. :best-effort: Use implementation-specific values whenever possible, fall back on :keyword in unsupported implementations. On SBCL and Allegro Common Lisp, NaN and infinity can be represented.

License

Copyright (c) 2013-2015 Fernando Borretti

Licensed under the MIT License.

cl-yaml's People

Contributors

arademaker avatar euandreh avatar eudoxia0 avatar jasonmelbye avatar

Watchers

 avatar  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.