Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion spec/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

## Unreleased

- Support astral Unicode characters. (#179)
- Support astral Unicode characters. (#174)

Unicode characters from outside of the Basic Multilingual Plane can now
be used in values of `TextElements` and `StringLiterals`. This means all
characters in the U+10000 to U+10FFFF range. 🎉

- Don't store the `-` sigil in `Identifiers` of `Terms`. (#142)

The `-` sigil is no longer part of the term's `Identifier`. This is now
consistent with how `Identifiers` of variables don't include the `$`
sigil either.

## 0.7.0 (October 15, 2018)

- Relax the indentation requirement. (#87)
Expand Down
11 changes: 4 additions & 7 deletions spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Entry ::= (Message line_end)
| (Term line_end)
| CommentLine
Message ::= Identifier blank_inline? "=" blank_inline? ((Pattern Attribute*) | (Attribute+))
Term ::= TermIdentifier blank_inline? "=" blank_inline? Value Attribute*
Term ::= "-" Identifier blank_inline? "=" blank_inline? Value Attribute*

/* Adjacent comment lines of the same comment type are joined together during
* the AST construction. */
Expand Down Expand Up @@ -62,8 +62,8 @@ NumberLiteral ::= "-"? digit+ ("." digit+)?

/* Inline Expressions */
MessageReference ::= Identifier
TermReference ::= TermIdentifier
VariableReference ::= VariableIdentifier
TermReference ::= "-" Identifier
VariableReference ::= "$" Identifier
CallExpression ::= Function blank? "(" blank? argument_list blank? ")"
argument_list ::= (Argument blank? "," blank?)* Argument?
Argument ::= NamedArgument
Expand All @@ -80,11 +80,8 @@ DefaultVariant ::= line_end blank? "*" VariantKey blank_inline? Value
VariantKey ::= "[" blank? (NumberLiteral | Identifier) blank? "]"

/* Identifiers */
Identifier ::= identifier
TermIdentifier ::= "-" identifier
VariableIdentifier ::= "$" identifier
Identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*
Function ::= [A-Z] [A-Z_?-]*
identifier ::= [a-zA-Z] [a-zA-Z0-9_-]*

/* Characters */
backslash ::= "\\"
Expand Down
43 changes: 18 additions & 25 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ let Message = defer(() =>

let Term = defer(() =>
sequence(
TermIdentifier.abstract,
string("-"),
Identifier.abstract,
maybe(blank_inline),
string("="),
maybe(blank_inline),
Expand Down Expand Up @@ -223,10 +224,18 @@ let MessageReference = defer(() =>
Identifier.chain(into(FTL.MessageReference)));

let TermReference = defer(() =>
TermIdentifier.chain(into(FTL.TermReference)));
sequence(
string("-"),
Identifier)
.map(element_at(1))
.chain(into(FTL.TermReference)));

let VariableReference = defer(() =>
VariableIdentifier.chain(into(FTL.VariableReference)));
sequence(
string("$"),
Identifier)
.map(element_at(1))
.chain(into(FTL.VariableReference)));

let CallExpression = defer(() =>
sequence(
Expand Down Expand Up @@ -343,22 +352,14 @@ let VariantKey = defer(() =>
/* ----------- */
/* Identifiers */

let Identifier = defer(() =>
identifier.chain(into(FTL.Identifier)));

let TermIdentifier = defer(() =>
let Identifier =
sequence(
string("-"),
identifier)
charset("a-zA-Z"),
repeat(
charset("a-zA-Z0-9_-")))
.map(flatten(1))
.map(join)
.chain(into(FTL.Identifier)));

let VariableIdentifier = defer(() =>
sequence(
string("$"),
identifier)
.map(element_at(1))
.chain(into(FTL.Identifier)));
.chain(into(FTL.Identifier));

let Function =
sequence(
Expand All @@ -369,14 +370,6 @@ let Function =
.map(join)
.chain(into(FTL.Function));

let identifier =
sequence(
charset("a-zA-Z"),
repeat(
charset("a-zA-Z0-9_-")))
.map(flatten(1))
.map(join);

/* ---------- */
/* Characters */

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/call_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "-msg"
"name": "msg"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/comments.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-term"
"name": "term"
},
"value": {
"type": "Pattern",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/member_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "-term"
"name": "term"
}
},
"key": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/mixed_entries.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-brand-name"
"name": "brand-name"
},
"value": {
"type": "Pattern",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/reference_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "-term"
"name": "term"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/select_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "-term"
"name": "term"
}
},
"name": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/terms.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-term01"
"name": "term01"
},
"value": {
"type": "Pattern",
Expand Down Expand Up @@ -40,7 +40,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-term02"
"name": "term02"
},
"value": {
"type": "Pattern",
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/variables.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
key01 = {$var}
key02 = { $var }
key03 = {
$var
}
key04 = {
$var}


## Errors

# ERROR Missing variable identifier
err01 = {$}
# ERROR Double $$
err02 = {$$var}
# ERROR Invalid first char of the identifier
err03 = {$-var}
132 changes: 132 additions & 0 deletions test/fixtures/variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
"type": "Resource",
"body": [
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key01"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "var"
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key02"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "var"
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key03"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "var"
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key04"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "VariableReference",
"id": {
"type": "Identifier",
"name": "var"
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "GroupComment",
"content": "Errors"
},
{
"type": "Comment",
"content": "ERROR Missing variable identifier"
},
{
"type": "Junk",
"annotations": [],
"content": "err01 = {$}\n"
},
{
"type": "Comment",
"content": "ERROR Double $$"
},
{
"type": "Junk",
"annotations": [],
"content": "err02 = {$$var}\n"
},
{
"type": "Comment",
"content": "ERROR Invalid first char of the identifier"
},
{
"type": "Junk",
"annotations": [],
"content": "err03 = {$-var}\n"
}
]
}
8 changes: 4 additions & 4 deletions test/fixtures/variant_keys.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-simple-identifier"
"name": "simple-identifier"
},
"value": {
"type": "VariantList",
Expand Down Expand Up @@ -36,7 +36,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-identifier-surrounded-by-whitespace"
"name": "identifier-surrounded-by-whitespace"
},
"value": {
"type": "VariantList",
Expand Down Expand Up @@ -67,7 +67,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-int-number"
"name": "int-number"
},
"value": {
"type": "VariantList",
Expand Down Expand Up @@ -98,7 +98,7 @@
"type": "Term",
"id": {
"type": "Identifier",
"name": "-float-number"
"name": "float-number"
},
"value": {
"type": "VariantList",
Expand Down
Loading