From 993d3c8795779b86ed60c406e42f759f9384445c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Fri, 16 Nov 2018 13:49:43 +0100 Subject: [PATCH] Change line endings in comments to line_end 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. --- spec/fluent.ebnf | 3 ++- syntax/grammar.mjs | 8 +++++++- test/fixtures/cr.json | 5 ++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/fluent.ebnf b/spec/fluent.ebnf index e511445..6b5fabc 100644 --- a/spec/fluent.ebnf +++ b/spec/fluent.ebnf @@ -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. * diff --git a/syntax/grammar.mjs b/syntax/grammar.mjs index 2cdeb76..5d8e57c 100644 --- a/syntax/grammar.mjs +++ b/syntax/grammar.mjs @@ -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. * diff --git a/test/fixtures/cr.json b/test/fixtures/cr.json index afec811..44eab75 100644 --- a/test/fixtures/cr.json +++ b/test/fixtures/cr.json @@ -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" } ] }