|
1 | 1 | import { ParsingContext } from "../../../chrono";
|
2 | 2 | import { ParsingResult } from "../../../results";
|
3 | 3 | import { findYearClosestToRef } from "../../../calculation/years";
|
4 |
| -import { MONTH_DICTIONARY, REGEX_PARTS } from "../constants"; |
| 4 | +import { MONTH_DICTIONARY } from "../constants"; |
5 | 5 | import { YEAR_PATTERN, parseYear } from "../constants";
|
6 | 6 | import { ORDINAL_NUMBER_PATTERN, parseOrdinalNumberPattern } from "../constants";
|
7 | 7 | import { matchAnyPattern } from "../../../utils/pattern";
|
8 |
| -import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary"; |
9 |
| - |
10 |
| -// prettier-ignore |
11 |
| -const PATTERN = new RegExp( |
12 |
| - `(?:с)?\\s*(${ORDINAL_NUMBER_PATTERN})` + |
13 |
| - `(?:` + |
14 |
| - `\\s{0,3}(?:по|-|–|до)?\\s{0,3}` + |
15 |
| - `(${ORDINAL_NUMBER_PATTERN})` + |
16 |
| - `)?` + |
17 |
| - `(?:-|\\/|\\s{0,3}(?:of)?\\s{0,3})` + |
18 |
| - `(${matchAnyPattern(MONTH_DICTIONARY)})` + |
19 |
| - `(?:` + |
20 |
| - `(?:-|\\/|,?\\s{0,3})` + |
21 |
| - `(${YEAR_PATTERN}(?![^\\s]\\d))` + |
22 |
| - `)?` + |
23 |
| - `${REGEX_PARTS.rightBoundary}`, |
24 |
| - REGEX_PARTS.flags |
25 |
| -); |
| 8 | +import { AbstractParserWithLeftRightBoundaryChecking } from "./AbstractParserWithWordBoundaryChecking"; |
26 | 9 |
|
27 | 10 | const DATE_GROUP = 1;
|
28 | 11 | const DATE_TO_GROUP = 2;
|
29 | 12 | const MONTH_NAME_GROUP = 3;
|
30 | 13 | const YEAR_GROUP = 4;
|
31 | 14 |
|
32 |
| -export default class RUMonthNameLittleEndianParser extends AbstractParserWithWordBoundaryChecking { |
33 |
| - patternLeftBoundary(): string { |
34 |
| - return REGEX_PARTS.leftBoundary; |
35 |
| - } |
36 |
| - |
37 |
| - innerPattern(): RegExp { |
38 |
| - return PATTERN; |
| 15 | +export default class RUMonthNameLittleEndianParser extends AbstractParserWithLeftRightBoundaryChecking { |
| 16 | + innerPatternString(context: ParsingContext): string { |
| 17 | + // prettier-ignore |
| 18 | + return `(?:с)?\\s*(${ORDINAL_NUMBER_PATTERN})` + |
| 19 | + `(?:` + |
| 20 | + `\\s{0,3}(?:по|-|–|до)?\\s{0,3}` + |
| 21 | + `(${ORDINAL_NUMBER_PATTERN})` + |
| 22 | + `)?` + |
| 23 | + `(?:-|\\/|\\s{0,3}(?:of)?\\s{0,3})` + |
| 24 | + `(${matchAnyPattern(MONTH_DICTIONARY)})` + |
| 25 | + `(?:` + |
| 26 | + `(?:-|\\/|,?\\s{0,3})` + |
| 27 | + `(${YEAR_PATTERN}(?![^\\s]\\d))` + |
| 28 | + `)?`; |
39 | 29 | }
|
40 | 30 |
|
41 | 31 | innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingResult {
|
|
0 commit comments