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.

0 commit comments

Comments
 (0)