Skip to content

Remove variant lists #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2019
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
13 changes: 10 additions & 3 deletions spec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 0.9.0 (Unreleased)

- Remove `VariantLists`. (#204)

The `VariantLists` and the `VariantExpression` syntax and AST nodes were
deprecated in Syntax 0.9 and have now been removed.

## 0.8.0 (December 13, 2018)

- Preserve content-indent in multiline `Patterns`. (#162)
Expand Down Expand Up @@ -73,7 +80,7 @@
`VariantLists`:

```properties
# A Term with a VariantList as a value.
# BEFORE A Term with a VariantList as a value.
-thing = {
*[definite] the thing
[indefinite] a thing
Expand All @@ -83,7 +90,7 @@
```

```properties
# A parametrized Term with a Pattern as a value.
# AFTER A parameterized Term with a Pattern as a value.
-thing = { $article ->
*[definite] the thing
[indefinite] a thing
Expand All @@ -96,7 +103,7 @@
hierarchies of term values:

```properties
# A parametrized Term with nested Patterns.
# AFTER A parameterized Term with nested Patterns.
-thing = { $article ->
*[definite] { $first-letter ->
*[lower] the thing
Expand Down
11 changes: 2 additions & 9 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 ::= "-" Identifier blank_inline? "=" blank_inline? Value Attribute*
Term ::= "-" Identifier blank_inline? "=" blank_inline? Pattern Attribute*

/* Adjacent comment lines of the same comment type are joined together during
* the AST construction. */
Expand All @@ -31,12 +31,8 @@ junk_line ::= /[^\n]*/ ("\u000A" | EOF)
/* Attributes of Messages and Terms. */
Attribute ::= line_end blank? "." Identifier blank_inline? "=" blank_inline? Pattern

/* Value types: Pattern and VariantList (deprecated). */
Value ::= Pattern
| VariantList
/* Patterns are values of Messages, Terms, Attributes and Variants. */
Pattern ::= PatternElement+
/* DEPRECATION NOTICE VariantLists have been deprecated in Syntax 0.8. */
VariantList ::= blank? "{" variant_list blank? "}"

/* TextElement and Placeable can occur inline or as block.
* Text needs to be indented and start with a non-special character.
Expand All @@ -58,7 +54,6 @@ InlineExpression ::= StringLiteral
| NumberLiteral
| CallExpression
| AttributeExpression
| VariantExpression
| MessageReference
| TermReference
| VariableReference
Expand All @@ -82,8 +77,6 @@ Argument ::= NamedArgument
| InlineExpression
NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral)
AttributeExpression ::= (MessageReference | TermReference) "." Identifier
/* DEPRECATION NOTICE VariantExpressions have been deprecated in Syntax 0.8. */
VariantExpression ::= TermReference VariantKey

/* Block Expressions */
SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list
Expand Down
3 changes: 0 additions & 3 deletions syntax/abstract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ export function list_into(Type) {

return always(new Type(selector, variants));
};
case FTL.VariantList:
return ([variants]) =>
always(new Type(variants));
default:
return elements =>
always(new Type(...elements));
Expand Down
17 changes: 0 additions & 17 deletions syntax/ast.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ export class Term extends Entry {
}
}

export class VariantList extends SyntaxNode {
constructor(variants) {
super();
this.type = "VariantList";
this.variants = variants;
}
}

export class Pattern extends SyntaxNode {
constructor(elements) {
super();
Expand Down Expand Up @@ -154,15 +146,6 @@ export class AttributeExpression extends Expression {
}
}

export class VariantExpression extends Expression {
constructor(ref, key) {
super();
this.type = "VariantExpression";
this.ref = ref;
this.key = key;
}
}

export class CallExpression extends Expression {
constructor(callee, positional = [], named = []) {
super();
Expand Down
31 changes: 3 additions & 28 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let Term = defer(() =>
maybe(blank_inline),
string("="),
maybe(blank_inline),
Value.abstract,
Pattern.abstract,
repeat(Attribute).abstract)
.map(keep_abstract)
.chain(list_into(FTL.Term)));
Expand Down Expand Up @@ -133,31 +133,15 @@ let Attribute = defer(() =>
.map(keep_abstract)
.chain(list_into(FTL.Attribute)));

/* -------------------------------------------------- */
/* Value types: Pattern and VariantList (deprecated). */
let Value = defer(() =>
either(
Pattern,
VariantList));

/* ---------------------------------------------------------------- */
/* Patterns are values of Messages, Terms, Attributes and Variants. */
let Pattern = defer(() =>
repeat1(
PatternElement)
// Flatten block_text and block_placeable which return lists.
.map(flatten(1))
.chain(list_into(FTL.Pattern)));

/* DEPRECATION NOTICE VariantLists have been deprecated in Syntax 0.8. */
let VariantList = defer(() =>
sequence(
maybe(blank),
string("{"),
variant_list.abstract,
maybe(blank),
string("}"))
.map(keep_abstract)
.chain(list_into(FTL.VariantList)));

/* ----------------------------------------------------------------- */
/* TextElement and Placeable can occur inline or as block.
* Text needs to be indented and start with a non-special character.
Expand Down Expand Up @@ -214,7 +198,6 @@ let InlineExpression = defer(() =>
NumberLiteral,
CallExpression,
AttributeExpression,
VariantExpression,
MessageReference,
TermReference,
VariableReference,
Expand Down Expand Up @@ -322,14 +305,6 @@ let AttributeExpression = defer(() =>
.map(keep_abstract)
.chain(list_into(FTL.AttributeExpression)));

/* DEPRECATION NOTICE VariantExpressions have been deprecated in Syntax 0.8. */
let VariantExpression = defer(() =>
sequence(
TermReference.abstract,
VariantKey.abstract)
.map(keep_abstract)
.chain(list_into(FTL.VariantExpression)));

/* ----------------- */
/* Block Expressions */
let SelectExpression = defer(() =>
Expand Down
17 changes: 4 additions & 13 deletions test/fixtures/member_expressions.ftl
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
## Member expressions in placeables.

# OK Message attributes may be interpolated in values.
message-attribute-expression-placeable = {msg.attr}
term-variant-expression-placeable = {-term[case]}

# ERROR Message values cannot be VariantLists
message-variant-expression-placeable = {msg[case]}
# ERROR Term attributes may not be used for interpolation.
term-attribute-expression-placeable = {-term.attr}


## Member expressions in selectors.

# OK Term attributes may be used as selectors.
term-attribute-expression-selector = {-term.attr ->
*[key] Value
}

# ERROR Message attributes may not be used as selector.
# ERROR Message attributes may not be used as selectors.
message-attribute-expression-selector = {msg.attr ->
*[key] Value
}
# ERROR Term values may not be used as selector.
term-variant-expression-selector = {-term[case] ->
*[key] Value
}
# ERROR Message values cannot be VariantLists
message-variant-expression-selector = {msg[case] ->
*[key] Value
}
72 changes: 10 additions & 62 deletions test/fixtures/member_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,10 @@
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "term-variant-expression-placeable"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "VariantExpression",
"ref": {
"type": "TermReference",
"id": {
"type": "Identifier",
"name": "term"
}
},
"key": {
"type": "Identifier",
"name": "case"
}
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Comment",
"content": "ERROR Message values cannot be VariantLists"
},
{
"type": "Junk",
"annotations": [],
"content": "message-variant-expression-placeable = {msg[case]}\n"
"comment": {
"type": "Comment",
"content": "OK Message attributes may be interpolated in values."
}
},
{
"type": "Comment",
Expand All @@ -83,7 +46,7 @@
{
"type": "Junk",
"annotations": [],
"content": "term-attribute-expression-placeable = {-term.attr}\n\n"
"content": "term-attribute-expression-placeable = {-term.attr}\n\n\n"
},
{
"type": "GroupComment",
Expand Down Expand Up @@ -140,34 +103,19 @@
]
},
"attributes": [],
"comment": null
"comment": {
"type": "Comment",
"content": "OK Term attributes may be used as selectors."
}
},
{
"type": "Comment",
"content": "ERROR Message attributes may not be used as selector."
"content": "ERROR Message attributes may not be used as selectors."
},
{
"type": "Junk",
"annotations": [],
"content": "message-attribute-expression-selector = {msg.attr ->\n *[key] Value\n}\n"
},
{
"type": "Comment",
"content": "ERROR Term values may not be used as selector."
},
{
"type": "Junk",
"annotations": [],
"content": "term-variant-expression-selector = {-term[case] ->\n *[key] Value\n}\n"
},
{
"type": "Comment",
"content": "ERROR Message values cannot be VariantLists"
},
{
"type": "Junk",
"annotations": [],
"content": "message-variant-expression-selector = {msg[case] ->\n *[key] Value\n}\n"
}
]
}
29 changes: 29 additions & 0 deletions test/fixtures/obsolete.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### The syntax in this file has been discontinued. It is no longer part of the
### Fluent specification and should not be implemented nor used. We're keeping
### these fixtures around to protect against accidental syntax reuse.


## Variant lists.

message-variant-list =
{
*[key] Value
}

-term-variant-list =
{
*[key] Value
}


## Variant expressions.

message-variant-expression-placeable = {msg[case]}
message-variant-expression-selector = {msg[case] ->
*[key] Value
}

term-variant-expression-placeable = {-term[case]}
term-variant-expression-selector = {-term[case] ->
*[key] Value
}
47 changes: 47 additions & 0 deletions test/fixtures/obsolete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"type": "Resource",
"body": [
{
"type": "ResourceComment",
"content": "The syntax in this file has been discontinued. It is no longer part of the\nFluent specification and should not be implemented nor used. We're keeping\nthese fixtures around to protect against accidental syntax reuse."
},
{
"type": "GroupComment",
"content": "Variant lists."
},
{
"type": "Junk",
"annotations": [],
"content": "message-variant-list =\n {\n *[key] Value\n }\n\n"
},
{
"type": "Junk",
"annotations": [],
"content": "-term-variant-list =\n {\n *[key] Value\n }\n\n\n"
},
{
"type": "GroupComment",
"content": "Variant expressions."
},
{
"type": "Junk",
"annotations": [],
"content": "message-variant-expression-placeable = {msg[case]}\n"
},
{
"type": "Junk",
"annotations": [],
"content": "message-variant-expression-selector = {msg[case] ->\n *[key] Value\n}\n\n"
},
{
"type": "Junk",
"annotations": [],
"content": "term-variant-expression-placeable = {-term[case]}\n"
},
{
"type": "Junk",
"annotations": [],
"content": "term-variant-expression-selector = {-term[case] ->\n *[key] Value\n}\n"
}
]
}
Loading