Skip to content

Remove tags #110

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 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions fluent-syntax/src/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ export class Entry extends SyntaxNode {
}

export class Message extends Entry {
constructor(id, value = null, attributes = [], tags = [], comment = null) {
constructor(id, value = null, attributes = [], comment = null) {
super();
this.type = 'Message';
this.id = id;
this.value = value;
this.attributes = attributes;
this.tags = tags;
this.comment = comment;
}
}
Expand Down Expand Up @@ -159,14 +158,6 @@ export class Attribute extends SyntaxNode {
}
}

export class Tag extends SyntaxNode {
constructor(name) {
super();
this.type = 'Tag';
this.name = name;
}
}

export class Variant extends SyntaxNode {
constructor(key, value, def = false) {
super();
Expand Down
2 changes: 0 additions & 2 deletions fluent-syntax/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ function getErrorMessage(code, args) {
return 'Expected one of the variants to be marked as default (*)';
case 'E0011':
return 'Expected at least one variant after "->"';
case 'E0012':
return 'Tags cannot be added to messages with attributes';
case 'E0013':
return 'Expected variant key';
case 'E0014':
Expand Down
28 changes: 0 additions & 28 deletions fluent-syntax/src/ftlstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export class FTLParserStream extends ParserStream {

if (this.currentPeekIs('}') ||
this.currentPeekIs('.') ||
this.currentPeekIs('#') ||
this.currentPeekIs('[') ||
this.currentPeekIs('*')) {
this.resetPeek();
Expand All @@ -216,33 +215,6 @@ export class FTLParserStream extends ParserStream {
return true;
}

isPeekNextLineTagStart() {
if (!this.currentPeekIs('\n')) {
return false;
}

this.peek();

this.peekBlankLines();

const ptr = this.getPeekIndex();

this.peekInlineWS();

if (this.getPeekIndex() - ptr === 0) {
this.resetPeek();
return false;
}

if (this.currentPeekIs('#')) {
this.resetPeek();
return true;
}

this.resetPeek();
return false;
}

skipToNextEntryStart() {
while (this.ch) {
if (this.currentIs('\n') && !this.peekCharIs('\n')) {
Expand Down
34 changes: 2 additions & 32 deletions fluent-syntax/src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class FluentParser {

// Poor man's decorators.
[
'getComment', 'getSection', 'getMessage', 'getAttribute', 'getTag',
'getComment', 'getSection', 'getMessage', 'getAttribute',
'getIdentifier', 'getVariant', 'getSymbol', 'getNumber', 'getPattern',
'getTextElement', 'getPlaceable', 'getExpression',
'getSelectorExpression', 'getCallArg', 'getString', 'getLiteral',
Expand Down Expand Up @@ -189,7 +189,6 @@ export default class FluentParser {

let pattern;
let attrs;
let tags;

if (ps.currentIs('=')) {
ps.next();
Expand All @@ -203,18 +202,11 @@ export default class FluentParser {
attrs = this.getAttributes(ps);
}

if (ps.isPeekNextLineTagStart()) {
if (attrs !== undefined) {
throw new ParseError('E0012');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove E0012 from errors.js.

}
tags = this.getTags(ps);
}

if (pattern === undefined && attrs === undefined) {
throw new ParseError('E0005', id.name);
}

return new AST.Message(id, pattern, attrs, tags, comment);
return new AST.Message(id, pattern, attrs, comment);
}

getAttribute(ps) {
Expand Down Expand Up @@ -251,28 +243,6 @@ export default class FluentParser {
return attrs;
}

getTag(ps) {
ps.expectChar('#');
const symb = this.getSymbol(ps);
return new AST.Tag(symb);
}

getTags(ps) {
const tags = [];

while (true) {
ps.expectIndent();

const tag = this.getTag(ps);
tags.push(tag);

if (!ps.isPeekNextLineTagStart()) {
break;
}
}
return tags;
}

getIdentifier(ps) {
let name = '';

Expand Down
10 changes: 0 additions & 10 deletions fluent-syntax/src/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ function serializeMessage(message) {
parts.push(serializeValue(message.value));
}

for (const tag of message.tags) {
parts.push(serializeTag(tag));
}

for (const attribute of message.attributes) {
parts.push(serializeAttribute(attribute));
}
Expand All @@ -105,12 +101,6 @@ function serializeMessage(message) {
}


function serializeTag(tag) {
const name = serializeSymbol(tag.name);
return `\n #${name}`;
}


function serializeAttribute(attribute) {
const id = serializeIdentifier(attribute.id);
const value = indent(serializeValue(attribute.value));
Expand Down
2 changes: 0 additions & 2 deletions fluent-syntax/test/entry_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ suite('Parse entry', function() {
"end": 9,
"type": "Span"
},
"tags": [],
"value": {
"elements": [
{
Expand Down Expand Up @@ -72,7 +71,6 @@ suite('Serialize entry', function() {
"end": 9,
"type": "Span"
},
"tags": [],
"value": {
"elements": [
{
Expand Down

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions fluent-syntax/test/fixtures_behavior/tag_starts_from_nl.ftl

This file was deleted.

7 changes: 0 additions & 7 deletions fluent-syntax/test/fixtures_structure/elements_indent.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,3 @@ foo = Foo
bar = Bar
.attr1 = Bar Attr 1
.attr2 = Bar Attr 2

baz = Baz
#tag

qux = Qux
#tag1
#tag2
150 changes: 3 additions & 147 deletions fluent-syntax/test/fixtures_structure/elements_indent.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
}
},
"attributes": [],
"tags": [],
"comment": null,
"span": {
"type": "Span",
Expand Down Expand Up @@ -132,7 +131,6 @@
}
}
],
"tags": [],
"comment": null,
"span": {
"type": "Span",
Expand All @@ -155,160 +153,18 @@
}
}
],
"content": ".attr2 = Bar Attr 2\n\n",
"content": ".attr2 = Bar Attr 2\n",
"span": {
"type": "Span",
"start": 62,
"end": 83
}
},
{
"type": "Message",
"annotations": [],
"id": {
"type": "Identifier",
"name": "baz",
"span": {
"type": "Span",
"start": 83,
"end": 86
}
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Baz",
"span": {
"type": "Span",
"start": 89,
"end": 92
}
}
],
"span": {
"type": "Span",
"start": 89,
"end": 92
}
},
"attributes": [],
"tags": [],
"comment": null,
"span": {
"type": "Span",
"start": 83,
"end": 92
}
},
{
"type": "Junk",
"annotations": [
{
"type": "Annotation",
"code": "E0002",
"args": [],
"message": "Expected an entry start",
"span": {
"type": "Span",
"start": 93,
"end": 93
}
}
],
"content": "#tag\n\n",
"span": {
"type": "Span",
"start": 93,
"end": 99
}
},
{
"type": "Message",
"annotations": [],
"id": {
"type": "Identifier",
"name": "qux",
"span": {
"type": "Span",
"start": 99,
"end": 102
}
},
"value": {
"type": "Pattern",
"elements": [
{
"type": "TextElement",
"value": "Qux",
"span": {
"type": "Span",
"start": 105,
"end": 108
}
}
],
"span": {
"type": "Span",
"start": 105,
"end": 108
}
},
"attributes": [],
"tags": [
{
"type": "Tag",
"name": {
"type": "Symbol",
"name": "tag1",
"span": {
"type": "Span",
"start": 114,
"end": 118
}
},
"span": {
"type": "Span",
"start": 113,
"end": 118
}
}
],
"comment": null,
"span": {
"type": "Span",
"start": 99,
"end": 118
}
},
{
"type": "Junk",
"annotations": [
{
"type": "Annotation",
"code": "E0002",
"args": [],
"message": "Expected an entry start",
"span": {
"type": "Span",
"start": 119,
"end": 119
}
}
],
"content": "#tag2\n",
"span": {
"type": "Span",
"start": 119,
"end": 125
"end": 82
}
}
],
"comment": null,
"span": {
"type": "Span",
"start": 0,
"end": 125
"end": 82
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
}
},
"attributes": [],
"tags": [],
"comment": null,
"span": {
"type": "Span",
Expand Down
Loading