Skip to content

Commit

Permalink
fix: consistent option naming
Browse files Browse the repository at this point in the history
  • Loading branch information
NLKNguyen committed Apr 8, 2023
1 parent 188c701 commit 1dae009
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ npx tape ./tests/helpers.js | npx tap-spec

Piping to `tap-spec` is optional, but it makes the output easier to read.

<!--
# Publish
```shell
npm publish --access public
```
-->

# 🚀 Quick start

API documentation is embedded at the bottom for reference.
Expand Down Expand Up @@ -457,7 +465,7 @@ tree
#### Parameters

* `str` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** S-expression string
* `opts` **any** deserializing options (optional, default `{includedRootBrackets:true}`)
* `opts` **any** deserializing options (optional, default `{includedRootParentheses:true}`)

Returns **[json](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/JSON)** an expression tree in form of list that can include nested
lists similar to the structure of the input S-expression
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ class SExpr {
* tree
*
* @param {string} str S-expression string
* @param {*} [opts = { includedRootBrackets: true}] deserializing options
* @param {*} [opts = { includedRootParentheses: true}] deserializing options
* @returns {json} an expression tree in form of list that can include nested
* lists similar to the structure of the input S-expression
* @ref improved on: https://rosettacode.org/wiki/S-expressions#JavaScript
*/
parse(str, opts = { includedRootBrackets: true}) {
parse(str, opts = { includedRootParentheses: true}) {
// TODO: consider handle try/catch here to report error message
if (!opts.includedRootBrackets) {
if (!opts.includedRootParentheses) {
str = `(\n${str}\n)` // parsing logic requires 1 root expression
}
str = this.stripComments(str + "\n")
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "s-expression.js",
"version": "0.6.0",
"version": "0.6.1",
"description": "S-Expression Parser, Serializer, and Tree Constructor / Walker Utilities in JavaScript for Browsers and Node.js",
"main": "index.js",
"files": [
"index.js",
"LICENSE"
],
"scripts": {
"publish": "npm publish --access public",
"test": "tape ./tests/*.js | tap-spec",
"test-browser": "browserify ./tests/all.js | tap-closer | smokestack -b chrome | tap-spec",
"update-readme-api": "documentation readme index.js --section=API",
Expand Down
8 changes: 4 additions & 4 deletions tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const SExpr = require("../index")
test("parse method", function (t) {
const S = new SExpr()
t.plan(2)
t.deepEqual(S.parse("(1 2 3)", { includedRootBrackets: true }), [1, 2, 3])
t.deepEqual(S.parse('(a 1 "cd ef ( )")', { includedRootBrackets: true }), ["a", 1, '"cd ef ( )"'])
t.deepEqual(S.parse("(1 2 3)", { includedRootParentheses: true }), [1, 2, 3])
t.deepEqual(S.parse('(a 1 "cd ef ( )")', { includedRootParentheses: true }), ["a", 1, '"cd ef ( )"'])
})

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -35,7 +35,7 @@ test("serialize method", async function (t) {
)
`
let originalAst = S.parse(input, { includedRootBrackets: true })
let originalAst = S.parse(input, { includedRootParentheses: true })

// console.log(
// colorize(originalAst, {
Expand All @@ -46,7 +46,7 @@ test("serialize method", async function (t) {
let serialized = S.serialize(originalAst, { includingRootParentheses: true })
// console.log("serialized: " + serialized)

let recreatedAst = S.parse(serialized, { includedRootBrackets: true })
let recreatedAst = S.parse(serialized, { includedRootParentheses: true })
// console.log(recreatedAst)

t.deepEquals(originalAst, recreatedAst)
Expand Down
14 changes: 7 additions & 7 deletions tests/interpret.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test("interpret method", async function (t) {
{
note: "root list",
input: "(a b c)",
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand All @@ -27,7 +27,7 @@ test("interpret method", async function (t) {
},
{
input: "((a b c))",
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand Down Expand Up @@ -60,7 +60,7 @@ test("interpret method", async function (t) {
// },
{
input: "((a b c) (d e f))",
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand Down Expand Up @@ -88,7 +88,7 @@ test("interpret method", async function (t) {
},
{
input: "(a (b c d) e (f) () (g h))",
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand Down Expand Up @@ -124,7 +124,7 @@ test("interpret method", async function (t) {
{
note: "multiline string",
input: '(a "multi\n line\n string")',
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand All @@ -137,7 +137,7 @@ test("interpret method", async function (t) {
{
note: "multiline string with escaped quotes",
input: `(a "multi\n line\n string \\"with \nquotes\\"")`,
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
[S.ROOT]: [
{
Expand Down Expand Up @@ -166,7 +166,7 @@ test("interpret method", async function (t) {
)
)
)`,
parsingOpts: { includedRootBrackets: true },
parsingOpts: { includedRootParentheses: true },
expect: {
"[ ROOT ]": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ test("parse method", function (t) {
{
input: `( 1 "a \\"b\\" c" true null d (e f ()) )`,
expect: [1, '"a "b" c"', "true", "null", "d", ["e", "f", []]],
opts: { includedRootBrackets: true }
opts: { includedRootParentheses: true }
},
]
t.plan(testCases.length)
Expand Down

0 comments on commit 1dae009

Please sign in to comment.