Skip to content

Commit

Permalink
Change line endings in comments to line_end (#219)
Browse files Browse the repository at this point in the history
The /.*/ regex doesn't match any of the line endings recognized by the
JS RegExp engine, i.e. \n, \r, \u2028, \u2029. These are different from
the line endings supported by the rest of the Fluent Syntax. This change
unifies the line endings in all grammar productions.
  • Loading branch information
stasm authored Nov 22, 2018
1 parent 392a01d commit 2d224cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Term ::= "-" Identifier blank_inline? "=" blank_inline? Value Att

/* Adjacent comment lines of the same comment type are joined together during
* the AST construction. */
CommentLine ::= ("###" | "##" | "#") ("\u0020" /.*/)? line_end
CommentLine ::= ("###" | "##" | "#") ("\u0020" comment_char*)? line_end
comment_char ::= any_char - line_end

/* Junk represents unparsed content.
*
Expand Down
8 changes: 7 additions & 1 deletion syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ let CommentLine = defer(() =>
maybe(
sequence(
string(" "),
regex(/.*/).abstract)),
repeat(comment_char)
.map(join).abstract)),
line_end)
.map(flatten(1))
.map(keep_abstract)
.chain(list_into(FTL.Comment)));

let comment_char = defer(() =>
and(
not(line_end),
any_char));

/* -------------------------------------------------------------------------- */
/* Junk represents unparsed content.
*
Expand Down
5 changes: 2 additions & 3 deletions test/fixtures/cr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"type": "Resource",
"body": [
{
"type": "Junk",
"annotations": [],
"content": "### This entire file uses CR as EOL.\r\rerr01 = Value 01\rerr02 = Value 02\r\rerr03 =\r\r Value 03\r Continued\r\r .title = Title\r\rerr04 = { \"str\r\rerr05 = { $sel -> }\r"
"type": "ResourceComment",
"content": "This entire file uses CR as EOL.\r\rerr01 = Value 01\rerr02 = Value 02\r\rerr03 =\r\r Value 03\r Continued\r\r .title = Title\r\rerr04 = { \"str\r\rerr05 = { $sel -> }\r"
}
]
}

0 comments on commit 2d224cb

Please sign in to comment.