Skip to content

Commit 1782ee1

Browse files
authored
Merge pull request #148 from stasm/0.4.x-update-parser
Backport MessageContext parser changes from fluent 0.6.0
2 parents beabada + b468110 commit 1782ee1

30 files changed

+335
-701
lines changed

compat_config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default {
1313
],
1414
'plugins': [
1515
'external-helpers',
16+
'babel-plugin-optimize-starts-with',
1617
['babel-plugin-transform-builtin-extend', {
1718
globals: ['Error']
1819
}]

fluent-syntax/src/ast.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@ export class Entry extends SyntaxNode {
4040
}
4141

4242
export class Message extends Entry {
43-
constructor(id, value = null, attributes = [], tags = [], comment = null) {
43+
constructor(id, value = null, attributes = [], comment = null) {
4444
super();
4545
this.type = 'Message';
4646
this.id = id;
4747
this.value = value;
4848
this.attributes = attributes;
49-
this.tags = tags;
5049
this.comment = comment;
5150
}
5251
}
@@ -159,14 +158,6 @@ export class Attribute extends SyntaxNode {
159158
}
160159
}
161160

162-
export class Tag extends SyntaxNode {
163-
constructor(name) {
164-
super();
165-
this.type = 'Tag';
166-
this.name = name;
167-
}
168-
}
169-
170161
export class Variant extends SyntaxNode {
171162
constructor(key, value, def = false) {
172163
super();

fluent-syntax/src/errors.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ function getErrorMessage(code, args) {
3939
return 'Expected one of the variants to be marked as default (*)';
4040
case 'E0011':
4141
return 'Expected at least one variant after "->"';
42-
case 'E0012':
43-
return 'Tags cannot be added to messages with attributes';
4442
case 'E0013':
4543
return 'Expected variant key';
4644
case 'E0014':

fluent-syntax/src/ftlstream.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ export class FTLParserStream extends ParserStream {
205205

206206
if (this.currentPeekIs('}') ||
207207
this.currentPeekIs('.') ||
208-
this.currentPeekIs('#') ||
209208
this.currentPeekIs('[') ||
210209
this.currentPeekIs('*')) {
211210
this.resetPeek();
@@ -216,33 +215,6 @@ export class FTLParserStream extends ParserStream {
216215
return true;
217216
}
218217

219-
isPeekNextLineTagStart() {
220-
if (!this.currentPeekIs('\n')) {
221-
return false;
222-
}
223-
224-
this.peek();
225-
226-
this.peekBlankLines();
227-
228-
const ptr = this.getPeekIndex();
229-
230-
this.peekInlineWS();
231-
232-
if (this.getPeekIndex() - ptr === 0) {
233-
this.resetPeek();
234-
return false;
235-
}
236-
237-
if (this.currentPeekIs('#')) {
238-
this.resetPeek();
239-
return true;
240-
}
241-
242-
this.resetPeek();
243-
return false;
244-
}
245-
246218
skipToNextEntryStart() {
247219
while (this.ch) {
248220
if (this.currentIs('\n') && !this.peekCharIs('\n')) {

fluent-syntax/src/parser.js

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class FluentParser {
4242

4343
// Poor man's decorators.
4444
[
45-
'getComment', 'getSection', 'getMessage', 'getAttribute', 'getTag',
45+
'getComment', 'getSection', 'getMessage', 'getAttribute',
4646
'getIdentifier', 'getVariant', 'getSymbol', 'getNumber', 'getPattern',
4747
'getTextElement', 'getPlaceable', 'getExpression',
4848
'getSelectorExpression', 'getCallArg', 'getString', 'getLiteral',
@@ -189,7 +189,6 @@ export default class FluentParser {
189189

190190
let pattern;
191191
let attrs;
192-
let tags;
193192

194193
if (ps.currentIs('=')) {
195194
ps.next();
@@ -203,18 +202,11 @@ export default class FluentParser {
203202
attrs = this.getAttributes(ps);
204203
}
205204

206-
if (ps.isPeekNextLineTagStart()) {
207-
if (attrs !== undefined) {
208-
throw new ParseError('E0012');
209-
}
210-
tags = this.getTags(ps);
211-
}
212-
213205
if (pattern === undefined && attrs === undefined) {
214206
throw new ParseError('E0005', id.name);
215207
}
216208

217-
return new AST.Message(id, pattern, attrs, tags, comment);
209+
return new AST.Message(id, pattern, attrs, comment);
218210
}
219211

220212
getAttribute(ps) {
@@ -251,28 +243,6 @@ export default class FluentParser {
251243
return attrs;
252244
}
253245

254-
getTag(ps) {
255-
ps.expectChar('#');
256-
const symb = this.getSymbol(ps);
257-
return new AST.Tag(symb);
258-
}
259-
260-
getTags(ps) {
261-
const tags = [];
262-
263-
while (true) {
264-
ps.expectIndent();
265-
266-
const tag = this.getTag(ps);
267-
tags.push(tag);
268-
269-
if (!ps.isPeekNextLineTagStart()) {
270-
break;
271-
}
272-
}
273-
return tags;
274-
}
275-
276246
getIdentifier(ps) {
277247
let name = '';
278248

fluent-syntax/src/serializer.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ function serializeMessage(message) {
9292
parts.push(serializeValue(message.value));
9393
}
9494

95-
for (const tag of message.tags) {
96-
parts.push(serializeTag(tag));
97-
}
98-
9995
for (const attribute of message.attributes) {
10096
parts.push(serializeAttribute(attribute));
10197
}
@@ -105,12 +101,6 @@ function serializeMessage(message) {
105101
}
106102

107103

108-
function serializeTag(tag) {
109-
const name = serializeSymbol(tag.name);
110-
return `\n #${name}`;
111-
}
112-
113-
114104
function serializeAttribute(attribute) {
115105
const id = serializeIdentifier(attribute.id);
116106
const value = indent(serializeValue(attribute.value));

fluent-syntax/test/entry_test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ suite('Parse entry', function() {
1919
"end": 9,
2020
"type": "Span"
2121
},
22-
"tags": [],
2322
"value": {
2423
"elements": [
2524
{
@@ -72,7 +71,6 @@ suite('Serialize entry', function() {
7271
"end": 9,
7372
"type": "Span"
7473
},
75-
"tags": [],
7674
"value": {
7775
"elements": [
7876
{

fluent-syntax/test/fixtures_behavior/second_tag_starts_from_nl.ftl

Lines changed: 0 additions & 4 deletions
This file was deleted.

fluent-syntax/test/fixtures_behavior/tag_and_attribute_together.ftl

Lines changed: 0 additions & 4 deletions
This file was deleted.

fluent-syntax/test/fixtures_behavior/tag_starts_from_nl.ftl

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)