From 9a23acd4ce131138616fc6a1c27dbfa57dd472e5 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 8 Feb 2023 17:54:36 +0200 Subject: [PATCH] Treat tab as text, not whitespace --- .../test/fixtures_reference/tab.json | 12 +++++ fluent-syntax/src/parser.ts | 2 +- fluent-syntax/test/fixtures_reference/tab.ftl | 7 +++ .../test/fixtures_reference/tab.json | 53 ++++++++++++++++++- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/fluent-bundle/test/fixtures_reference/tab.json b/fluent-bundle/test/fixtures_reference/tab.json index 3cc8f40a2..32ec1fea0 100644 --- a/fluent-bundle/test/fixtures_reference/tab.json +++ b/fluent-bundle/test/fixtures_reference/tab.json @@ -11,6 +11,18 @@ "This line is indented by 4 spaces," ], "attributes": {} + }, + { + "id": "key05", + "value": "\t", + "attributes": {} + }, + { + "id": "key06", + "value": null, + "attributes": { + "attr": "\t\t" + } } ] } diff --git a/fluent-syntax/src/parser.ts b/fluent-syntax/src/parser.ts index 7d1da66f2..82448017b 100644 --- a/fluent-syntax/src/parser.ts +++ b/fluent-syntax/src/parser.ts @@ -6,7 +6,7 @@ import type { Resource, Entry } from "./ast.js"; import { EOF, EOL, FluentParserStream } from "./stream.js"; import { ParseError } from "./errors.js"; -const trailingWSRe = /[ \t\n\r]+$/; +const trailingWSRe = /[ \n\r]+$/; type ParseFn = // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/fluent-syntax/test/fixtures_reference/tab.ftl b/fluent-syntax/test/fixtures_reference/tab.ftl index 4b23ad87c..4b4e47de8 100644 --- a/fluent-syntax/test/fixtures_reference/tab.ftl +++ b/fluent-syntax/test/fixtures_reference/tab.ftl @@ -12,3 +12,10 @@ key03 = key04 = This line is indented by 4 spaces, whereas this line by 1 tab. + +# OK (value is a single tab) +key05 = + +# OK (attribute value is two tabs) +key06 = + .attr = diff --git a/fluent-syntax/test/fixtures_reference/tab.json b/fluent-syntax/test/fixtures_reference/tab.json index 714eb947e..0c0c65a14 100644 --- a/fluent-syntax/test/fixtures_reference/tab.json +++ b/fluent-syntax/test/fixtures_reference/tab.json @@ -64,7 +64,58 @@ { "type": "Junk", "annotations": [], - "content": "\twhereas this line by 1 tab.\n" + "content": "\twhereas this line by 1 tab.\n\n" + }, + { + "type": "Message", + "id": { + "type": "Identifier", + "name": "key05" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "\t" + } + ] + }, + "attributes": [], + "comment": { + "type": "Comment", + "content": "OK (value is a single tab)" + } + }, + { + "type": "Message", + "id": { + "type": "Identifier", + "name": "key06" + }, + "value": null, + "attributes": [ + { + "type": "Attribute", + "id": { + "type": "Identifier", + "name": "attr" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "\t\t" + } + ] + } + } + ], + "comment": { + "type": "Comment", + "content": "OK (attribute value is two tabs)" + } } ] }