0.2.0
S-Expression Parser, Serializer, and Tree Constructor / Walker Utilities for JavaScript in Browsers and Node.js
Zero-dependencies. Tree structure as plain JSON. Ideal for custom data transfer format and making DSLs.
Class of S-Expression resolver that includes parser, serializer, tree constructors, and tree walker utilities.
Creates an instance of SExpr. Optional options
input for configuring default behavior, such as how to recognize null, boolean values as it's up to the programmer to decide the syntax. Nevertheless, here is the default that you can override.
{
truthy: ['true', '#t'],
falsy: ['false', '#f'],
nully: ['null', '#nil']
}
(any
= {}
)
Public field for programmers to store arbitrary data that might be useful for parsing expressions
Serialize an expression tree into an S-expression string
(any)
any
:
Check if a node is an identifier, optionally compare to a given name
(any)
a node to check
(string
= undefined
)
optional id name to compare to
boolean
:
true if it is an identifier
const S = new SExpr()
const node = S.expression(S.identifier('a'))
console.log(S.isIdentifier(S.first(node)))
// true
console.log(S.isIdentifier(S.first(node, 'a')))
// true
Get a value content of a symbol (not expression).
(any)
a node to extract value
any
:
value
Get the first child of a node.
(any)
a node to get its child
any
:
a child node if exists
Get the second child of a node.
(any)
a node to get its child
any
:
a child node if exists
Get the third child of a node.
(any)
a node to get its child
any
:
a child node if exists