-
Notifications
You must be signed in to change notification settings - Fork 80
Require = after the id (but not really) #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,6 @@ export default class FluentParser { | |
entries.push(entry); | ||
} | ||
|
||
ps.skipInlineWS(); | ||
ps.skipBlankLines(); | ||
} | ||
|
||
|
@@ -258,12 +257,15 @@ export default class FluentParser { | |
let pattern; | ||
let attrs; | ||
|
||
// XXX Syntax 0.4 compatibility. | ||
// XXX Replace with ps.expectChar('='). | ||
if (ps.currentIs('=')) { | ||
ps.next(); | ||
ps.skipInlineWS(); | ||
ps.skipBlankLines(); | ||
|
||
pattern = this.getPattern(ps); | ||
if (ps.isPeekPatternStart()) { | ||
ps.skipIndent(); | ||
pattern = this.getPattern(ps); | ||
} | ||
} | ||
|
||
if (ps.isPeekNextLineAttributeStart()) { | ||
|
@@ -278,29 +280,27 @@ export default class FluentParser { | |
} | ||
|
||
getAttribute(ps) { | ||
ps.expectIndent(); | ||
ps.expectChar('.'); | ||
|
||
const key = this.getPublicIdentifier(ps); | ||
|
||
ps.skipInlineWS(); | ||
ps.expectChar('='); | ||
ps.skipInlineWS(); | ||
|
||
const value = this.getPattern(ps); | ||
|
||
if (value === undefined) { | ||
throw new ParseError('E0006', 'value'); | ||
if (ps.isPeekPatternStart()) { | ||
ps.skipIndent(); | ||
const value = this.getPattern(ps); | ||
return new AST.Attribute(key, value); | ||
} | ||
|
||
return new AST.Attribute(key, value); | ||
throw new ParseError('E0006', 'value'); | ||
} | ||
|
||
getAttributes(ps) { | ||
const attrs = []; | ||
|
||
while (true) { | ||
ps.expectIndent(); | ||
|
||
const attr = this.getAttribute(ps); | ||
attrs.push(attr); | ||
|
||
|
@@ -349,6 +349,8 @@ export default class FluentParser { | |
} | ||
|
||
getVariant(ps, hasDefault) { | ||
ps.expectIndent(); | ||
|
||
let defaultIndex = false; | ||
|
||
if (ps.currentIs('*')) { | ||
|
@@ -366,24 +368,20 @@ export default class FluentParser { | |
|
||
ps.expectChar(']'); | ||
|
||
ps.skipInlineWS(); | ||
|
||
const value = this.getPattern(ps); | ||
|
||
if (!value) { | ||
throw new ParseError('E0006', 'value'); | ||
if (ps.isPeekPatternStart()) { | ||
ps.skipIndent(); | ||
const value = this.getPattern(ps); | ||
return new AST.Variant(key, value, defaultIndex); | ||
} | ||
|
||
return new AST.Variant(key, value, defaultIndex); | ||
throw new ParseError('E0006', 'value'); | ||
} | ||
|
||
getVariants(ps) { | ||
const variants = []; | ||
let hasDefault = false; | ||
|
||
while (true) { | ||
ps.expectIndent(); | ||
|
||
const variant = this.getVariant(ps, hasDefault); | ||
|
||
if (variant.default) { | ||
|
@@ -459,18 +457,12 @@ export default class FluentParser { | |
const elements = []; | ||
ps.skipInlineWS(); | ||
|
||
// Special-case: trim leading whitespace and newlines. | ||
if (ps.isPeekNextNonBlankLinePattern()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed any more because calls to |
||
ps.skipBlankLines(); | ||
ps.skipInlineWS(); | ||
} | ||
|
||
let ch; | ||
while ((ch = ps.current())) { | ||
|
||
// The end condition for getPattern's while loop is a newline | ||
// which is not followed by a valid pattern continuation. | ||
if (ch === '\n' && !ps.isPeekNextNonBlankLinePattern()) { | ||
if (ch === '\n' && !ps.isPeekNextLinePatternStart()) { | ||
break; | ||
} | ||
|
||
|
@@ -491,13 +483,12 @@ export default class FluentParser { | |
|
||
let ch; | ||
while ((ch = ps.current())) { | ||
|
||
if (ch === '{') { | ||
return new AST.TextElement(buffer); | ||
} | ||
|
||
if (ch === '\n') { | ||
if (!ps.isPeekNextNonBlankLinePattern()) { | ||
if (!ps.isPeekNextLinePatternStart()) { | ||
return new AST.TextElement(buffer); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
fluent-syntax/test/fixtures_behavior/attribute_with_empty_pattern.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
key = Value | ||
.label = | ||
//~ ERROR E0006, pos 24, args "value" |
7 changes: 6 additions & 1 deletion
7
fluent-syntax/test/fixtures_behavior/variant_with_empty_pattern.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
key = { | ||
key1 = { | ||
*[one] {""} | ||
} | ||
|
||
err1 = { | ||
*[one] | ||
} | ||
//~ ERROR E0006, pos 51, args "value" |
17 changes: 17 additions & 0 deletions
17
fluent-syntax/test/fixtures_structure/attribute_with_empty_pattern.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
key1 = Value 1 | ||
.attr = | ||
|
||
key2 = | ||
.attr = | ||
|
||
key3 = | ||
.attr1 = Attr 1 | ||
.attr2 = | ||
|
||
key4 = | ||
.attr1 = | ||
.attr2 = Attr 2 | ||
|
||
key5 = | ||
.attr1 = | ||
.attr2 = |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the
isPeekNextLine*
methods only consider non-blank lines so I renamed this one to match the naming of all others.