@@ -114,14 +114,6 @@ export class Term extends Entry {
114
114
}
115
115
}
116
116
117
- export class VariantList extends SyntaxNode {
118
- constructor ( variants ) {
119
- super ( ) ;
120
- this . type = "VariantList" ;
121
- this . variants = variants ;
122
- }
123
- }
124
-
125
117
export class Pattern extends SyntaxNode {
126
118
constructor ( elements ) {
127
119
super ( ) ;
@@ -156,36 +148,87 @@ export class Placeable extends PatternElement {
156
148
*/
157
149
export class Expression extends SyntaxNode { }
158
150
159
- export class StringLiteral extends Expression {
160
- constructor ( raw , value ) {
151
+ // An abstract base class for Literals.
152
+ export class Literal extends Expression {
153
+ constructor ( value ) {
161
154
super ( ) ;
162
- this . type = "StringLiteral" ;
163
- this . raw = raw ;
155
+ // The "value" field contains the exact contents of the literal,
156
+ // character-for-character.
164
157
this . value = value ;
165
158
}
159
+
160
+ parse ( ) {
161
+ return { value : this . value } ;
162
+ }
166
163
}
167
164
168
- export class NumberLiteral extends Expression {
165
+ export class StringLiteral extends Literal {
169
166
constructor ( value ) {
170
- super ( ) ;
167
+ super ( value ) ;
168
+ this . type = "StringLiteral" ;
169
+ }
170
+
171
+ parse ( ) {
172
+ // Backslash backslash, backslash double quote, uHHHH, UHHHHHH.
173
+ const KNOWN_ESCAPES =
174
+ / (?: \\ \\ | \\ " | \\ u ( [ 0 - 9 a - f A - F ] { 4 } ) | \\ U ( [ 0 - 9 a - f A - F ] { 6 } ) ) / g;
175
+
176
+ function from_escape_sequence ( match , codepoint4 , codepoint6 ) {
177
+ switch ( match ) {
178
+ case "\\\\" :
179
+ return "\\" ;
180
+ case "\\\"" :
181
+ return "\"" ;
182
+ default :
183
+ let codepoint = parseInt ( codepoint4 || codepoint6 , 16 ) ;
184
+ if ( codepoint <= 0xD7FF || 0xE000 <= codepoint ) {
185
+ // It's a Unicode scalar value.
186
+ return String . fromCodePoint ( codepoint ) ;
187
+ }
188
+ // Escape sequences reresenting surrogate code points are
189
+ // well-formed but invalid in Fluent. Replace them with U+FFFD
190
+ // REPLACEMENT CHARACTER.
191
+ return "�" ;
192
+ }
193
+ }
194
+
195
+ let value = this . value . replace ( KNOWN_ESCAPES , from_escape_sequence ) ;
196
+ return { value} ;
197
+ }
198
+ }
199
+
200
+ export class NumberLiteral extends Literal {
201
+ constructor ( value ) {
202
+ super ( value ) ;
171
203
this . type = "NumberLiteral" ;
172
- this . value = value ;
204
+ }
205
+
206
+ parse ( ) {
207
+ let value = parseFloat ( this . value ) ;
208
+ let decimal_position = this . value . indexOf ( "." ) ;
209
+ let precision = decimal_position > 0
210
+ ? this . value . length - decimal_position - 1
211
+ : 0 ;
212
+ return { value, precision} ;
173
213
}
174
214
}
175
215
176
216
export class MessageReference extends Expression {
177
- constructor ( id ) {
217
+ constructor ( id , attribute = null ) {
178
218
super ( ) ;
179
219
this . type = "MessageReference" ;
180
220
this . id = id ;
221
+ this . attribute = attribute ;
181
222
}
182
223
}
183
224
184
225
export class TermReference extends Expression {
185
- constructor ( id ) {
226
+ constructor ( id , attribute = null , args = null ) {
186
227
super ( ) ;
187
228
this . type = "TermReference" ;
188
229
this . id = id ;
230
+ this . attribute = attribute ;
231
+ this . arguments = args ;
189
232
}
190
233
}
191
234
@@ -198,10 +241,11 @@ export class VariableReference extends Expression {
198
241
}
199
242
200
243
export class FunctionReference extends Expression {
201
- constructor ( id ) {
244
+ constructor ( id , args ) {
202
245
super ( ) ;
203
246
this . type = "FunctionReference" ;
204
247
this . id = id ;
248
+ this . arguments = args ;
205
249
}
206
250
}
207
251
@@ -214,29 +258,10 @@ export class SelectExpression extends Expression {
214
258
}
215
259
}
216
260
217
- export class AttributeExpression extends Expression {
218
- constructor ( ref , name ) {
219
- super ( ) ;
220
- this . type = "AttributeExpression" ;
221
- this . ref = ref ;
222
- this . name = name ;
223
- }
224
- }
225
-
226
- export class VariantExpression extends Expression {
227
- constructor ( ref , key ) {
228
- super ( ) ;
229
- this . type = "VariantExpression" ;
230
- this . ref = ref ;
231
- this . key = key ;
232
- }
233
- }
234
-
235
- export class CallExpression extends Expression {
236
- constructor ( callee , positional = [ ] , named = [ ] ) {
261
+ export class CallArguments extends SyntaxNode {
262
+ constructor ( positional = [ ] , named = [ ] ) {
237
263
super ( ) ;
238
- this . type = "CallExpression" ;
239
- this . callee = callee ;
264
+ this . type = "CallArguments" ;
240
265
this . positional = positional ;
241
266
this . named = named ;
242
267
}
@@ -333,7 +358,7 @@ export class Annotation extends SyntaxNode {
333
358
super ( ) ;
334
359
this . type = "Annotation" ;
335
360
this . code = code ;
336
- this . args = args ;
361
+ this . arguments = args ;
337
362
this . message = message ;
338
363
}
339
364
}
0 commit comments