Skip to content

Commit 94dae4d

Browse files
authored
Rename all files to *.js; invoke with node -r esm (#265)
1 parent 1e71666 commit 94dae4d

28 files changed

+74
-70
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ validate your work:
2626
npm test # Test the parser against JSON AST fixtures.
2727
npm run lint # Lint the parser code.
2828

29-
npm run generate:ebnf # Generate the EBNF from syntax/grammar.mjs.
29+
npm run generate:ebnf # Generate the EBNF from syntax/grammar.js.
3030
npm run generate:fixtures # Generate test fixtures (FTL → JSON AST).
3131

3232
npm run build:guide # Build the HTML version of the Guide.

bin/ebnf.mjs renamed to bin/ebnf.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import readline from "readline";
33
import parse_args from "minimist";
4-
import ebnf from "../lib/ebnf.mjs";
4+
import ebnf from "../lib/ebnf.js";
55

66
const argv = parse_args(process.argv.slice(2), {
77
boolean: ["help"],
@@ -26,14 +26,14 @@ if (file_path === "-") {
2626

2727
function exit_help(exit_code) {
2828
console.log(`
29-
Usage: node --experimental-modules ebnf.mjs [OPTIONS] <FILE>
29+
Usage: node -r esm ebnf.js [OPTIONS] <FILE>
3030
3131
When FILE is "-", read text from stdin.
3232
3333
Examples:
3434
35-
node --experimental-modules ebnf.mjs path/to/grammar.mjs
36-
cat path/to/grammar.mjs | node --experimental-modules ebnf.mjs -
35+
node -r esm ebnf.js path/to/grammar.js
36+
cat path/to/grammar.js | node -r esm ebnf.js -
3737
3838
Options:
3939

bin/parse.mjs renamed to bin/parse.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import readline from "readline";
33
import parse_args from "minimist";
4-
import {Resource} from "../syntax/grammar.mjs";
4+
import {Resource} from "../syntax/grammar.js";
55

66
const argv = parse_args(process.argv.slice(2), {
77
boolean: ["help"],
@@ -26,14 +26,14 @@ if (file_path === "-") {
2626

2727
function exit_help(exit_code) {
2828
console.log(`
29-
Usage: node --experimental-modules parse.mjs [OPTIONS] <FILE>
29+
Usage: node -r esm parse.js [OPTIONS] <FILE>
3030
3131
When FILE is "-", read text from stdin.
3232
3333
Examples:
3434
35-
node --experimental-modules parse.mjs path/to/file.ftl
36-
cat path/to/file.ftl | node --experimental-modules parse.mjs -
35+
node -r esm parse.js path/to/file.ftl
36+
cat path/to/file.ftl | node -r esm parse.js -
3737
3838
Options:
3939

lib/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Fluent Specification Support Code
22

3-
This directory contains support code for the parser-combinator underlying the syntax code, as well as the code to transform `grammar.mjs` to `fluent.ebnf`. The combination allows for a succinct formulation of the syntax in `grammar.mjs` and a readable representation of that in `fluent.ebnf`.
3+
This directory contains support code for the parser-combinator underlying the syntax code, as well as the code to transform `grammar.js` to `fluent.ebnf`. The combination allows for a succinct formulation of the syntax in `grammar.js` and a readable representation of that in `fluent.ebnf`.
44

55
## Parser-Combinator
66

7-
**`parser.mjs`** is the base parser class, **`stream.mjs`** holds a iterator over the strings to be parsed.
7+
**`parser.js`** is the base parser class, **`stream.js`** holds a iterator over the strings to be parsed.
88

9-
**`combinators.mjs`** holds the actual basic grammar productions and logical combinations of grammar productions.
9+
**`combinators.js`** holds the actual basic grammar productions and logical combinations of grammar productions.
1010

11-
Both use `Success` and `Failure` from **`result.mjs`** to pass success and failure conditions forward.
11+
Both use `Success` and `Failure` from **`result.js`** to pass success and failure conditions forward.
1212

13-
After the definition of grammar productions, the utilities in **`mappers.mjs`** are used to concat, flatten, and extract the matched data to prepare it for AST generation.
13+
After the definition of grammar productions, the utilities in **`mappers.js`** are used to concat, flatten, and extract the matched data to prepare it for AST generation.
1414

1515
## EBNF Generation
1616

17-
The `fluent.ebnf` is created by parsing the `grammar.mjs` and transpilation to an EBNF file. The `babylon` JavaScript parser is used to load a Babel AST.
17+
The `fluent.ebnf` is created by parsing the `grammar.js` and transpilation to an EBNF file. The `babylon` JavaScript parser is used to load a Babel AST.
1818

19-
**`ebnf.mjs`** is the top-level entry point used by `bin/ebnf.mjs`. It uses the iteration logic from **`walker.mjs`** to go over the Babel AST and to extract the information relevant to the EBNF via the Visitor in **`visitor.mjs`**. The resulting data is then serialiazed to EBNF via **`serializer.mjs`**.
19+
**`ebnf.js`** is the top-level entry point used by `bin/ebnf.js`. It uses the iteration logic from **`walker.js`** to go over the Babel AST and to extract the information relevant to the EBNF via the Visitor in **`visitor.js`**. The resulting data is then serialiazed to EBNF via **`serializer.js`**.

lib/combinators.mjs renamed to lib/combinators.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Parser from "./parser.mjs";
2-
import {Success, Failure} from "./result.mjs";
3-
import {join} from "./mappers.mjs";
1+
import Parser from "./parser.js";
2+
import {Success, Failure} from "./result.js";
3+
import {join} from "./mappers.js";
44

55
export function defer(fn) {
66
// Parsers may be defined as defer(() => parser) to avoid cyclic
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import babylon from "babylon";
2-
import walk from "./walker.mjs";
3-
import visitor from "./visitor.mjs";
4-
import serialize from "./serializer.mjs";
1+
import {parse} from "babylon";
2+
import walk from "./walker.js";
3+
import visitor from "./visitor.js";
4+
import serialize from "./serializer.js";
55

66
export default
77
function ebnf(source, min_name_length = 0) {
8-
let grammar_ast = babylon.parse(source, {sourceType: "module"});
8+
let grammar_ast = parse(source, {sourceType: "module"});
99
let rules = walk(grammar_ast, visitor);
1010
let state = {
1111
max_name_length: Math.max(
@@ -16,4 +16,3 @@ function ebnf(source, min_name_length = 0) {
1616
.map(rule => serialize(rule, state))
1717
.join("");
1818
}
19-

lib/mappers.mjs renamed to lib/mappers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Abstract} from "./parser.mjs";
1+
import {Abstract} from "./parser.js";
22

33
// Flatten a list up to a given depth.
44
// This is useful when a parser uses nested sequences and repeats.

lib/parser.mjs renamed to lib/parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Stream from "./stream.mjs";
2-
import {Failure} from "./result.mjs";
1+
import Stream from "./stream.js";
2+
import {Failure} from "./result.js";
33

44
export class Abstract {
55
constructor(value) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
"version": "1.0.0",
55
"private": true,
66
"scripts": {
7-
"bench": "node --experimental-modules --harmony-async-iteration ./test/bench.mjs ./test/benchmarks/gecko_strings.ftl",
7+
"bench": "node -r esm --harmony-async-iteration ./test/bench.js ./test/benchmarks/gecko_strings.ftl",
88
"build:guide": "gitbook build guide build/guide",
99
"build": "npm run --silent build:guide",
1010
"ci": "npm run --silent lint && npm test && npm run --silent test:ebnf",
1111
"clean": "rm -rf build",
1212
"deploy": "gh-pages -d build",
13-
"generate:ebnf": "node --experimental-modules bin/ebnf.mjs ./syntax/grammar.mjs > ./spec/fluent.ebnf",
13+
"generate:ebnf": "node -r esm bin/ebnf.js ./syntax/grammar.js > ./spec/fluent.ebnf",
1414
"generate:fixtures": "make -sC test/fixtures",
1515
"generate": "npm run --silent generate:ebnf && npm run --silent generate:fixtures",
16-
"lint": "eslint **/*.mjs",
17-
"test:ebnf": "node --experimental-modules test/ebnf.mjs ./syntax/grammar.mjs ./spec/fluent.ebnf",
18-
"test:fixtures": "node --experimental-modules test/parser.mjs ./test/fixtures",
19-
"test:unit": "node --experimental-modules test/literals.mjs",
16+
"lint": "eslint **/*.js",
17+
"test:ebnf": "node -r esm test/ebnf.js ./syntax/grammar.js ./spec/fluent.ebnf",
18+
"test:fixtures": "node -r esm test/parser.js ./test/fixtures",
19+
"test:unit": "node -r esm test/literals.js",
2020
"test": "npm run --silent test:fixtures && npm run --silent test:unit"
2121
},
2222
"homepage": "https://projectfluent.org",
@@ -41,6 +41,7 @@
4141
"json-diff": "^0.5.2"
4242
},
4343
"dependencies": {
44+
"esm": "^3.2.25",
4445
"minimist": "^1.2.0"
4546
}
4647
}

spec/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ compatibility strategy for future releases.
233233

234234
The `Function` production and its corresponding AST node have been
235235
removed. The logic validating that function names are all upper-case has
236-
been moved to `abstract.mjs`.
236+
been moved to `abstract.js`.
237237

238238
## 0.7.0 (October 15, 2018)
239239

@@ -282,11 +282,11 @@ compatibility strategy for future releases.
282282
correctness at a cost of reduced performance.
283283
284284
The ASDL description of the AST has been removed in favor of
285-
`syntax/ast.mjs` which defines the actual AST nodes returned by the
285+
`syntax/ast.js` which defines the actual AST nodes returned by the
286286
reference parser.
287287
288288
The EBNF is now auto-generated from the reference parser's
289-
`syntax/grammar.mjs` file. It provides an easy to read overview of the
289+
`syntax/grammar.js` file. It provides an easy to read overview of the
290290
grammar and will continue to be updated in the future.
291291

292292
Going forward, all changes to the grammar will be implemented in the

spec/fluent.ebnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ block_placeable ::= blank_block blank_inline? inline_placeable
4949

5050
/* Rules for validating expressions in Placeables and as selectors of
5151
* SelectExpressions are documented in spec/valid.md and enforced in
52-
* syntax/abstract.mjs. */
52+
* syntax/abstract.js. */
5353
InlineExpression ::= StringLiteral
5454
| NumberLiteral
5555
| FunctionReference

spec/valid.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Fluent Syntax distinguishes between well-formed and valid resources.
44

55
- Well-formed Fluent resources conform to the Fluent grammar described by
66
the Fluent EBNF (`spec/fluent.ebnf`). The EBNF is auto-generated from
7-
`syntax/grammar.mjs`.
7+
`syntax/grammar.js`.
88

99
- Valid Fluent resources must be well-formed and are additionally checked
1010
for semantic correctness. The validation process may reject syntax which is
1111
well-formed. The validation rules are expressed in code in
12-
`syntax/abstract.mjs`.
12+
`syntax/abstract.js`.
1313

1414
For example, the `message.attr(param: "value")` syntax is _well-formed_.
1515
`message.attr` is an `AttributeExpression` which may be the callee of a

syntax/abstract.mjs renamed to syntax/abstract.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* AST Validation
33
*
4-
* The parse result of the grammar.mjs parser is a well-formed AST which is
4+
* The parse result of the grammar.js parser is a well-formed AST which is
55
* validated according to the rules documented in `spec/valid.md`.
66
*/
77

8-
import * as FTL from "./ast.mjs";
9-
import {always, never} from "../lib/combinators.mjs";
8+
import * as FTL from "./ast.js";
9+
import {always, never} from "../lib/combinators.js";
1010

1111
export function list_into(Type) {
1212
switch (Type) {
@@ -155,7 +155,7 @@ function attach_comments(acc, cur) {
155155
}
156156

157157
// Remove the largest common indentation from a list of elements of a Pattern.
158-
// The indents are parsed in grammar.mjs and passed to abstract.mjs as string
158+
// The indents are parsed in grammar.js and passed to abstract.js as string
159159
// primitives along with other PatternElements.
160160
function dedent(elements) {
161161
// Calculate the maximum common indent.
File renamed without changes.

syntax/grammar.mjs renamed to syntax/grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as FTL from "./ast.mjs";
2-
import {list_into, into} from "./abstract.mjs";
1+
import * as FTL from "./ast.js";
2+
import {list_into, into} from "./abstract.js";
33
import {
44
always, and, charset, defer, either, eof, maybe, not,
55
regex, repeat, repeat1, sequence, string
6-
} from "../lib/combinators.mjs";
6+
} from "../lib/combinators.js";
77
import {
88
element_at, flatten, join, keep_abstract, mutate, print, prune
9-
} from "../lib/mappers.mjs";
9+
} from "../lib/mappers.js";
1010

1111
/* ----------------------------------------------------- */
1212
/* An FTL file defines a Resource consisting of Entries. */
@@ -191,7 +191,7 @@ let block_placeable = defer(() =>
191191
/* ------------------------------------------------------------------- */
192192
/* Rules for validating expressions in Placeables and as selectors of
193193
* SelectExpressions are documented in spec/valid.md and enforced in
194-
* syntax/abstract.mjs. */
194+
* syntax/abstract.js. */
195195
let InlineExpression = defer(() =>
196196
either(
197197
StringLiteral,

test/bench.mjs renamed to test/bench.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import fs from "fs";
22
import perf from "perf_hooks";
33
const {PerformanceObserver, performance} = perf;
44

5-
import FluentSyntax from "fluent-syntax";
6-
import FluentRuntime from "fluent";
7-
import {Resource} from "../syntax/grammar.mjs";
8-
import {readfile} from "./util.mjs";
5+
import {parse} from "fluent-syntax";
6+
import {_parse} from "fluent";
7+
import {Resource} from "../syntax/grammar.js";
8+
import {readfile} from "./util.js";
99

1010
let args = process.argv.slice(2);
1111

1212
if (args.length < 1 || 2 < args.length) {
1313
console.error(
14-
"Usage: node --experimental-modules --harmony-async-iteration " +
15-
"bench.mjs FTL_FILE [SAMPLE SIZE = 30]");
14+
"Usage: node -r esm --harmony-async-iteration " +
15+
"bench.js FTL_FILE [SAMPLE SIZE = 30]");
1616
process.exit(1);
1717
}
1818

@@ -31,8 +31,8 @@ async function main(ftl_file, sample_size = 30) {
3131

3232
let subjects = new Map([
3333
["Reference", new Subject("Reference", () => Resource.run(ftl))],
34-
["Tooling", new Subject("Tooling", () => FluentSyntax.parse(ftl))],
35-
["Runtime", new Subject("Runtime", () => FluentRuntime._parse(ftl))],
34+
["Tooling", new Subject("Tooling", () => parse(ftl))],
35+
["Runtime", new Subject("Runtime", () => _parse(ftl))],
3636
]);
3737

3838
new PerformanceObserver(items => {

test/ebnf.mjs renamed to test/ebnf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import color from "cli-color";
22
import difflib from "difflib";
3-
import ebnf from "../lib/ebnf.mjs";
4-
import {readfile, PASS, FAIL} from "./util.mjs";
3+
import ebnf from "../lib/ebnf.js";
4+
import {readfile, PASS, FAIL} from "./util.js";
55

66
let args = process.argv.slice(2);
77

88
if (args.length !== 2) {
99
console.error(
10-
"Usage: node --experimental-modules ebnf.mjs " +
10+
"Usage: node -r esm ebnf.js " +
1111
"GRAMMAR_FILE EXPECTED_EBNF");
1212
process.exit(1);
1313
}

test/fixtures/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ all: $(AST_FIXTURES)
55

66
.PHONY: $(AST_FIXTURES)
77
$(AST_FIXTURES): %.json: %.ftl
8-
@node --experimental-modules ../../bin/parse.mjs $< \
8+
@node -r esm ../../bin/parse.js $< \
99
2> /dev/null \
1010
1> $@;
1111
@echo "$< → $@"

test/literals.mjs renamed to test/literals.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint quotes: "off" */
2-
import suite from "./suite.mjs";
3-
import {StringLiteral, NumberLiteral} from "../syntax/grammar.mjs";
2+
import suite from "./suite.js";
3+
import {StringLiteral, NumberLiteral} from "../syntax/grammar.js";
44

55
if (process.argv.length > 2) {
6-
console.error("Usage: node --experimental-modules literals.mjs");
6+
console.error("Usage: node -r esm literals.js");
77
process.exit(1);
88
}
99

@@ -71,4 +71,3 @@ suite(tester => {
7171
test(NumberLiteral.run("-01.0300"), {value: -1.03, precision: 4});
7272
};
7373
});
74-

test/parser.mjs renamed to test/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import assert from "assert";
22
import path from "path";
3-
import {Resource} from "../syntax/grammar.mjs";
4-
import {readdir, readfile, diff, PASS, FAIL} from "./util.mjs";
3+
import {Resource} from "../syntax/grammar.js";
4+
import {readdir, readfile, diff, PASS, FAIL} from "./util.js";
55

66
const fixtures_dir = process.argv[2];
77

88
if (!fixtures_dir) {
99
console.error(
10-
"Usage: node --experimental-modules parser.mjs FIXTURE");
10+
"Usage: node -r esm parser.js FIXTURE");
1111
process.exit(1);
1212
}
1313

test/suite.mjs renamed to test/suite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "assert";
22
import color from "cli-color";
3-
import {diff, PASS, FAIL} from "./util.mjs";
3+
import {diff, PASS, FAIL} from "./util.js";
44

55
export default
66
function suite(fn) {
File renamed without changes.

0 commit comments

Comments
 (0)