@formatjs/icu-messageformat-parser 3.2.1 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/date-time-pattern-generator.d.ts +6 -6
- package/date-time-pattern-generator.js +62 -77
- package/error.d.ts +64 -64
- package/error.js +64 -63
- package/index.d.ts +4 -4
- package/index.js +40 -42
- package/manipulator.d.ts +19 -19
- package/manipulator.js +158 -159
- package/no-parser.d.ts +2 -2
- package/no-parser.js +4 -4
- package/package.json +4 -4
- package/parser.d.ts +142 -139
- package/parser.js +839 -900
- package/printer.d.ts +1 -1
- package/printer.js +68 -79
- package/regex.generated.js +2 -2
- package/time-data.generated.js +1162 -1424
- package/types.d.ts +77 -74
- package/types.js +68 -67
package/parser.d.ts
CHANGED
|
@@ -1,147 +1,150 @@
|
|
|
1
|
-
import { ParserError } from
|
|
2
|
-
import { MessageFormatElement } from
|
|
1
|
+
import { type ParserError } from "./error.js";
|
|
2
|
+
import { type MessageFormatElement } from "./types.js";
|
|
3
3
|
export interface Position {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/** Offset in terms of UTF-16 *code unit*. */
|
|
5
|
+
offset: number;
|
|
6
|
+
line: number;
|
|
7
|
+
/** Column offset in terms of unicode *code point*. */
|
|
8
|
+
column: number;
|
|
9
9
|
}
|
|
10
10
|
export interface ParserOptions {
|
|
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
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Whether to treat HTML/XML tags as string literal
|
|
13
|
+
* instead of parsing them as tag token.
|
|
14
|
+
* When this is false we only allow simple tags without
|
|
15
|
+
* any attributes
|
|
16
|
+
*/
|
|
17
|
+
ignoreTag?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Should `select`, `selectordinal`, and `plural` arguments always include
|
|
20
|
+
* the `other` case clause.
|
|
21
|
+
*/
|
|
22
|
+
requiresOtherClause?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to parse number/datetime skeleton
|
|
25
|
+
* into Intl.NumberFormatOptions and Intl.DateTimeFormatOptions, respectively.
|
|
26
|
+
*/
|
|
27
|
+
shouldParseSkeletons?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Capture location info in AST
|
|
30
|
+
* Default is false
|
|
31
|
+
*/
|
|
32
|
+
captureLocation?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Instance of Intl.Locale to resolve locale-dependent skeleton
|
|
35
|
+
*/
|
|
36
|
+
locale?: Intl.Locale;
|
|
37
37
|
}
|
|
38
|
-
export type Result<
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export type Result<
|
|
39
|
+
T,
|
|
40
|
+
E
|
|
41
|
+
> = {
|
|
42
|
+
val: T;
|
|
43
|
+
err: null;
|
|
41
44
|
} | {
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
val: null;
|
|
46
|
+
err: E;
|
|
44
47
|
};
|
|
45
48
|
export declare class Parser {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
49
|
+
private message;
|
|
50
|
+
private position;
|
|
51
|
+
private locale?;
|
|
52
|
+
private ignoreTag;
|
|
53
|
+
private requiresOtherClause;
|
|
54
|
+
private shouldParseSkeletons?;
|
|
55
|
+
constructor(message: string, options?: ParserOptions);
|
|
56
|
+
parse(): Result<MessageFormatElement[], ParserError>;
|
|
57
|
+
private parseMessage;
|
|
58
|
+
/**
|
|
59
|
+
* A tag name must start with an ASCII lower/upper case letter. The grammar is based on the
|
|
60
|
+
* [custom element name][] except that a dash is NOT always mandatory and uppercase letters
|
|
61
|
+
* are accepted:
|
|
62
|
+
*
|
|
63
|
+
* ```
|
|
64
|
+
* tag ::= "<" tagName (whitespace)* "/>" | "<" tagName (whitespace)* ">" message "</" tagName (whitespace)* ">"
|
|
65
|
+
* tagName ::= [a-z] (PENChar)*
|
|
66
|
+
* PENChar ::=
|
|
67
|
+
* "-" | "." | [0-9] | "_" | [a-z] | [A-Z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] |
|
|
68
|
+
* [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
|
|
69
|
+
* [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* [custom element name]: https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
73
|
+
* NOTE: We're a bit more lax here since HTML technically does not allow uppercase HTML element but we do
|
|
74
|
+
* since other tag-based engines like React allow it
|
|
75
|
+
*/
|
|
76
|
+
private parseTag;
|
|
77
|
+
/**
|
|
78
|
+
* This method assumes that the caller has peeked ahead for the first tag character.
|
|
79
|
+
*/
|
|
80
|
+
private parseTagName;
|
|
81
|
+
private parseLiteral;
|
|
82
|
+
tryParseLeftAngleBracket(): string | null;
|
|
83
|
+
/**
|
|
84
|
+
* Starting with ICU 4.8, an ASCII apostrophe only starts quoted text if it immediately precedes
|
|
85
|
+
* a character that requires quoting (that is, "only where needed"), and works the same in
|
|
86
|
+
* nested messages as on the top level of the pattern. The new behavior is otherwise compatible.
|
|
87
|
+
*/
|
|
88
|
+
private tryParseQuote;
|
|
89
|
+
private tryParseUnquoted;
|
|
90
|
+
private parseArgument;
|
|
91
|
+
/**
|
|
92
|
+
* Advance the parser until the end of the identifier, if it is currently on
|
|
93
|
+
* an identifier character. Return an empty string otherwise.
|
|
94
|
+
*/
|
|
95
|
+
private parseIdentifierIfPossible;
|
|
96
|
+
private parseArgumentOptions;
|
|
97
|
+
private tryParseArgumentClose;
|
|
98
|
+
/**
|
|
99
|
+
* See: https://github.com/unicode-org/icu/blob/af7ed1f6d2298013dc303628438ec4abe1f16479/icu4c/source/common/messagepattern.cpp#L659
|
|
100
|
+
*/
|
|
101
|
+
private parseSimpleArgStyleIfPossible;
|
|
102
|
+
private parseNumberSkeletonFromString;
|
|
103
|
+
/**
|
|
104
|
+
* @param nesting_level The current nesting level of messages.
|
|
105
|
+
* This can be positive when parsing message fragment in select or plural argument options.
|
|
106
|
+
* @param parent_arg_type The parent argument's type.
|
|
107
|
+
* @param parsed_first_identifier If provided, this is the first identifier-like selector of
|
|
108
|
+
* the argument. It is a by-product of a previous parsing attempt.
|
|
109
|
+
* @param expecting_close_tag If true, this message is directly or indirectly nested inside
|
|
110
|
+
* between a pair of opening and closing tags. The nested message will not parse beyond
|
|
111
|
+
* the closing tag boundary.
|
|
112
|
+
*/
|
|
113
|
+
private tryParsePluralOrSelectOptions;
|
|
114
|
+
private tryParseDecimalInteger;
|
|
115
|
+
private offset;
|
|
116
|
+
private isEOF;
|
|
117
|
+
private clonePosition;
|
|
118
|
+
/**
|
|
119
|
+
* Return the code point at the current position of the parser.
|
|
120
|
+
* Throws if the index is out of bound.
|
|
121
|
+
*/
|
|
122
|
+
private char;
|
|
123
|
+
private error;
|
|
124
|
+
/** Bump the parser to the next UTF-16 code unit. */
|
|
125
|
+
private bump;
|
|
126
|
+
/**
|
|
127
|
+
* If the substring starting at the current position of the parser has
|
|
128
|
+
* the given prefix, then bump the parser to the character immediately
|
|
129
|
+
* following the prefix and return true. Otherwise, don't bump the parser
|
|
130
|
+
* and return false.
|
|
131
|
+
*/
|
|
132
|
+
private bumpIf;
|
|
133
|
+
/**
|
|
134
|
+
* Bump the parser until the pattern character is found and return `true`.
|
|
135
|
+
* Otherwise bump to the end of the file and return `false`.
|
|
136
|
+
*/
|
|
137
|
+
private bumpUntil;
|
|
138
|
+
/**
|
|
139
|
+
* Bump the parser to the target offset.
|
|
140
|
+
* If target offset is beyond the end of the input, bump the parser to the end of the input.
|
|
141
|
+
*/
|
|
142
|
+
private bumpTo;
|
|
143
|
+
/** advance the parser through all whitespace to the next non-whitespace code unit. */
|
|
144
|
+
private bumpSpace;
|
|
145
|
+
/**
|
|
146
|
+
* Peek at the *next* Unicode codepoint in the input without advancing the parser.
|
|
147
|
+
* If the input has been exhausted, then this returns null.
|
|
148
|
+
*/
|
|
149
|
+
private peek;
|
|
147
150
|
}
|