Repository navigation
Support /\p{General_Category=Letter}/gu? #74
Unanswered
crapthings
asked this question in
Q&A
Replies: 4 comments
|
Maybe. See #15 for the precursor to this discussion. |
0 replies
|
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:
|
0 replies
|
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 ] |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
will this support
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Unicode_Property_Escapes#general_categories
All reactions