File tree 8 files changed +263
-78
lines changed 8 files changed +263
-78
lines changed Original file line number Diff line number Diff line change 91
91
Junk represents a literal slice of unparsed content and shouldn' t have
92
92
its line endings normalized to LF.
93
93
94
+ - Add the `FunctionReference` production. (#210)
95
+
96
+ Function references in `CallExpressions` are now stored as
97
+ `FunctionReference` AST nodes, with an `id` field which is an
98
+ `Identifier`.
99
+
100
+ The `Function` production and its corresponding AST node have been
101
+ removed. The logic validating that function names are all upper-case has
102
+ been moved to `abstract.mjs`.
103
+
94
104
## 0.7.0 (October 15, 2018)
95
105
96
106
- Relax the indentation requirement. (#87)
Original file line number Diff line number Diff line change @@ -64,7 +64,8 @@ NumberLiteral ::= "-"? digit+ ("." digit+)?
64
64
MessageReference ::= Identifier
65
65
TermReference ::= " -" Identifier
66
66
VariableReference ::= " $" Identifier
67
- CallExpression ::= Function blank ? " (" blank ? argument_list blank ? " )"
67
+ FunctionReference ::= Identifier
68
+ CallExpression ::= FunctionReference blank ? " (" blank ? argument_list blank ? " )"
68
69
argument_list ::= (Argument blank ? " ," blank ? )* Argument ?
69
70
Argument ::= NamedArgument
70
71
| InlineExpression
@@ -79,9 +80,8 @@ Variant ::= line_end blank? VariantKey blank_inline? Value
79
80
DefaultVariant ::= line_end blank ? " *" VariantKey blank_inline ? Value
80
81
VariantKey ::= " [" blank ? (NumberLiteral | Identifier ) blank ? " ]"
81
82
82
- /* Identifiers */
83
+ /* Identifier */
83
84
Identifier ::= [a-zA-Z ] [a-zA-Z0-9_- ]*
84
- Function ::= [A-Z ] [A-Z_ ? - ]*
85
85
86
86
/* Content Characters
87
87
*
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ export function list_into(Type) {
72
72
|| ( selector instanceof FTL . AttributeExpression
73
73
&& selector . ref instanceof FTL . MessageReference ) ;
74
74
if ( invalid_selector_found ) {
75
- return never ( " Invalid selector type: ${selector.type}." ) ;
75
+ return never ( ` Invalid selector type: ${ selector . type } .` ) ;
76
76
}
77
77
let invalid_variants_found = variants . some (
78
78
variant => variant . value instanceof FTL . VariantList ) ;
@@ -94,14 +94,24 @@ export function list_into(Type) {
94
94
95
95
export function into ( Type ) {
96
96
switch ( Type ) {
97
+ case FTL . FunctionReference :
98
+ const VALID_FUNCTION_NAME = / ^ [ A - Z ] [ A - Z 0 - 9 _ ? - ] * $ / ;
99
+ return identifier => {
100
+ if ( ! VALID_FUNCTION_NAME . test ( identifier . name ) ) {
101
+ return never (
102
+ `Invalid function name: ${ identifier . name } . ` +
103
+ "Function names must be upper-case." ) ;
104
+ }
105
+ return always ( new Type ( identifier ) ) ;
106
+ } ;
97
107
case FTL . Placeable :
98
108
return expression => {
99
109
let invalid_expression_found =
100
110
expression instanceof FTL . AttributeExpression
101
111
&& expression . ref instanceof FTL . TermReference ;
102
112
if ( invalid_expression_found ) {
103
113
return never (
104
- " Invalid expression type: ${expression.type}." ) ;
114
+ ` Invalid expression type: ${ expression . type } .` ) ;
105
115
}
106
116
return always ( new Type ( expression ) ) ;
107
117
} ;
Original file line number Diff line number Diff line change @@ -121,6 +121,14 @@ export class VariableReference extends Expression {
121
121
}
122
122
}
123
123
124
+ export class FunctionReference extends Expression {
125
+ constructor ( id ) {
126
+ super ( ) ;
127
+ this . type = "FunctionReference" ;
128
+ this . id = id ;
129
+ }
130
+ }
131
+
124
132
export class SelectExpression extends Expression {
125
133
constructor ( selector , variants ) {
126
134
super ( ) ;
@@ -222,13 +230,6 @@ export class ResourceComment extends BaseComment {
222
230
}
223
231
}
224
232
225
- export class Function extends Identifier {
226
- constructor ( name ) {
227
- super ( name ) ;
228
- this . type = "Function" ;
229
- }
230
- }
231
-
232
233
export class Junk extends SyntaxNode {
233
234
constructor ( content ) {
234
235
super ( ) ;
Original file line number Diff line number Diff line change @@ -238,9 +238,12 @@ let VariableReference = defer(() =>
238
238
. map ( element_at ( 1 ) )
239
239
. chain ( into ( FTL . VariableReference ) ) ) ;
240
240
241
+ let FunctionReference = defer ( ( ) =>
242
+ Identifier . chain ( into ( FTL . FunctionReference ) ) ) ;
243
+
241
244
let CallExpression = defer ( ( ) =>
242
245
sequence (
243
- Function . abstract ,
246
+ FunctionReference . abstract ,
244
247
maybe ( blank ) ,
245
248
string ( "(" ) ,
246
249
maybe ( blank ) ,
@@ -350,8 +353,8 @@ let VariantKey = defer(() =>
350
353
string ( "]" ) )
351
354
. map ( element_at ( 2 ) ) ) ;
352
355
353
- /* ----------- */
354
- /* Identifiers */
356
+ /* ---------- */
357
+ /* Identifier */
355
358
356
359
let Identifier =
357
360
sequence (
@@ -362,15 +365,6 @@ let Identifier =
362
365
. map ( join )
363
366
. chain ( into ( FTL . Identifier ) ) ;
364
367
365
- let Function =
366
- sequence (
367
- charset ( "A-Z" ) ,
368
- repeat (
369
- charset ( "A-Z_?-" ) ) )
370
- . map ( flatten ( 1 ) )
371
- . map ( join )
372
- . chain ( into ( FTL . Function ) ) ;
373
-
374
368
/* -------------------------------------------------------------------------- */
375
369
/* Content Characters
376
370
*
Original file line number Diff line number Diff line change
1
+ ## Callees
2
+
3
+ function-callee = { FUNCTION( ) }
4
+
5
+ # ERROR Equivalent to a MessageReference callee.
6
+ mixed-case-callee = { Function ()}
7
+
8
+ # ERROR MessageReference is not a valid callee.
9
+ message-callee = { message ()}
10
+ # ERROR TermReference is not a valid callee.
11
+ term-callee = { -term ()}
12
+ # ERROR VariableReference is not a valid callee.
13
+ variable-callee = { $variable ()}
14
+
15
+ ## Arguments
16
+
1
17
positional-args = { FUN( 1, "a", msg ) }
2
18
named-args = { FUN( x: 1 , y: "Y" ) }
3
19
dense-named-args = { FUN( x: 1 , y: "Y" ) }
You can’t perform that action at this time.
0 commit comments