Skip to content

Commit

Permalink
Update to support TOML v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vmfhrmfoaj committed Mar 6, 2022
1 parent 927a577 commit 4ce084e
Show file tree
Hide file tree
Showing 7 changed files with 1,506 additions and 427 deletions.
73 changes: 42 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
# clj-toml

clj-toml is [TOML](https://github.com/vmfhrmfoaj/clj-toml) for Clojure. TOML is Tom's Obvious, Minimal Language.
`clj-toml` is [TOML](https://toml.io) for Clojure.
TOML is Tom's Obvious, Minimal Language.

> TOML is like INI, only better (Tom Preston-Werner)
clj-toml uses [Instaparse](https://github.com/Engelberg/instaparse) for parsing.
`clj-toml` uses [Instaparse](https://github.com/Engelberg/instaparse) for parsing.
Instaparse does all the heavy lifting, we're just sitting pretty.
Currently clj-toml support TOML [v1.0.0](https://toml.io/en/v1.0.0).
`clj-toml` support TOML [v1.0.0](https://toml.io/en/v1.0.0).


## Usage

Work is underway towards a TOML 0.4.0-compliant release. Use the 0.3.1 release (TOML 0.1.0-compliant) in the meantime:

Leiningen:
```clojure
[clj-toml "1.0.0"]
```

Test:
```clojure
lein test
```

Use:
```clojure
(use 'clj-toml.core)

(parse-toml "
title = \"TOML\"
[Foo]
bar=[1,2,3]")
;; {"title" "TOML" "foo" {"bar" [1 2 3]}}

(meta (parse-toml "
title = \"TOML\"
[Foo]
bar=[1,2,3]"))
;; {...}
```
Currently `clj-toml` v1.0.0 has not been released yet.
You can install `clj-toml` locally by using `lein install` command.

```clojure
#_user> (use 'clj-toml.core)
;;=> nil

#_user> (def example "
title = \"TOML\"\n
[Foo]\n
bar=[1,2,3]")

#_user> (parse-toml example)
;;=> {"title" "TOML", "Foo" {"bar" [1 2 3]}}

#_user> (meta (parse-toml example))
;;=> {"title" #:clj-toml.core{:start 1, :end 15},
;; "Foo" {:clj-toml.core/start 17,
;; :clj-toml.core/end 22,
;; "bar" #:clj-toml.core{:start 24, :end 35}}}

#_user> (subs example 1 15)
;;=> "title = \"TOML\""

#_user> (subs example 17 22)
;;=> "[Foo]"
```


### Version

```
x.x.x-z.z < patch number
^^^^^
TOML version
```


## License

Expand Down
244 changes: 0 additions & 244 deletions dev-resources/example-v0.4.0.toml

This file was deleted.

26 changes: 5 additions & 21 deletions dev-resources/example.toml
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
# 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?
dob = 1979-05-27T07:32:00-08:00 # First class dates

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

[servers]

# You can indent as you please. Tabs or spaces. TOML don't care.
# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"

[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
country = "中国" # This should be parsed as UTF-8

[clients]
data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers support it
data = [ ["gamma", "delta"], [1, 2] ]

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

# Products

[[products]]
name = "Hammer"
sku = 738594937

[[products]]
name = "Nail"
sku = 284758393
color = "gray"
]
Loading

0 comments on commit 4ce084e

Please sign in to comment.