Skip to content
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

Introduce the Name node for attribute and variant names #172

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 5 additions & 8 deletions spec/fluent.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,26 +69,23 @@ 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 */
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 | Name) blank? "]"

/* Identifiers */
/* Identifiers and Names */
Identifier ::= identifier
Name ::= 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 ::= "\\"
Expand Down
11 changes: 6 additions & 5 deletions syntax/ast.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -194,10 +194,11 @@ export class Identifier extends SyntaxNode {
}
}

export class VariantName extends Identifier {
export class Name extends SyntaxNode {
constructor(name) {
super(name);
this.type = "VariantName";
super();
this.type = "Name";
this.name = name;
}
}

Expand Down
38 changes: 8 additions & 30 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let Attribute = defer(() =>
line_end,
maybe(blank),
string("."),
Identifier.abstract,
Name.abstract,
maybe(blank_inline),
string("="),
maybe(blank_inline),
Expand Down Expand Up @@ -275,7 +275,7 @@ let AttributeExpression = defer(() =>
MessageReference,
TermReference).abstract,
string("."),
Identifier.abstract)
Name.abstract)
.map(keep_abstract)
.chain(list_into(FTL.AttributeExpression)));

Expand Down Expand Up @@ -335,28 +335,20 @@ let VariantKey = defer(() =>
maybe(blank),
either(
NumberLiteral,
VariantName),
Name),
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 */
/* --------------------- */
/* Identifiers and Names */

let Identifier = defer(() =>
identifier.chain(into(FTL.Identifier)));

let Name = defer(() =>
identifier.chain(into(FTL.Name)));

let TermIdentifier = defer(() =>
sequence(
string("-"),
Expand All @@ -380,8 +372,6 @@ let Function =
.map(join)
.chain(into(FTL.Function));

/* ------ */
/* Tokens */
let identifier =
sequence(
charset("a-zA-Z"),
Expand All @@ -390,18 +380,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 */

Expand Down
24 changes: 12 additions & 12 deletions test/fixtures/leading_dots.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "Value"
},
"value": {
Expand Down Expand Up @@ -251,8 +251,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "accesskey"
},
"value": {
Expand All @@ -278,8 +278,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attribute"
},
"value": {
Expand All @@ -305,8 +305,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attribute"
},
"value": {
Expand Down Expand Up @@ -350,7 +350,7 @@
{
"type": "Variant",
"key": {
"type": "VariantName",
"type": "Name",
"name": "one"
},
"value": {
Expand All @@ -367,7 +367,7 @@
{
"type": "Variant",
"key": {
"type": "VariantName",
"type": "Name",
"name": "other"
},
"value": {
Expand Down Expand Up @@ -433,8 +433,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attribute"
},
"value": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/member_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
},
"key": {
"type": "VariantName",
"type": "Name",
"name": "case"
}
}
Expand Down Expand Up @@ -53,7 +53,7 @@
}
},
"name": {
"type": "Identifier",
"type": "Name",
"name": "attr"
}
}
Expand Down
28 changes: 14 additions & 14 deletions test/fixtures/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr"
},
"value": {
Expand Down Expand Up @@ -72,8 +72,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr1"
},
"value": {
Expand All @@ -88,8 +88,8 @@
},
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr2"
},
"value": {
Expand All @@ -115,8 +115,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr"
},
"value": {
Expand All @@ -142,8 +142,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr1"
},
"value": {
Expand All @@ -158,8 +158,8 @@
},
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr2"
},
"value": {
Expand All @@ -185,8 +185,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr1"
},
"value": {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/mixed_entries.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr"
},
"value": {
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/multiline_values.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr"
},
"value": {
Expand All @@ -74,8 +74,8 @@
"attributes": [
{
"type": "Attribute",
"id": {
"type": "Identifier",
"name": {
"type": "Name",
"name": "attr"
},
"value": {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/select_expressions.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ new-messages =

valid-selector =
{ -term.case ->
*[ many words ] value
*[key] value
}

# ERROR
Expand Down
Loading