Skip to content

Forbid the closing brace in text #198

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
Oct 31, 2018
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
3 changes: 2 additions & 1 deletion spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ any_char ::= [\\u{9}\\u{20}-\\u{D7FF}\\u{E000}-\\u{FFFD}]
* new line.
*/
special_text_char ::= "{"
| "}"
text_char ::= any_char - special_text_char
indented_char ::= text_char - "}" - "[" - "*" - "."
indented_char ::= text_char - "[" - "*" - "."

/* String literals
*
Expand Down
5 changes: 3 additions & 2 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@ let any_char =
*/

let special_text_char =
string("{");
either(
string("{"),
string("}"));

let text_char =
and(
Expand All @@ -409,7 +411,6 @@ let indented_char =
not(string(".")),
not(string("*")),
not(string("[")),
not(string("}")),
text_char);

/* -------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/escaped_characters.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ string-escaped-unicode = {"\\u0041"}

## Literal braces
brace-open = An opening {"{"} brace.
brace-close = A closing } brace.
brace-close = A closing {"}"} brace.
13 changes: 12 additions & 1 deletion test/fixtures/escaped_characters.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,18 @@
"elements": [
{
"type": "TextElement",
"value": "A closing } brace."
"value": "A closing "
},
{
"type": "Placeable",
"expression": {
"type": "StringLiteral",
"value": "}"
}
},
{
"type": "TextElement",
"value": " brace."
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/placeables.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
nested-placeable = {{{1}}}
padded-placeable = { 1 }
sparse-placeable = { { 1 } }

# ERROR Unmatched opening brace
unmatched-open1 = { 1

# ERROR Unmatched opening brace
unmatched-open2 = {{ 1 }

# ERROR Unmatched closing brace
unmatched-close1 = 1 }

# ERROR Unmatched closing brace
unmatched-close2 = { 1 }}
36 changes: 36 additions & 0 deletions test/fixtures/placeables.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,42 @@
},
"attributes": [],
"comment": null
},
{
"type": "Comment",
"content": "ERROR Unmatched opening brace"
},
{
"type": "Junk",
"annotations": [],
"content": "unmatched-open1 = { 1\n"
},
{
"type": "Comment",
"content": "ERROR Unmatched opening brace"
},
{
"type": "Junk",
"annotations": [],
"content": "unmatched-open2 = {{ 1 }\n"
},
{
"type": "Comment",
"content": "ERROR Unmatched closing brace"
},
{
"type": "Junk",
"annotations": [],
"content": "unmatched-close1 = 1 }\n"
},
{
"type": "Comment",
"content": "ERROR Unmatched closing brace"
},
{
"type": "Junk",
"annotations": [],
"content": "unmatched-close2 = { 1 }}\n"
}
]
}
5 changes: 5 additions & 0 deletions test/fixtures/select_expressions.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ nested-variant-list =
*[two] Value
}
}

# ERROR Missing line end after variant list
missing-line-end =
{ 1 ->
*[one] One}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a syntax error because any list of variants must end with a line_end to be well-formed.

9 changes: 9 additions & 0 deletions test/fixtures/select_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@
"type": "Junk",
"annotations": [],
"content": "nested-variant-list =\n { 1 ->\n *[one] {\n *[two] Value\n }\n }\n"
},
{
"type": "Comment",
"content": "ERROR Missing line end after variant list"
},
{
"type": "Junk",
"annotations": [],
"content": "missing-line-end =\n { 1 ->\n *[one] One}\n"
}
]
}