Skip to content

Commit

Permalink
Merge pull request #140 from stasm/fix-compare-locales
Browse files Browse the repository at this point in the history
 Parser fixes required to update compare-locales to 0.6
  • Loading branch information
stasm authored Jan 31, 2018
2 parents 24585e6 + 59f8018 commit 7bc49e1
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 26 deletions.
26 changes: 16 additions & 10 deletions fluent-syntax/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default class FluentParser {
'getVariant', 'getVariantName', 'getNumber', 'getPattern',
'getTextElement', 'getPlaceable', 'getExpression',
'getSelectorExpression', 'getCallArg', 'getString', 'getLiteral',
'getGroupCommentFromSection'
].forEach(
name => this[name] = withSpan(this[name])
);
Expand Down Expand Up @@ -133,11 +134,12 @@ export default class FluentParser {
}

if (ps.currentIs('[')) {
this.skipSection(ps);
if (comment) {
return new AST.GroupComment(comment.content);
const groupComment = this.getGroupCommentFromSection(ps, comment);
if (comment && this.withSpans) {
// The Group Comment should start where the section comment starts.
groupComment.span.start = comment.span.start;
}
return null;
return groupComment;
}

if (ps.isEntryIDStart() && (!comment || comment.type === 'Comment')) {
Expand Down Expand Up @@ -233,7 +235,7 @@ export default class FluentParser {
return new Comment(content);
}

skipSection(ps) {
getGroupCommentFromSection(ps, comment) {
ps.expectChar('[');
ps.expectChar('[');

Expand All @@ -246,8 +248,13 @@ export default class FluentParser {
ps.expectChar(']');
ps.expectChar(']');

ps.skipInlineWS();
ps.next();
if (comment) {
return new AST.GroupComment(comment.content);
}

// A Section without a comment is like an empty Group Comment. Semantically
// it ends the previous group and starts a new one.
return new AST.GroupComment('');
}

getMessage(ps, comment) {
Expand Down Expand Up @@ -289,7 +296,6 @@ export default class FluentParser {
}

getAttribute(ps) {
ps.expectIndent();
ps.expectChar('.');

const key = this.getIdentifier(ps);
Expand All @@ -310,6 +316,7 @@ export default class FluentParser {
const attrs = [];

while (true) {
ps.expectIndent();
const attr = this.getAttribute(ps);
attrs.push(attr);

Expand Down Expand Up @@ -353,8 +360,6 @@ export default class FluentParser {
}

getVariant(ps, hasDefault) {
ps.expectIndent();

let defaultIndex = false;

if (ps.currentIs('*')) {
Expand Down Expand Up @@ -386,6 +391,7 @@ export default class FluentParser {
let hasDefault = false;

while (true) {
ps.expectIndent();
const variant = this.getVariant(ps, hasDefault);

if (variant.default) {
Expand Down
2 changes: 1 addition & 1 deletion fluent-syntax/test/fixtures_structure/elements_indent.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
},
"span": {
"type": "Span",
"start": 37,
"start": 42,
"end": 61
}
}
Expand Down
13 changes: 12 additions & 1 deletion fluent-syntax/test/fixtures_structure/section.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"type": "Resource",
"body": [],
"body": [
{
"type": "GroupComment",
"annotations": [],
"content": "",
"span": {
"type": "Span",
"start": 1,
"end": 24
}
}
],
"span": {
"type": "Span",
"start": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Comment
[[ Section ]]
20 changes: 20 additions & 0 deletions fluent-syntax/test/fixtures_structure/section_with_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "Resource",
"body": [
{
"type": "GroupComment",
"annotations": [],
"content": "Comment",
"span": {
"type": "Span",
"start": 0,
"end": 24
}
}
],
"span": {
"type": "Span",
"start": 0,
"end": 25
}
}
8 changes: 4 additions & 4 deletions fluent-syntax/test/fixtures_structure/sparse-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
},
"span": {
"type": "Span",
"start": 23,
"start": 30,
"end": 47
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@
},
"span": {
"type": "Span",
"start": 102,
"start": 110,
"end": 125
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@
"default": false,
"span": {
"type": "Span",
"start": 152,
"start": 164,
"end": 173
}
},
Expand Down Expand Up @@ -304,7 +304,7 @@
"default": true,
"span": {
"type": "Span",
"start": 173,
"start": 186,
"end": 196
}
}
Expand Down
6 changes: 3 additions & 3 deletions fluent-syntax/test/fixtures_structure/syntax_zero_four.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"span": {
"type": "Span",
"start": 4,
"start": 9,
"end": 24
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@
},
"span": {
"type": "Span",
"start": 30,
"start": 35,
"end": 50
}
},
Expand Down Expand Up @@ -141,7 +141,7 @@
},
"span": {
"type": "Span",
"start": 50,
"start": 55,
"end": 70
}
}
Expand Down
12 changes: 6 additions & 6 deletions fluent-syntax/test/fixtures_structure/term.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"default": true,
"span": {
"type": "Span",
"start": 19,
"start": 27,
"end": 48
}
},
Expand Down Expand Up @@ -92,7 +92,7 @@
"default": false,
"span": {
"type": "Span",
"start": 48,
"start": 57,
"end": 78
}
}
Expand Down Expand Up @@ -149,7 +149,7 @@
},
"span": {
"type": "Span",
"start": 84,
"start": 89,
"end": 108
}
}
Expand Down Expand Up @@ -347,7 +347,7 @@
"default": false,
"span": {
"type": "Span",
"start": 220,
"start": 229,
"end": 289
}
},
Expand Down Expand Up @@ -409,7 +409,7 @@
"default": false,
"span": {
"type": "Span",
"start": 289,
"start": 298,
"end": 358
}
},
Expand Down Expand Up @@ -480,7 +480,7 @@
"default": true,
"span": {
"type": "Span",
"start": 358,
"start": 366,
"end": 431
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"default": true,
"span": {
"type": "Span",
"start": 17,
"start": 25,
"end": 36
}
}
Expand Down
1 change: 1 addition & 0 deletions fluent/test/fixtures_structure/section_with_comment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit 7bc49e1

Please sign in to comment.