elzup/peeler

How to ignore brackets inside different quotes?

Closed this issue ยท 4 comments

Something like this
( text [] ) ( text "[{ignored brackets)){" and 'other ignored}}((' text)

Thanks for the great library!

elzup commented

thank you
I think quots, quotechar option is useful. I'd like to add one in the near future.

We also recommend the following alternatives if you need custom parser rules.
https://github.com/zaach/jison

jison is too big, complex and has too many dependencies.
In my case, I only need quotes except that peeler can itself)

P.S. It would be nice to be able to use not only the same quotes, but also brackets for blocks of this type
( text [] ) ( text { everything here is parsed as text like inside quotes((( ( ] ] ) } text)

elzup commented

released v1.4.0

doc: https://github.com/elzup/peeler#quotes-option
test: https://github.com/elzup/peeler/blob/main/src/__test__/index.test.ts#L56

> peeler(`( text [] ) ( text "[{ignored brackets)){" and 'other ignored}}((' text) { ) }`, { quotes: [`"`, `'`, `{}`]})
[
  {
    nodeType: 'bracket',
    open: '(',
    close: ')',
    nodes: [ [Object], [Object], [Object] ],
    pos: { start: 0, depth: 0, end: 10 },
    content: '( text [] )',
    innerContent: ' text [] '
  },
  {
    nodeType: 'text',
    pos: { start: 11, end: 12, depth: 0 },
    content: ' '
  },
  {
    nodeType: 'bracket',
    open: '(',
    close: ')',
    nodes: [ 
      {
        nodeType: 'text',
        pos: { start: 13, end: 71, depth: 1 },
        content: ` text "[{ignored brackets)){" and 'other ignored}}((' text`
      }
    ],
    pos: { start: 12, depth: 0, end: 71 },
    content: `( text "[{ignored brackets)){" and 'other ignored}}((' text)`,
    innerContent: ` text "[{ignored brackets)){" and 'other ignored}}((' text`
  },
  {
    nodeType: 'text',
    pos: { start: 72, end: 78, depth: 0 },
    content: ' { ) }'
  }
]

released v1.4.0

Fantastic!
Exactly what I need.

Thank's again ๐Ÿ™๐Ÿป