From 6f551e5009322570ebb469234694ef4af02e49af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Wed, 11 Jul 2018 17:27:56 +0200 Subject: [PATCH] WIP Broken Attributes should not break the whole Entry --- fluent-syntax/src/parser.js | 11 +++++++++-- fluent-syntax/src/stream.js | 4 ++++ fluent-syntax/test/reference_test.js | 5 ----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fluent-syntax/src/parser.js b/fluent-syntax/src/parser.js index 6a5ea335c..314e05566 100644 --- a/fluent-syntax/src/parser.js +++ b/fluent-syntax/src/parser.js @@ -287,9 +287,16 @@ export default class FluentParser { const attrs = []; while (true) { + const lineStart = ps.getIndex() + 1; ps.expectIndent(); - const attr = this.getAttribute(ps); - attrs.push(attr); + + try { + const attr = this.getAttribute(ps); + attrs.push(attr); + } catch (err) { + ps.setIndex(lineStart); + return attrs; + } if (!ps.isPeekNextLineAttributeStart()) { break; diff --git a/fluent-syntax/src/stream.js b/fluent-syntax/src/stream.js index 0eb281c5f..643ae6cb6 100644 --- a/fluent-syntax/src/stream.js +++ b/fluent-syntax/src/stream.js @@ -86,6 +86,10 @@ export class ParserStream { return this.index; } + setIndex(idx) { + return this.index = idx; + } + getPeekIndex() { return this.peekIndex; } diff --git a/fluent-syntax/test/reference_test.js b/fluent-syntax/test/reference_test.js index b3c2a36c2..7588eb516 100644 --- a/fluent-syntax/test/reference_test.js +++ b/fluent-syntax/test/reference_test.js @@ -34,11 +34,6 @@ readdir(fixtures, function(err, filenames) { // There's even a behavior fixture for this; it must have been a // deliberate decision. "select_expressions.ftl", - - // Broken Attributes break the entire Entry right now. - // https://github.com/projectfluent/fluent.js/issues/237 - "leading_dots.ftl", - "variant_lists.ftl" ]; for (const filename of ftlnames) {