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

Revert changes to NumberLiteral from #232 #242

Merged
merged 1 commit into from
Feb 26, 2019
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
7 changes: 0 additions & 7 deletions spec/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
The `VariantLists` and the `VariantExpression` syntax and AST nodes were
deprecated in Syntax 0.9 and have now been removed.

- Store `NumberLiterals` as floats with precision. (#232)

The `NumberLiteral.value` field is now a float value rather than a string.
A new field called `precision` stores the number of decimal places used in
the literal, thus allowing the AST to preserve the precision used in the
source.

- Rename `args` to `arguments`.

The `args` field of `MessageReference`, `TermReference`,
Expand Down
7 changes: 0 additions & 7 deletions syntax/abstract.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ export function into(Type) {
return always(new Type(
positional, Array.from(named.values())));
};
case FTL.NumberLiteral:
return ([minus, integer, fraction = ""]) => {
let sign = minus ? "-" : "+";
let value = parseFloat(sign + integer + "." + fraction);
let precision = fraction.length;
return always(new Type(value, precision));
};
case FTL.Placeable:
return expression => {
if (expression instanceof FTL.TermReference
Expand Down
3 changes: 1 addition & 2 deletions syntax/ast.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ export class StringLiteral extends Expression {
}

export class NumberLiteral extends Expression {
constructor(value, precision) {
constructor(value) {
super();
this.type = "NumberLiteral";
this.value = value;
this.precision = precision;
}
}

Expand Down
10 changes: 5 additions & 5 deletions syntax/grammar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,14 @@ let StringLiteral = defer(() =>

let NumberLiteral = defer(() =>
sequence(
maybe(string("-")).abstract,
digits.abstract,
maybe(string("-")),
digits,
maybe(
sequence(
string("."),
digits.abstract)))
.map(flatten(2))
.map(keep_abstract)
digits)))
.map(flatten(1))
.map(join)
.chain(into(FTL.NumberLiteral)));

/* ------------------ */
Expand Down
78 changes: 26 additions & 52 deletions test/fixtures/call_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "StringLiteral",
Expand Down Expand Up @@ -82,8 +81,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
},
{
Expand Down Expand Up @@ -136,8 +134,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
},
{
Expand Down Expand Up @@ -183,8 +180,7 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "StringLiteral",
Expand All @@ -209,8 +205,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
},
{
Expand Down Expand Up @@ -299,8 +294,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down Expand Up @@ -384,8 +378,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down Expand Up @@ -440,8 +433,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down Expand Up @@ -504,8 +496,7 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
],
"named": []
Expand Down Expand Up @@ -737,8 +728,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down Expand Up @@ -814,8 +804,7 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
],
"named": []
Expand Down Expand Up @@ -849,18 +838,15 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "NumberLiteral",
"value": 2,
"precision": 0
"value": "2"
},
{
"type": "NumberLiteral",
"value": 3,
"precision": 0
"value": "3"
}
],
"named": []
Expand Down Expand Up @@ -894,18 +880,15 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "NumberLiteral",
"value": 2,
"precision": 0
"value": "2"
},
{
"type": "NumberLiteral",
"value": 3,
"precision": 0
"value": "3"
}
],
"named": []
Expand Down Expand Up @@ -939,13 +922,11 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "NumberLiteral",
"value": 2,
"precision": 0
"value": "2"
}
],
"named": []
Expand Down Expand Up @@ -979,13 +960,11 @@
"positional": [
{
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
{
"type": "NumberLiteral",
"value": 2,
"precision": 0
"value": "2"
}
],
"named": []
Expand Down Expand Up @@ -1049,8 +1028,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
},
{
Expand All @@ -1061,8 +1039,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 2,
"precision": 0
"value": "2"
}
},
{
Expand All @@ -1073,8 +1050,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 3,
"precision": 0
"value": "3"
}
}
]
Expand Down Expand Up @@ -1115,8 +1091,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down Expand Up @@ -1157,8 +1132,7 @@
},
"value": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
}
}
]
Expand Down
3 changes: 1 addition & 2 deletions test/fixtures/leading_dots.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@
"type": "SelectExpression",
"selector": {
"type": "NumberLiteral",
"value": 1,
"precision": 0
"value": "1"
},
"variants": [
{
Expand Down
6 changes: 2 additions & 4 deletions test/fixtures/literal_expressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"type": "Placeable",
"expression": {
"type": "NumberLiteral",
"value": 123,
"precision": 0
"value": "123"
}
}
]
Expand All @@ -58,8 +57,7 @@
"type": "Placeable",
"expression": {
"type": "NumberLiteral",
"value": -3.14,
"precision": 2
"value": "-3.14"
}
}
]
Expand Down
Loading