From f195581665a65b1f1b3b651d537496fc590e7607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Thu, 20 Apr 2017 11:48:36 +0200 Subject: [PATCH 1/2] Fixtures for parser bug: placeables should be allowed at the beginning and end of line --- .../placeable_at_line_extremes.ftl | 8 ++++ .../fixtures_structure/placeable_at_eol.ftl | 4 ++ .../fixtures_structure/placeable_at_eol.json | 42 +++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 fluent-syntax/test/fixtures_behavior/placeable_at_line_extremes.ftl create mode 100644 fluent-syntax/test/fixtures_structure/placeable_at_eol.ftl create mode 100644 fluent-syntax/test/fixtures_structure/placeable_at_eol.json diff --git a/fluent-syntax/test/fixtures_behavior/placeable_at_line_extremes.ftl b/fluent-syntax/test/fixtures_behavior/placeable_at_line_extremes.ftl new file mode 100644 index 000000000..64389db44 --- /dev/null +++ b/fluent-syntax/test/fixtures_behavior/placeable_at_line_extremes.ftl @@ -0,0 +1,8 @@ +key1 = + { foo } + +key2 = + Foo { foo } + +key3 = + { foo } Foo diff --git a/fluent-syntax/test/fixtures_structure/placeable_at_eol.ftl b/fluent-syntax/test/fixtures_structure/placeable_at_eol.ftl new file mode 100644 index 000000000..37665cc24 --- /dev/null +++ b/fluent-syntax/test/fixtures_structure/placeable_at_eol.ftl @@ -0,0 +1,4 @@ +key = + A multiline message with a { placeable } + at the end of line. The message should + consist of three lines of text. diff --git a/fluent-syntax/test/fixtures_structure/placeable_at_eol.json b/fluent-syntax/test/fixtures_structure/placeable_at_eol.json new file mode 100644 index 000000000..5da1469a8 --- /dev/null +++ b/fluent-syntax/test/fixtures_structure/placeable_at_eol.json @@ -0,0 +1,42 @@ +{ + "type": "Resource", + "body": [ + { + "type": "Message", + "span": { + "type": "Span", + "start": 0, + "end": 130 + }, + "annotations": [], + "id": { + "type": "Identifier", + "name": "key" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "A multiline message with a " + }, + { + "type": "MessageReference", + "id": { + "type": "Identifier", + "name": "placeable" + } + }, + { + "type": "TextElement", + "value": "\nat the end of line. The message should\nconsist of three lines of text." + } + ] + }, + "attributes": null, + "tags": null, + "comment": null + } + ], + "comment": null +} From b7ee91fa3ade83ac3a3f8a13350fa0bd1e317693 Mon Sep 17 00:00:00 2001 From: Zibi Braniecki Date: Wed, 26 Apr 2017 04:49:44 +0200 Subject: [PATCH 2/2] Fix placeables in pattern at boundries. --- fluent-syntax/src/ftlstream.js | 3 +-- fluent-syntax/src/parser.js | 5 ++--- fluent-syntax/test/serializer_test.js | 13 ------------- fluent/src/parser.js | 2 +- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/fluent-syntax/src/ftlstream.js b/fluent-syntax/src/ftlstream.js index 82aef23ea..3fef5b179 100644 --- a/fluent-syntax/src/ftlstream.js +++ b/fluent-syntax/src/ftlstream.js @@ -173,8 +173,7 @@ export class FTLParserStream extends ParserStream { this.currentPeekIs('.') || this.currentPeekIs('#') || this.currentPeekIs('[') || - this.currentPeekIs('*') || - this.currentPeekIs('{')) { + this.currentPeekIs('*')) { this.resetPeek(); return false; } diff --git a/fluent-syntax/src/parser.js b/fluent-syntax/src/parser.js index 57f5e7f89..92e9ad2da 100644 --- a/fluent-syntax/src/parser.js +++ b/fluent-syntax/src/parser.js @@ -360,11 +360,10 @@ function getPattern(ps) { ps.next(); ps.skipLineWS(); - firstLine = false; - - if (buffer.length !== 0) { + if (!firstLine) { buffer += ch; } + firstLine = false; continue; } else if (ch === '\\') { const ch2 = ps.peek(); diff --git a/fluent-syntax/test/serializer_test.js b/fluent-syntax/test/serializer_test.js index fbe7b2d83..3077a4d6d 100644 --- a/fluent-syntax/test/serializer_test.js +++ b/fluent-syntax/test/serializer_test.js @@ -122,7 +122,6 @@ suite('Serializer', function() { assert.equal(pretty(input), input); }); - // XXX The Parser ignores the new line after the closing brace test.skip('multiline with placeable', function() { const input = ftl` foo = @@ -132,18 +131,6 @@ suite('Serializer', function() { assert.equal(pretty(input), input); }); - test('multiline with placeable (current)', function() { - const input = ftl` - foo = - Foo { bar } - Baz - `; - const output = ftl` - foo = Foo { bar }Baz - `; - assert.equal(pretty(input), output); - }); - test('tag', function() { const input = ftl` foo = Foo diff --git a/fluent/src/parser.js b/fluent/src/parser.js index 8bc52b1a0..a568d8c2f 100644 --- a/fluent/src/parser.js +++ b/fluent/src/parser.js @@ -321,7 +321,7 @@ class RuntimeParser { break; } - if (buffer.length) { + if (buffer.length || content.length) { buffer += '\n'; } ch = this._source[this._index];