Git Product home page Git Product logo

emacs-toml's Introduction

emacs-toml

Main workflow

toml.el is a library for parsing TOML (Tom's Obvious, Minimal Language).

Example

Parse the example.toml as an example.

(toml:read-from-string "\
key1 = \"foo\"
key2 = \"bar\"
key3 = \"333\"")

;; => '(("key3" . "333") ("key2" . "bar") ("key1" . "foo"))
(toml:read-from-file "example.toml")

;; or

(toml:read-from-string "\
# This is a TOML document. Boom.

title = \"TOML Example\"

\[owner\]
name = \"Tom Preston-Werner\"
organization = \"GitHub\"
bio = \"GitHub Cofounder & CEO\\nLikes tater tots and beer.\"
dob = 1979-05-27T07:32:00Z # First class dates? Why not?

\[database\]
server = \"192.168.1.1\"
ports = \[ 8001, 8001, 8002 \]
connection_max = 5000
enabled = true

\[servers\]

  # You can indent as you please. Tabs or spaces. TOML don't care.
  \[servers.alpha\]
  ip = \"10.0.0.1\"
  dc = \"eqdc10\"

  \[servers.beta\]
  ip = \"10.0.0.2\"
  dc = \"eqdc10\"

\[clients\]
data = \[ \[\"gamma\", \"delta\"\], \[1, 2\] \]

# Line breaks are OK when inside arrays
hosts = \[
  \"alpha\",
  \"omega\"
\]")

;; =>  '(
;;        ("clients"
;;          ("hosts" "alpha" "omega")
;;          ("data" ("gamma" "delta") (1 2)))
;;        ("servers"
;;          ("beta" ("dc" . "eqdc10") ("ip" . "10.0.0.2"))
;;          ("alpha" ("dc" . "eqdc10") ("ip" . "10.0.0.1")))
;;        ("database"
;;          ("enabled" . t)
;;          ("connection_max" . 5000)
;;          ("ports" 8001 8001 8002)
;;          ("server" . "192.168.1.1"))
;;        ("owner"
;;          ("dob" 0 32 7 27 5 1979)
;;          ("bio" . "GitHub Cofounder & CEO\\nLikes tater tots and beer.")
;;          ("organization" . "GitHub")
;;          ("name" . "Tom Preston-Werner"))
;;        ("title" . "TOML Example"))

Spec

In emacs-toml, "key groups" and "key" key pattern are as follows:

  • key = [a-zA-Z][a-zA-Z0-9_]*
  • keygroup = [a-zA-Z][a-zA-Z0-9_\\.]*
    • The end doesn't end in the period.

Test

Use Cask.el. follow commands:

$ make test
cask exec emacs -Q --batch \
		--load toml.el \
		--load toml-test.el \
		-f ert-run-tests-batch-and-exit
Real cl-lib shadowed by compatibility cl-lib? (/Users/gongo/.emacs.d/elpa/cl-lib-0.3/cl-lib.elc)
Real cl-lib shadowed by compatibility cl-lib? (/Users/gongo/.emacs.d/elpa/cl-lib-0.3/cl-lib.elc)
Running 21 tests (2013-08-29 22:33:46+0900)
   passed   1/21  toml-test-error:parse
   passed   2/21  toml-test-error:read-boolean
   passed   3/21  toml-test-error:read-datetime
   passed   4/21  toml-test-error:read-escaped-char
   passed   5/21  toml-test-error:read-key
   passed   6/21  toml-test-error:read-keygroup
   passed   7/21  toml-test-error:read-numeric
   passed   8/21  toml-test-error:read-string
   passed   9/21  toml-test:make-hashes
Mark set
Mark set
Mark set
Mark set
Mark set
   passed  10/21  toml-test:parse
   passed  11/21  toml-test:read-char
   passed  12/21  toml-test:read-char-with-char-p
   passed  13/21  toml-test:read-datetime
   passed  14/21  toml-test:read-escaped-char
   passed  15/21  toml-test:read-key
   passed  16/21  toml-test:read-keygroup
   passed  17/21  toml-test:read-numeric
   passed  18/21  toml-test:read-string
   passed  19/21  toml-test:seek-beginning-of-next-line
   passed  20/21  toml-test:seek-non-whitespace
   passed  21/21  toml-test:seek-readable-point

Ran 21 tests, 21 results as expected (2013-08-29 22:33:46+0900)

License

MIT License. see toml.el.

emacs-toml's People

Contributors

gongo avatar johannes-mueller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

emacs-toml's Issues

Tag current version

The current version in Melpa stable is 0.1.0 โ€“ really outdated. Can you please tag the current state with say 0.1.1 so that it can be referenced properly?

Merging PR5 and PR6

Is there anything that blocks the merge of #5 and #6? I am developing an emacs package that depends on these fixes.

Thanks

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.