From 0f8809fb0d4d915d201410d851bf0ff1f7e4e275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Thu, 26 Jul 2018 09:32:22 +0200 Subject: [PATCH 1/3] Restrict variant keys to Identifiers and NumberLiterals --- spec/fluent.ebnf | 6 +- syntax/ast.mjs | 7 -- syntax/grammar.mjs | 27 +---- test/fixtures/leading_dots.json | 4 +- test/fixtures/member_expressions.json | 2 +- test/fixtures/select_expressions.ftl | 2 +- test/fixtures/select_expressions.json | 12 +- test/fixtures/sparse_entries.json | 4 +- test/fixtures/variant_keys.ftl | 37 ++++++ test/fixtures/variant_keys.json | 156 ++++++++++++++++++++++++++ test/fixtures/variant_lists.json | 10 +- 11 files changed, 212 insertions(+), 55 deletions(-) create mode 100644 test/fixtures/variant_keys.ftl create mode 100644 test/fixtures/variant_keys.json diff --git a/spec/fluent.ebnf b/spec/fluent.ebnf index 48d755b..16697cd 100644 --- a/spec/fluent.ebnf +++ b/spec/fluent.ebnf @@ -77,18 +77,14 @@ SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list variant_list ::= Variant* DefaultVariant Variant* line_end Variant ::= line_end blank? VariantKey blank_inline? Value DefaultVariant ::= line_end blank? "*" VariantKey blank_inline? Value -VariantKey ::= "[" blank? (NumberLiteral | VariantName) blank? "]" -VariantName ::= word (blank word)* +VariantKey ::= "[" blank? (NumberLiteral | Identifier) blank? "]" /* Identifiers */ Identifier ::= identifier TermIdentifier ::= "-" identifier VariableIdentifier ::= "$" identifier Function ::= [A-Z] [A-Z_?-]* - -/* Tokens */ identifier ::= [a-zA-Z] [a-zA-Z0-9_-]* -word ::= (regular_char - backslash - "}" - "{" - "]" - "[" - "=")+ /* Characters */ backslash ::= "\\" diff --git a/syntax/ast.mjs b/syntax/ast.mjs index 6ec6fcc..cec14ff 100644 --- a/syntax/ast.mjs +++ b/syntax/ast.mjs @@ -194,13 +194,6 @@ export class Identifier extends SyntaxNode { } } -export class VariantName extends Identifier { - constructor(name) { - super(name); - this.type = "VariantName"; - } -} - export class BaseComment extends Entry { constructor(content) { super(); diff --git a/syntax/grammar.mjs b/syntax/grammar.mjs index 547abc8..cfb9b2f 100644 --- a/syntax/grammar.mjs +++ b/syntax/grammar.mjs @@ -335,22 +335,11 @@ let VariantKey = defer(() => maybe(blank), either( NumberLiteral, - VariantName), + Identifier), maybe(blank), string("]")) .map(element_at(2))); -let VariantName = defer(() => - sequence( - word, - repeat( - sequence( - blank, - word))) - .map(flatten(2)) - .map(join) - .chain(into(FTL.VariantName))); - /* ----------- */ /* Identifiers */ @@ -380,8 +369,6 @@ let Function = .map(join) .chain(into(FTL.Function)); -/* ------ */ -/* Tokens */ let identifier = sequence( charset("a-zA-Z"), @@ -390,18 +377,6 @@ let identifier = .map(flatten(1)) .map(join); -let word = defer(() => - repeat1( - and( - not(string("=")), - not(string("[")), - not(string("]")), - not(string("{")), - not(string("}")), - not(backslash), - regular_char)) - .map(join)); - /* ---------- */ /* Characters */ diff --git a/test/fixtures/leading_dots.json b/test/fixtures/leading_dots.json index 962a3e5..6459cb5 100644 --- a/test/fixtures/leading_dots.json +++ b/test/fixtures/leading_dots.json @@ -350,7 +350,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -367,7 +367,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "other" }, "value": { diff --git a/test/fixtures/member_expressions.json b/test/fixtures/member_expressions.json index f23f28a..939ff5e 100644 --- a/test/fixtures/member_expressions.json +++ b/test/fixtures/member_expressions.json @@ -22,7 +22,7 @@ } }, "key": { - "type": "VariantName", + "type": "Identifier", "name": "case" } } diff --git a/test/fixtures/select_expressions.ftl b/test/fixtures/select_expressions.ftl index e1c420a..3c54f57 100644 --- a/test/fixtures/select_expressions.ftl +++ b/test/fixtures/select_expressions.ftl @@ -6,7 +6,7 @@ new-messages = valid-selector = { -term.case -> - *[ many words ] value + *[key] value } # ERROR diff --git a/test/fixtures/select_expressions.json b/test/fixtures/select_expressions.json index d13fba6..3dac7c7 100644 --- a/test/fixtures/select_expressions.json +++ b/test/fixtures/select_expressions.json @@ -44,7 +44,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "other" }, "value": { @@ -104,8 +104,8 @@ { "type": "Variant", "key": { - "type": "VariantName", - "name": "many words" + "type": "Identifier", + "name": "key" }, "value": { "type": "Pattern", @@ -156,7 +156,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -202,7 +202,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -220,7 +220,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "two" }, "value": { diff --git a/test/fixtures/sparse_entries.json b/test/fixtures/sparse_entries.json index 549263b..0c4a368 100644 --- a/test/fixtures/sparse_entries.json +++ b/test/fixtures/sparse_entries.json @@ -120,7 +120,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -137,7 +137,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "two" }, "value": { diff --git a/test/fixtures/variant_keys.ftl b/test/fixtures/variant_keys.ftl new file mode 100644 index 0000000..7586d52 --- /dev/null +++ b/test/fixtures/variant_keys.ftl @@ -0,0 +1,37 @@ +-simple-identifier = + { + *[key] value + } + +-identifier-surrounded-by-whitespace = + { + *[ key ] value + } + +-int-number = + { + *[1] value + } + +-float-number = + { + *[3.14] value + } + +# ERROR +-invalid-identifier = + { + *[two words] value + } + +# ERROR +-invalid-int = + { + *[1 apple] value + } + +# ERROR +-invalid-int = + { + *[3.14 apples] value + } diff --git a/test/fixtures/variant_keys.json b/test/fixtures/variant_keys.json new file mode 100644 index 0000000..f85abe6 --- /dev/null +++ b/test/fixtures/variant_keys.json @@ -0,0 +1,156 @@ +{ + "type": "Resource", + "body": [ + { + "type": "Term", + "id": { + "type": "Identifier", + "name": "-simple-identifier" + }, + "value": { + "type": "VariantList", + "variants": [ + { + "type": "Variant", + "key": { + "type": "Identifier", + "name": "key" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "value" + } + ] + }, + "default": true + } + ] + }, + "attributes": [], + "comment": null + }, + { + "type": "Term", + "id": { + "type": "Identifier", + "name": "-identifier-surrounded-by-whitespace" + }, + "value": { + "type": "VariantList", + "variants": [ + { + "type": "Variant", + "key": { + "type": "Identifier", + "name": "key" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "value" + } + ] + }, + "default": true + } + ] + }, + "attributes": [], + "comment": null + }, + { + "type": "Term", + "id": { + "type": "Identifier", + "name": "-int-number" + }, + "value": { + "type": "VariantList", + "variants": [ + { + "type": "Variant", + "key": { + "type": "NumberLiteral", + "value": "1" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "value" + } + ] + }, + "default": true + } + ] + }, + "attributes": [], + "comment": null + }, + { + "type": "Term", + "id": { + "type": "Identifier", + "name": "-float-number" + }, + "value": { + "type": "VariantList", + "variants": [ + { + "type": "Variant", + "key": { + "type": "NumberLiteral", + "value": "3.14" + }, + "value": { + "type": "Pattern", + "elements": [ + { + "type": "TextElement", + "value": "value" + } + ] + }, + "default": true + } + ] + }, + "attributes": [], + "comment": null + }, + { + "type": "Comment", + "content": "ERROR" + }, + { + "type": "Junk", + "annotations": [], + "content": "-invalid-identifier =\n {\n *[two words] value\n }\n" + }, + { + "type": "Comment", + "content": "ERROR" + }, + { + "type": "Junk", + "annotations": [], + "content": "-invalid-int =\n {\n *[1 apple] value\n }\n" + }, + { + "type": "Comment", + "content": "ERROR" + }, + { + "type": "Junk", + "annotations": [], + "content": "-invalid-int =\n {\n *[3.14 apples] value\n }\n" + } + ] +} diff --git a/test/fixtures/variant_lists.json b/test/fixtures/variant_lists.json index 38f08db..9713e09 100644 --- a/test/fixtures/variant_lists.json +++ b/test/fixtures/variant_lists.json @@ -13,7 +13,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "key" }, "value": { @@ -105,7 +105,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -114,7 +114,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "two" }, "value": { @@ -149,7 +149,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "one" }, "value": { @@ -167,7 +167,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Identifier", "name": "two" }, "value": { From 98082d0c552437d41d24ba649eb0aeb8fcb4dc70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Tue, 28 Aug 2018 11:36:59 +0200 Subject: [PATCH 2/3] Add a Name AST node --- spec/fluent.ebnf | 9 +++---- syntax/ast.mjs | 8 +++++++ syntax/grammar.mjs | 13 ++++++---- test/fixtures/leading_dots.json | 14 +++++------ test/fixtures/member_expressions.json | 4 ++-- test/fixtures/messages.json | 14 +++++------ test/fixtures/mixed_entries.json | 2 +- test/fixtures/multiline_values.json | 4 ++-- test/fixtures/select_expressions.json | 12 +++++----- test/fixtures/select_indent.json | 34 +++++++++++++-------------- test/fixtures/sparse_entries.json | 8 +++---- test/fixtures/terms.json | 2 +- test/fixtures/variant_keys.json | 4 ++-- test/fixtures/variant_lists.json | 10 ++++---- test/fixtures/variants_indent.json | 10 ++++---- 15 files changed, 80 insertions(+), 68 deletions(-) diff --git a/spec/fluent.ebnf b/spec/fluent.ebnf index 16697cd..19a0c0a 100644 --- a/spec/fluent.ebnf +++ b/spec/fluent.ebnf @@ -22,7 +22,7 @@ CommentLine ::= ("###" | "##" | "#") ("\u0020" /.*/)? line_end junk_line ::= /.*/ line_end /* Attributes of Messages and Terms. */ -Attribute ::= line_end blank? "." Identifier blank_inline? "=" blank_inline? Pattern +Attribute ::= line_end blank? "." Name blank_inline? "=" blank_inline? Pattern /* Value types: Pattern and VariantList. */ Value ::= Pattern @@ -69,7 +69,7 @@ argument_list ::= (Argument blank? "," blank?)* Argument? Argument ::= NamedArgument | InlineExpression NamedArgument ::= Identifier blank? ":" blank? (StringLiteral | NumberLiteral) -AttributeExpression ::= (MessageReference | TermReference) "." Identifier +AttributeExpression ::= (MessageReference | TermReference) "." Name VariantExpression ::= TermReference VariantKey /* Block Expressions */ @@ -77,10 +77,11 @@ SelectExpression ::= InlineExpression blank? "->" blank_inline? variant_list variant_list ::= Variant* DefaultVariant Variant* line_end Variant ::= line_end blank? VariantKey blank_inline? Value DefaultVariant ::= line_end blank? "*" VariantKey blank_inline? Value -VariantKey ::= "[" blank? (NumberLiteral | Identifier) blank? "]" +VariantKey ::= "[" blank? (NumberLiteral | Name) blank? "]" -/* Identifiers */ +/* Identifiers and Names */ Identifier ::= identifier +Name ::= identifier TermIdentifier ::= "-" identifier VariableIdentifier ::= "$" identifier Function ::= [A-Z] [A-Z_?-]* diff --git a/syntax/ast.mjs b/syntax/ast.mjs index cec14ff..c3b4bb7 100644 --- a/syntax/ast.mjs +++ b/syntax/ast.mjs @@ -194,6 +194,14 @@ export class Identifier extends SyntaxNode { } } +export class Name extends SyntaxNode { + constructor(name) { + super(); + this.type = "Name"; + this.name = name; + } +} + export class BaseComment extends Entry { constructor(content) { super(); diff --git a/syntax/grammar.mjs b/syntax/grammar.mjs index cfb9b2f..a220264 100644 --- a/syntax/grammar.mjs +++ b/syntax/grammar.mjs @@ -99,7 +99,7 @@ let Attribute = defer(() => line_end, maybe(blank), string("."), - Identifier.abstract, + Name.abstract, maybe(blank_inline), string("="), maybe(blank_inline), @@ -275,7 +275,7 @@ let AttributeExpression = defer(() => MessageReference, TermReference).abstract, string("."), - Identifier.abstract) + Name.abstract) .map(keep_abstract) .chain(list_into(FTL.AttributeExpression))); @@ -335,17 +335,20 @@ let VariantKey = defer(() => maybe(blank), either( NumberLiteral, - Identifier), + Name), maybe(blank), string("]")) .map(element_at(2))); -/* ----------- */ -/* Identifiers */ +/* --------------------- */ +/* Identifiers and Names */ let Identifier = defer(() => identifier.chain(into(FTL.Identifier))); +let Name = defer(() => + identifier.chain(into(FTL.Name))); + let TermIdentifier = defer(() => sequence( string("-"), diff --git a/test/fixtures/leading_dots.json b/test/fixtures/leading_dots.json index 6459cb5..2faa53d 100644 --- a/test/fixtures/leading_dots.json +++ b/test/fixtures/leading_dots.json @@ -200,7 +200,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "Value" }, "value": { @@ -252,7 +252,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "accesskey" }, "value": { @@ -279,7 +279,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attribute" }, "value": { @@ -306,7 +306,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attribute" }, "value": { @@ -350,7 +350,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -367,7 +367,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "other" }, "value": { @@ -434,7 +434,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attribute" }, "value": { diff --git a/test/fixtures/member_expressions.json b/test/fixtures/member_expressions.json index 939ff5e..fa14ccf 100644 --- a/test/fixtures/member_expressions.json +++ b/test/fixtures/member_expressions.json @@ -22,7 +22,7 @@ } }, "key": { - "type": "Identifier", + "type": "Name", "name": "case" } } @@ -53,7 +53,7 @@ } }, "name": { - "type": "Identifier", + "type": "Name", "name": "attr" } } diff --git a/test/fixtures/messages.json b/test/fixtures/messages.json index 1a5b5c4..425ec24 100644 --- a/test/fixtures/messages.json +++ b/test/fixtures/messages.json @@ -38,7 +38,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { @@ -73,7 +73,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr1" }, "value": { @@ -89,7 +89,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr2" }, "value": { @@ -116,7 +116,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { @@ -143,7 +143,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr1" }, "value": { @@ -159,7 +159,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr2" }, "value": { @@ -186,7 +186,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr1" }, "value": { diff --git a/test/fixtures/mixed_entries.json b/test/fixtures/mixed_entries.json index 4e349a5..4d574c5 100644 --- a/test/fixtures/mixed_entries.json +++ b/test/fixtures/mixed_entries.json @@ -42,7 +42,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { diff --git a/test/fixtures/multiline_values.json b/test/fixtures/multiline_values.json index 645a09b..d28f049 100644 --- a/test/fixtures/multiline_values.json +++ b/test/fixtures/multiline_values.json @@ -48,7 +48,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { @@ -75,7 +75,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { diff --git a/test/fixtures/select_expressions.json b/test/fixtures/select_expressions.json index 3dac7c7..07a107d 100644 --- a/test/fixtures/select_expressions.json +++ b/test/fixtures/select_expressions.json @@ -44,7 +44,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "other" }, "value": { @@ -96,7 +96,7 @@ } }, "name": { - "type": "Identifier", + "type": "Name", "name": "case" } }, @@ -104,7 +104,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "key" }, "value": { @@ -156,7 +156,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -202,7 +202,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -220,7 +220,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "two" }, "value": { diff --git a/test/fixtures/select_indent.json b/test/fixtures/select_indent.json index e9acf13..d0a003f 100644 --- a/test/fixtures/select_indent.json +++ b/test/fixtures/select_indent.json @@ -25,7 +25,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -71,7 +71,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -117,7 +117,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -163,7 +163,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -209,7 +209,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -255,7 +255,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -301,7 +301,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -347,7 +347,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -393,7 +393,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -439,7 +439,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -456,7 +456,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "other" }, "value": { @@ -502,7 +502,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -519,7 +519,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "other" }, "value": { @@ -574,7 +574,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -591,7 +591,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "other" }, "value": { @@ -637,7 +637,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -654,7 +654,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "other" }, "value": { diff --git a/test/fixtures/sparse_entries.json b/test/fixtures/sparse_entries.json index 0c4a368..7a67040 100644 --- a/test/fixtures/sparse_entries.json +++ b/test/fixtures/sparse_entries.json @@ -30,7 +30,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { @@ -65,7 +65,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { @@ -120,7 +120,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -137,7 +137,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "two" }, "value": { diff --git a/test/fixtures/terms.json b/test/fixtures/terms.json index 790e607..87fb485 100644 --- a/test/fixtures/terms.json +++ b/test/fixtures/terms.json @@ -20,7 +20,7 @@ { "type": "Attribute", "id": { - "type": "Identifier", + "type": "Name", "name": "attr" }, "value": { diff --git a/test/fixtures/variant_keys.json b/test/fixtures/variant_keys.json index f85abe6..8588a80 100644 --- a/test/fixtures/variant_keys.json +++ b/test/fixtures/variant_keys.json @@ -13,7 +13,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "key" }, "value": { @@ -44,7 +44,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "key" }, "value": { diff --git a/test/fixtures/variant_lists.json b/test/fixtures/variant_lists.json index 9713e09..536e4a7 100644 --- a/test/fixtures/variant_lists.json +++ b/test/fixtures/variant_lists.json @@ -13,7 +13,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "key" }, "value": { @@ -105,7 +105,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -114,7 +114,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "two" }, "value": { @@ -149,7 +149,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "one" }, "value": { @@ -167,7 +167,7 @@ { "type": "Variant", "key": { - "type": "Identifier", + "type": "Name", "name": "two" }, "value": { diff --git a/test/fixtures/variants_indent.json b/test/fixtures/variants_indent.json index 6171029..be9c73d 100644 --- a/test/fixtures/variants_indent.json +++ b/test/fixtures/variants_indent.json @@ -13,7 +13,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -44,7 +44,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -75,7 +75,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -106,7 +106,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "key" }, "value": { @@ -123,7 +123,7 @@ { "type": "Variant", "key": { - "type": "VariantName", + "type": "Name", "name": "other" }, "value": { From 495a743650e7a24a030d27cb446a95c68aeb964a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sta=C5=9B=20Ma=C5=82olepszy?= Date: Tue, 28 Aug 2018 12:04:57 +0200 Subject: [PATCH 3/3] Rename Attribute.id to Attribute.name --- syntax/ast.mjs | 4 ++-- test/fixtures/leading_dots.json | 10 +++++----- test/fixtures/messages.json | 14 +++++++------- test/fixtures/mixed_entries.json | 2 +- test/fixtures/multiline_values.json | 4 ++-- test/fixtures/sparse_entries.json | 4 ++-- test/fixtures/terms.json | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/syntax/ast.mjs b/syntax/ast.mjs index c3b4bb7..4aa27e7 100644 --- a/syntax/ast.mjs +++ b/syntax/ast.mjs @@ -159,10 +159,10 @@ export class CallExpression extends Expression { } export class Attribute extends SyntaxNode { - constructor(id, value) { + constructor(name, value) { super(); this.type = "Attribute"; - this.id = id; + this.name = name; this.value = value; } } diff --git a/test/fixtures/leading_dots.json b/test/fixtures/leading_dots.json index 2faa53d..148334d 100644 --- a/test/fixtures/leading_dots.json +++ b/test/fixtures/leading_dots.json @@ -199,7 +199,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "Value" }, @@ -251,7 +251,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "accesskey" }, @@ -278,7 +278,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attribute" }, @@ -305,7 +305,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attribute" }, @@ -433,7 +433,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attribute" }, diff --git a/test/fixtures/messages.json b/test/fixtures/messages.json index 425ec24..6b19b22 100644 --- a/test/fixtures/messages.json +++ b/test/fixtures/messages.json @@ -37,7 +37,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, @@ -72,7 +72,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr1" }, @@ -88,7 +88,7 @@ }, { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr2" }, @@ -115,7 +115,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, @@ -142,7 +142,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr1" }, @@ -158,7 +158,7 @@ }, { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr2" }, @@ -185,7 +185,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr1" }, diff --git a/test/fixtures/mixed_entries.json b/test/fixtures/mixed_entries.json index 4d574c5..27f8fae 100644 --- a/test/fixtures/mixed_entries.json +++ b/test/fixtures/mixed_entries.json @@ -41,7 +41,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, diff --git a/test/fixtures/multiline_values.json b/test/fixtures/multiline_values.json index d28f049..2b06d1a 100644 --- a/test/fixtures/multiline_values.json +++ b/test/fixtures/multiline_values.json @@ -47,7 +47,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, @@ -74,7 +74,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, diff --git a/test/fixtures/sparse_entries.json b/test/fixtures/sparse_entries.json index 7a67040..5af5800 100644 --- a/test/fixtures/sparse_entries.json +++ b/test/fixtures/sparse_entries.json @@ -29,7 +29,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, @@ -64,7 +64,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" }, diff --git a/test/fixtures/terms.json b/test/fixtures/terms.json index 87fb485..4e959dc 100644 --- a/test/fixtures/terms.json +++ b/test/fixtures/terms.json @@ -19,7 +19,7 @@ "attributes": [ { "type": "Attribute", - "id": { + "name": { "type": "Name", "name": "attr" },