-
Notifications
You must be signed in to change notification settings - Fork 1
/
Object$entences.js
61 lines (61 loc) · 2.25 KB
/
Object$entences.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Object$tring } from './Object$tring.js';
export class Object$entences extends Object$tring {
s;
mapConfig;
constructor(s, mapConfig) {
super(s);
this.s = s;
this.mapConfig = mapConfig;
}
async parse() {
await super.parse();
const { mapConfig } = this;
let { strVal, objVal } = this;
if (objVal === undefined) {
objVal = {};
this.objVal = objVal;
}
if (strVal) {
const statements = strVal.split('.')
.map(s => s.trim())
.filter(s => !s.startsWith('//'))
.map(s => s.replace(reNormalize, ' '))
.filter(s => s !== '');
const { regExpExts } = mapConfig;
if (regExpExts !== undefined && !mapConfig.parsedRegExps) {
for (const key in regExpExts) {
const rhs = regExpExts[key];
for (const regExpExt of rhs) {
if (!(regExpExt.regExp instanceof RegExp)) {
regExpExt.regExp = new RegExp(regExpExt.regExp);
}
}
}
mapConfig.parsedRegExps = true;
}
for (const statement of statements) {
if (regExpExts !== undefined) {
let foundMatch = false;
const { tryParse } = await import('./lib/prs/tryParse.js');
for (const key in regExpExts) {
const rhs = regExpExts[key];
const test = await tryParse(statement, rhs);
if (test !== null) {
if (objVal[key] === undefined)
objVal[key] = [];
objVal[key].push(test);
foundMatch = true;
break;
}
}
if (foundMatch)
continue;
}
if (objVal.rawStatements === undefined)
objVal.rawStatements = [];
objVal.rawStatements.push(statement);
}
}
}
}
export const reNormalize = /\s+/g;