Support /\p{General_Category=Letter}/gu? #74
Replies: 4 comments
-
Maybe. See #15 for the precursor to this discussion. |
Beta Was this translation helpful? Give feedback.
-
I was thinking about this some more, and I bet we could do something cool with unicode-trie. It wouldn't be quite as fast as something the JS engine provides, but it's the basic approach that ICU uses in most JS engines. The idea would be:
|
Beta Was this translation helpful? Give feedback.
-
For reference, this works, but I don't know how fast it is: const peggy = require('peggy')
const {parse} = peggy.generate(`
{{
const props = require('unicode-properties')
function toInt(str) {
return [...str].reduce((t, v) => (t * 10) + props.getNumericValue(v.codePointAt(0)), 0)
}
}}
Numbers = head:Number tail:(" " @Number)* { return [head].concat(tail) }
Number = num:$Nd+ { return toInt(num) }
Nd
= [0-9]
/ d:[^\u0000-\u065f] &{ return props.isDigit(d.codePointAt(0)) }
`)
console.log(parse('123١6 ੨੫੯')) // [ 12316, 259 ] |
Beta Was this translation helpful? Give feedback.
-
More discussion in #375 |
Beta Was this translation helpful? Give feedback.
-
will this support
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes#general_categories
Beta Was this translation helpful? Give feedback.
All reactions