No description
Find a file
Soyaine ae3f469075
Merge pull request #30 from Cirru/fix-symbol
fix special case of symbol
2021-03-18 11:26:53 +08:00
.github/workflows change version requirement in tests 2020-12-08 22:58:58 +08:00
src fix special case of symbol; bump 0.4.10 2021-03-17 23:15:10 +08:00
tests fix special case of symbol; bump 0.4.10 2021-03-17 23:15:10 +08:00
.gitignore upgrade parser for performance; bump 0.3.1 2020-10-10 18:09:43 +08:00
cirru_edn.nimble fix special case of symbol; bump 0.4.10 2021-03-17 23:15:10 +08:00
README.md fix special case of symbol; bump 0.4.10 2021-03-17 23:15:10 +08:00

Cirru EDN in Nim

Load Cirru EDN in Nim.

Usage

requires "cirru_edn >= 0.4.10"
import cirru_edn

parseCirruEdn("do 1") # gets 1
parseCirruEdn("[] 1 2 3")

let x = genCrEdnList(genCrEdn(1))

echo $x # stringify

type detection:

import cirru_edn

let x = parseCirruEdn("do 1") # gets 1

case x.kind:
of crEdnNil: # ...
of crEdnBool: # ...
of crEdnNumber: # ...
of crEdnKeyword: # ...
of crEdnString: # ...
of crEdnSymbol: # ...
of crEdnVector: # ...
of crEdnList: # ...
of crEdnMap: # ...
of crEdnRecord: # ...

formatToCirru(x) # returns string
formatToCirru(x, true) # turn on useInline option

Functions for generating data:

genCrEdn()
genCrEdn(true)
genCrEdn(1)
genCrEdn("a")
genCrEdnKeyword("k")
genCrEdnSymbol("s")
genCrEdnList(genCrEdn(1), genCrEdn(1))
genCrEdnVector(genCrEdn(1), genCrEdn(1))
genCrEdnSet(genCrEdn(1), genCrEdn(2))
genCrEdnMap(genCrEdnKeyword("a"), genCrEdn(2)) # even number of arguments
genCrEdnRecord("Demo", genCrEdn("a"), genCrEdn(2)) # odd number of arguments, string keys

Syntax

Cirru EDN is based on Cirru Text Syntax, on top of that is some syntax for EDN:

  • Lists and vectors:
[] 1 2 3
list 1 2 3
  • HashMaps:
{}
  :a 1
  :b 3
  • Record:

Record name and record fields are represented in symbols:

%{} Demo
  a 1
  b 2
  • Sets:
#{} 1 2 3
  • Literals, since Cirru use lines for expressions, need do for extracting a top value:
do 1
do :k
do nil
do 'sym
  • Strings, needs to be prefixed with a |(or a single escaped "):
do |short
do "|long text"
{}
  :code $ quote
    def a (x y) (+ x y)

License

MIT