diff --git a/spec/fluent.ebnf b/spec/fluent.ebnf index f253cb7..e6b4322 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 2943a24..f2fb95d 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" } ] }