forked from antoniodgonzalez/md5mesh-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparserUtils.ts
22 lines (16 loc) · 927 Bytes
/
parserUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export const str = "\"(.*?)\"";
export const num = "(-?\\d+\\.?\\d*)";
export const parseInt10 = (x: string) => parseInt(x, 10);
export const fromPattern = (pattern: string, options?: string) =>
new RegExp(pattern.replace(/\ /g, "\\s*"), options);
const getSectionRegExp = (name: string) =>
new RegExp(`${name}\\s*{([\\s\\S]*?)}`, "g");
export const getSections = (name: string) => (md5meshSource: string): string[] =>
md5meshSource.match(getSectionRegExp(name)) || [];
export const getSection = (name: string) => (md5meshSource: string): string =>
getSections(name)(md5meshSource)[0];
export const getParsedLines = (regExp: RegExp) => (input: string): RegExpMatchArray[] => {
const tryParseLine = (line: string) => line.match(regExp);
const lineHasParsed = (x: RegExpMatchArray | null) => x !== null;
return input.split("\n").map(tryParseLine).filter(lineHasParsed) as RegExpMatchArray[];
};