Skip to content

Commit 84a8a97

Browse files
committed
[js] Move preprocessed UCD data into a seperate npm module
Keep less generated stuff in the repo
1 parent 9bce90b commit 84a8a97

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

src/vm/js/nqp-runtime/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"stack-trace": "0.0.10",
3131
"unicharadata": "*",
3232
"unicode-collation-algorithm": "^0.0.2",
33-
"unicode-trie": "^0.3.1",
3433
"xorshift": "^1.1.0",
35-
"xregexp": "^3.2.0"
34+
"xregexp": "^3.2.0",
35+
"nqp-unicode-data": "^1.1.0"
3636
}
3737
}
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/vm/js/nqp-runtime/unicode-data/names.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/vm/js/nqp-runtime/unicode-props.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const xregexp = require('xregexp');
22

3-
const names = require('./unicode-data/names.js');
3+
const ucd = require('nqp-unicode-data');
4+
45
const core = require('./core.js');
56

67
//TODO - the regexes should be tweaked to match full graphemes instead
@@ -10,19 +11,14 @@ function mangled(name) {
1011
return name.toLowerCase(name).replace(/_/g, '');
1112
}
1213

13-
const propIdToNames = {};
14-
for (const propName in names.props) {
15-
const propId = names.props[propName];
16-
if (!propIdToNames[propId]) propIdToNames[propId] = propIdToNames[propId] || [];
17-
propIdToNames[propId].push(propName);
18-
}
1914

2015

2116
function addProp(propName, builder) {
22-
const propId = names.props[propName];
17+
const propId = ucd.propId(propName);
18+
2319
const match = builder(true);
2420
const do_not_match = builder(false);
25-
for (const alias of propIdToNames[propId]) {
21+
for (const alias of ucd.propIdToNames(propId)) {
2622
exports['uniprop_' + mangled(alias)] = match;
2723
exports['uniprop_not_' + mangled(alias)] = do_not_match;
2824
}
@@ -55,7 +51,7 @@ addExtraProp('ascii', match => matchClass(match, 'ASCII'));
5551
addExtraProp('any', match => matchClass(match, 'Any'));
5652

5753
function addPropValueProps(propName, builder, filter, extraMangle) {
58-
for (const propValue of names.propValues[names.props[propName]]) {
54+
for (const propValue of ucd.propValues(ucd.propId(propName))) {
5955
if (!filter(propValue[0])) continue;
6056
for (const alias of propValue) {
6157
const mangledAlias = mangled(extraMangle ? extraMangle(alias) : alias);
@@ -81,7 +77,7 @@ addPropValueProps('General_Category',
8177

8278
function categoriesToRegex(categories) {
8379
return categories ? categories.map(
84-
category => names.regexes[names.props[category]] || '\\p{' + category + '}'
80+
category => ucd.regex(ucd.propId(category)) || '\\p{' + category + '}'
8581
).join('|') : '';
8682
}
8783

@@ -103,16 +99,13 @@ const matchLC = match => matchDerived(match, ['Ll', 'Lu', 'Lt']);
10399
addExtraProp('LC', matchLC);
104100
addExtraProp('Cased_Letter', matchLC);
105101

106-
const UnicodeTrie = require('unicode-trie')
107-
const fs = require('fs')
108102

109103
const nativeArgs = require('./native-args.js');
110104
const NativeStrArg = nativeArgs.NativeStrArg;
111105

112-
const numericTypeData = new UnicodeTrie(fs.readFileSync(__dirname + '/unicode-data/NumericType.trie'));
113-
const bidiClassData = new UnicodeTrie(fs.readFileSync(__dirname + '/unicode-data/BidiClass.trie'));
114-
const numericValueData = new UnicodeTrie(fs.readFileSync(__dirname + '/unicode-data/NumericValue.trie'));
115-
106+
const numericTypeData = ucd.propTrie('NumericType');
107+
const bidiClassData = ucd.propTrie('BidiClass');
108+
const numericValueData = ucd.propTrie('NumericValue');
116109

117110
function delegateAccepts(shouldMatch, ctx, cursor, obj, code, value) {
118111
const result = cursor['!DELEGATE_ACCEPTS'](ctx, null, cursor, obj, new NativeStrArg(value)).$$getInt();
@@ -125,13 +118,13 @@ function delegateAccepts(shouldMatch, ctx, cursor, obj, code, value) {
125118
}
126119

127120
function propWithArgs(shouldMatch, trie, propName, longNames) {
128-
const propId = names.props[propName];
121+
const propId = ucd.propId(propName);
129122
return function(ctx, cursor, target, offset, obj) {
130123
const code = target.codePointAt(offset);
131124
if (code === undefined) return -1;
132125
const propValueId = trie.get(code);
133126

134-
let valueName = names.propValues[propId][propValueId-1][longNames ? 1 : 0];
127+
let valueName = ucd.propValues(propId)[propValueId-1][longNames ? 1 : 0];
135128

136129
return delegateAccepts(shouldMatch, ctx, cursor, obj, code, valueName);
137130
};
@@ -185,17 +178,17 @@ function matchRegex(shouldMatch, regexString) {
185178
};
186179
}
187180

188-
for (const propId in names.regexes) {
189-
const match = matchRegex(true, names.regexes[propId]);
190-
const negatedMatch = matchRegex(false, names.regexes[propId]);
191-
for (const propName of propIdToNames[propId]) {
181+
for (const propId of ucd.propIdsWithRegexes()) {
182+
const match = matchRegex(true, ucd.regex(propId));
183+
const negatedMatch = matchRegex(false, ucd.regex(propId));
184+
for (const propName of ucd.propIdToNames(propId)) {
192185
exports['uniprop_' + mangled(propName)] = match;
193186
exports['uniprop_not_' + mangled(propName)] = negatedMatch;
194187
}
195188
}
196189

197190

198-
const mathRegex = names.regexes[names.props.Other_Math] + '|\\p{Sm}';
191+
const mathRegex = ucd.regex(ucd.propId('Other_Math')) + '|\\p{Sm}';
199192
addProp('Math', match => matchRegex(match, mathRegex));
200193

201194
addExtraProp('Assigned', match => matchRegex(true, match ? '\\P{Cn}' : '\\p{Cn}'));

0 commit comments

Comments
 (0)