s-expression parser for javascript
JavaScript
Switch branches/tags
Nothing to show
Latest commit ad69f1e Aug 16, 2015 @hadashiA update version number
Permalink
Failed to load latest commit information.
lib ((1))が[1]になってしまうバグ修正 Nov 24, 2012
test v0.0.4 Nov 24, 2012
.gitignore initial commit Oct 20, 2012
.npmignore initial commit Oct 20, 2012
README.md README Nov 7, 2012
index.js generate() rename to stringify() Nov 7, 2012
package.json update version number Aug 16, 2015

README.md

Installation

npm install sexpression

Usage

var sexpression = require('sexpression');
sexpression.parse('()')
//=> null

sexpression.parse('(1 -2 3.45)')      
//=> [1, -2, 3.45]

sexpression.parse('(a b c)')          
//=> [{ name: 'a' }, { name: 'b' }, { name: 'c' }]

sexpression.parse('(a b (1 2) "a")')  
//=> [{ name: 'a' }, { name: 'b' }, [1, 2], 'a']

sexpression.parse('(:hoge 1 :fuga 2)')
//=> { hoge: 1, fuga: 2 }

sexpression.parse('(a b :hoge 1 :fuga 2 c)')
//=> [{ name: 'a' }, { name: 'b'}, { hoge: 1, fuga: 2 }, { name: c }]

sexpression.parse('(1 . 2)')
//=> { car: 1, cdr: 2 }

sexpression.parse('((hoge . 1) (fuga . 2))')
//=> [{ car: { name: 'hoge'}, cdr: 1}, { car: { name: 'fuga' }, cdr: 2 }]
sexpression.stringify([]);           
//=> 'nil'

sexpression.stringify([1, -2, 3.45]) 
//=> '(1 -2 3.45)'

sexpression.stringify([{ name: 'a' }, { name: 'b' }, [1, 2], 'a']) 
//=> '(a b (1 2) "a")'

sexpression.stringify({ car: 1, cdr: 2})  
//=> '(1 . 2)'

sexpression.stringify([{ car: { name: 'hoge'}, cdr: 1}, { car: { name: 'fuga' }, cdr: 2 }])  
//=> '((hoge . 1) (fuga . 2))'

sexpression.stringify({ a: 1, b: 2})                     
//=> '(:a 1 :b 2)'

sexpression.stringify([1, { hoge: 1, fuga: 2 }, "aaa"])  
//=> '(1 (:hoge 1 :fuga 2) "aaa")'

sexpression.stringify({ a: 1, b: 2}, 'alist') 
//=> '(("a" . 1) ("b" . 2))'

sexpression.stringify([1, { hoge: 1, fuga: 2 }, "aaa"], 'alist') 
//=> '(1 (('hoge' . 1) ('fuga' . 2)) 'aaa')'
sexpression.parse('hoge')  //=> { name: 'hoge' }
sexpression.parse('hoge') instanceof sexpression.Symbol  //=> true
sexpression.parse('hoge') === sexpression.parse('hoge')  //=> true