Skip to content

Commit

Permalink
Make trailing = optional if Message has no value
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki committed Oct 22, 2018
1 parent bac1271 commit e71471b
Show file tree
Hide file tree
Showing 4 changed files with 292 additions and 6 deletions.
2 changes: 1 addition & 1 deletion spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Resource ::= (Entry | blank_block | junk_line)*
Entry ::= (Message line_end)
| (Term line_end)
| CommentLine
Message ::= Identifier blank_inline? "=" blank_inline? ((Pattern Attribute*) | (Attribute+))
Message ::= Identifier ((blank_inline? "=" blank_inline? Pattern? Attribute+) | (blank_inline? "=" blank_inline? Pattern) | (blank_inline? Attribute+))
Term ::= "-" Identifier blank_inline? "=" blank_inline? Value Attribute*

/* Adjacent comment lines of the same comment type are joined together during
Expand Down
21 changes: 16 additions & 5 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,27 @@ let Entry = defer(() =>
let Message = defer(() =>
sequence(
Identifier.abstract,
maybe(blank_inline),
string("="),
maybe(blank_inline),
either(
sequence(
maybe(blank_inline),
string("="),
maybe(blank_inline),
maybe(Pattern).abstract,
repeat1(Attribute).abstract,
),
sequence(
maybe(blank_inline),
string("="),
maybe(blank_inline),
Pattern.abstract,
repeat(Attribute).abstract),
),
sequence(
maybe(blank_inline),
always(null).abstract,
repeat1(Attribute).abstract)))
repeat1(Attribute).abstract,
),
)
)
.map(flatten(1))
.map(keep_abstract)
.chain(list_into(FTL.Message)));
Expand Down
27 changes: 27 additions & 0 deletions test/fixtures/messages-no-equal.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
key01 = Value
key02 = Value
.attr = Attribute
key02 = Value
.attr1 = Attribute 1
.attr2 = Attribute 2
key03
.attr = Attribute

key04
.attr1 = Attribute 1
.attr2 = Attribute 2

# < whitespace >
key05
.attr1 = Attribute 1

key06 = {""}
# JUNK Missing value
key07 =
# JUNK Missing =
key08
248 changes: 248 additions & 0 deletions test/fixtures/messages-no-equal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
{
"type": "Resource",
"body": [
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key01"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Value"
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key02"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Value"
}
]
},
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key02"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Value"
}
]
},
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr1"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 1"
}
]
}
},
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr2"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 2"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key03"
},
"value": null,
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key04"
},
"value": null,
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr1"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 1"
}
]
}
},
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr2"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 2"
}
]
}
}
],
"comment": null
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key05"
},
"value": null,
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": "attr1"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Attribute 1"
}
]
}
}
],
"comment": {
"type": "Comment",
"content": " < whitespace >"
}
},
{
"type": "Message",
"id": {
"type": "Identifier",
"name": "key06"
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "Placeable",
"expression": {
"type": "StringLiteral",
"value": ""
}
}
]
},
"attributes": [],
"comment": null
},
{
"type": "Comment",
"content": "JUNK Missing value"
},
{
"type": "Junk",
"annotations": [],
"content": "key07 =\n"
},
{
"type": "Comment",
"content": "JUNK Missing ="
},
{
"type": "Junk",
"annotations": [],
"content": "key08\n"
}
]
}

0 comments on commit e71471b

Please sign in to comment.