massage the numbers,

This commit is contained in:
Rowan 2025-05-25 08:33:35 -05:00
parent daf07441de
commit 3e79f237eb

View file

@ -46,18 +46,23 @@ export const many = curry((parser, state) => {
export const many1 = parser => seq(parser, many(parser))
const _range = (start, end, step = 1) => {
const len = end - start + 1
const _range = (start, end, step = 1, deny = []) => {
const len = end - start - deny.length + 1
const result = new Array(len)
for (let i = 0, n = start; i <= len; i += i, n += step) {
if (deny.includes(n)) { continue }
result[i] = n
}
return result
}
export const range = (start, end) => {
return anyChar(_range(start.codePointAt(0), end.codePointAt(0)))
const code = s => s.codePointAt(0)
export const range = (start, end, deny = []) => {
return anyChar(
_range(code(start), code(end), deny.map(code)).map(String.fromCodePoint)
)
}