Skip to content

Make trailing = optional if Message has no value #191

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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+) | 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
24 changes: 17 additions & 7 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,27 @@ let Entry = defer(() =>
let Message = defer(() =>
sequence(
Identifier.abstract,
maybe(blank_inline),
string("="),
maybe(blank_inline),
either(
sequence(
Pattern.abstract,
repeat(Attribute).abstract),
maybe(blank_inline),
string("="),
maybe(blank_inline),
either(
sequence(
maybe(Pattern).abstract,
repeat1(Attribute).abstract,
),
Pattern.abstract,
),
),
sequence(
maybe(blank_inline),
always(null).abstract,
repeat1(Attribute).abstract)))
.map(flatten(1))
repeat1(Attribute).abstract,
),
)
)
.map(flatten(2))
.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"
}
]
}