Skip to content

Commit be7b885

Browse files
committed
Use module syntax and switch tests to mocha
1 parent dc16b57 commit be7b885

File tree

91 files changed

+722
-2082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+722
-2082
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"ecmaVersion": "latest",
99
"ecmaFeatures": {
1010
"jsx": true
11-
}
11+
},
12+
"sourceType": "module"
1213
}
1314
}

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0",
44
"name": "grammophone",
55
"browserslist": "> 0.5%, last 2 versions",
6+
"type": "module",
67
"source": [
78
"src/index.html"
89
],
@@ -14,16 +15,16 @@
1415
"@lezer/generator": "^1.2.2",
1516
"eslint": "^8.35.0",
1617
"eslint-plugin-react": "^7.32.2",
17-
"jest": "^29.4.3",
1818
"jshint": "^2.13.6",
19+
"mocha": "^10.2.0",
1920
"parcel": "^2.8.3"
2021
},
2122
"scripts": {
22-
"generate-lezer-parser": "yarn lezer-generator --cjs --output src/parser/rules.js src/parser/rules.grammar",
23-
"lint": "yarn eslint src test",
24-
"test": "jest",
25-
"build": "parcel build --no-autoinstall",
26-
"serve": "parcel serve --no-autoinstall"
23+
"generate-lezer-parser": "lezer-generator --output src/parser/rules.js src/parser/rules.grammar",
24+
"lint": "eslint src test",
25+
"test": "mocha --recursive",
26+
"build": "parcel build --no-autoinstall --no-cache",
27+
"serve": "parcel serve --no-autoinstall --no-cache"
2728
},
2829
"alias": {
2930
"preact/jsx-dev-runtime": "preact/jsx-runtime",

src/app/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { render } = require("preact");
2-
const { useReducer, useEffect } = require("preact/hooks");
3-
const { reducer, init } = require("./reducer.js");
4-
const ApplicationComponent = require("../components/application_component.js");
1+
import { render } from "preact";
2+
import { useReducer, useEffect } from "preact/hooks";
3+
import { reducer, init } from "./reducer.js";
4+
import ApplicationComponent from "../components/application_component.js";
55

66
function App() {
77
const [state, dispatch] = useReducer(reducer, "# Type a grammar here:\n\n", init);

src/app/reducer.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const Grammar = require("../grammar");
2-
const parser = require("../parser");
1+
import Grammar from "../grammar/index.js";
2+
import parser from "../parser/index.js";
33

4-
function reducer(state, action) {
4+
export function reducer(state, action) {
55
switch (action.type) {
66
case "setSpec":
77
return { ...state, spec: action.spec };
@@ -83,9 +83,6 @@ function reducer(state, action) {
8383
}
8484
}
8585

86-
function init(spec = "") {
86+
export function init(spec = "") {
8787
return { spec: spec, path: "/", mode: "edit" };
8888
}
89-
90-
module.exports.reducer = reducer;
91-
module.exports.init = init;

src/components/analysis/header_component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function({ path }) {
1+
export default function({ path }) {
22
let segments = [];
33

44
path.forEach(function(segment) {

src/components/analysis/nonterminals_component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { formatSymbol, formatSymbolList, listSymbols } = require("../helpers.js");
1+
import { formatSymbol, formatSymbolList, listSymbols } from "../helpers.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
const nullable = getCalculation("grammar.nullable");
55
const endable = getCalculation("grammar.endable");
66
const first = getCalculation("grammar.first");

src/components/analysis/parsing/abstract_lr1_table_component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { fillArray, formatSymbol, formatProduction } = require("../../helpers.js");
2-
const END = require("../../../grammar/symbols").END;
1+
import { fillArray, formatSymbol, formatProduction } from "../../helpers.js";
2+
import { END } from "../../../grammar/symbols.js";
33

4-
module.exports = function({ getCalculation, tableCalculation }) {
4+
export default function({ getCalculation, tableCalculation }) {
55
const info = getCalculation("grammar.symbolInfo");
66
const table = getCalculation(tableCalculation);
77
const productions = getCalculation("grammar.productions");

src/components/analysis/parsing/abstract_lr_automaton_component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const template = require("./lr_automaton_graph");
2-
const { Component } = require("preact");
1+
import template from "./lr_automaton_graph.js";
2+
import { Component } from "preact";
33

44
let viz;
55

@@ -16,7 +16,7 @@ function render(src) {
1616
});
1717
}
1818

19-
module.exports = class AbstractLRAutomatonComponent extends Component {
19+
export default class AbstractLRAutomatonComponent extends Component {
2020
shouldComponentUpdate(newProps) {
2121
this.updateBaseWithRenderedSVG(newProps);
2222
return false;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLRAutomatonComponent = require("./abstract_lr_automaton_component.js");
1+
import AbstractLRAutomatonComponent from "./abstract_lr_automaton_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLRAutomatonComponent getCalculation={getCalculation} automatonCalculation="parsing.lr.lalr1_automaton" title="LALR(1) Automaton" />;
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLR1TableComponent = require("./abstract_lr1_table_component.js");
1+
import AbstractLR1TableComponent from "./abstract_lr1_table_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLR1TableComponent getCalculation={getCalculation} tableCalculation="parsing.lr.lalr1_table" />;
55
}

src/components/analysis/parsing/ll1_table_component.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const { fillArray, formatSymbol, formatProduction } = require("../../helpers.js");
2-
const END = require("../../../grammar/symbols").END;
1+
import { fillArray, formatSymbol, formatProduction } from "../../helpers.js";
2+
import { END } from "../../../grammar/symbols.js";
33

4-
module.exports = function({ getCalculation }) {
4+
export default function({ getCalculation }) {
55
const info = getCalculation("grammar.symbolInfo");
66
const table = getCalculation("parsing.ll.ll1_table");
77
const productions = getCalculation("grammar.productions");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLRAutomatonComponent = require("./abstract_lr_automaton_component.js");
1+
import AbstractLRAutomatonComponent from "./abstract_lr_automaton_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLRAutomatonComponent getCalculation={getCalculation} automatonCalculation="parsing.lr.lr0_automaton" title="LR(0) Automaton" />;
55
}

src/components/analysis/parsing/lr0_table_component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { fillArray, formatSymbol, formatProduction } = require("../../helpers.js");
1+
import { fillArray, formatSymbol, formatProduction } from "../../helpers.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
const info = getCalculation("grammar.symbolInfo");
55
const table = getCalculation("parsing.lr.lr0_table");
66
const productions = getCalculation("grammar.productions");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLRAutomatonComponent = require("./abstract_lr_automaton_component.js");
1+
import AbstractLRAutomatonComponent from "./abstract_lr_automaton_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLRAutomatonComponent getCalculation={getCalculation} automatonCalculation="parsing.lr.lr1_automaton" title="LR(1) Automaton" />;
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLR1TableComponent = require("./abstract_lr1_table_component.js");
1+
import AbstractLR1TableComponent from "./abstract_lr1_table_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLR1TableComponent getCalculation={getCalculation} tableCalculation="parsing.lr.lr1_table" />;
55
}

src/components/analysis/parsing/lr_automaton_graph.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { bareFormatItem, bareFormatSymbol } = require("../../helpers.js");
1+
import { bareFormatItem, bareFormatSymbol } from "../../helpers.js";
22

3-
module.exports = function({ info, automaton, productions, start, title }) {
3+
export default function({ info, automaton, productions, start, title }) {
44
let result = [];
55

66
result.push(
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const AbstractLR1TableComponent = require("./abstract_lr1_table_component.js");
1+
import AbstractLR1TableComponent from "./abstract_lr1_table_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <AbstractLR1TableComponent getCalculation={getCalculation} tableCalculation="parsing.lr.slr1_table" />;
55
}

src/components/analysis/parsing_component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function formatClassification(cs, c, n) {
66
}
77
}
88

9-
module.exports = function({ getCalculation }) {
9+
export default function({ getCalculation }) {
1010
const classification = getCalculation("grammar.classification");
1111

1212
return (

src/components/analysis/sanity_component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { formatSentence, formatSymbolList, listSymbols, formatProduction } = require("../helpers.js");
1+
import { formatSentence, formatSymbolList, listSymbols, formatProduction } from "../helpers.js";
22

33
function formatUnreachable(unreachable, info) {
44
if (unreachable.size > 0) {
@@ -68,7 +68,7 @@ function formatAmbiguous(ambiguous, info) {
6868
}
6969
}
7070

71-
module.exports = function({ getCalculation }) {
71+
export default function({ getCalculation }) {
7272
const unreachable = getCalculation("grammar.unreachable");
7373
const unrealizable = getCalculation("grammar.unrealizable");
7474
const cycle = getCalculation("grammar.cycle");

src/components/analysis/sentences_component.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { formatSentence } = require("../helpers.js");
1+
import { formatSentence } from "../helpers.js";
22

3-
module.exports = function({ getCalculation, limit = 30 }) {
3+
export default function({ getCalculation, limit = 30 }) {
44
const sentences = getCalculation("grammar.sentences");
55
const info = getCalculation("grammar.symbolInfo");
66

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const SentencesComponent = require("./sentences_component.js");
1+
import SentencesComponent from "./sentences_component.js";
22

3-
module.exports = function({ getCalculation }) {
3+
export default function({ getCalculation }) {
44
return <SentencesComponent getCalculation={getCalculation} limit={10} />;
55
}

src/components/analysis_component.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const BlankSlateComponent = require("./blank_slate_component.js");
2-
const HeaderComponent = require("./analysis/header_component.js");
1+
import BlankSlateComponent from "./blank_slate_component.js";
2+
import HeaderComponent from "./analysis/header_component.js";
33

4-
const NonterminalsComponent = require("./analysis/nonterminals_component.js");
5-
const ParsingComponent = require("./analysis/parsing_component.js");
6-
const SanityComponent = require("./analysis/sanity_component.js");
7-
const ShortSentencesComponent = require("./analysis/short_sentences_component.js");
8-
const SentencesComponent = require("./analysis/sentences_component.js");
4+
import NonterminalsComponent from "./analysis/nonterminals_component.js";
5+
import ParsingComponent from "./analysis/parsing_component.js";
6+
import SanityComponent from "./analysis/sanity_component.js";
7+
import ShortSentencesComponent from "./analysis/short_sentences_component.js";
8+
import SentencesComponent from "./analysis/sentences_component.js";
99

10-
const LL1TableComponent = require("./analysis/parsing/ll1_table_component.js");
11-
const LR0TableComponent = require("./analysis/parsing/lr0_table_component.js");
12-
const LR1TableComponent = require("./analysis/parsing/lr1_table_component.js");
13-
const LALR1TableComponent = require("./analysis/parsing/lalr1_table_component.js");
14-
const SLR1TableComponent = require("./analysis/parsing/slr1_table_component.js");
10+
import LL1TableComponent from "./analysis/parsing/ll1_table_component.js";
11+
import LR0TableComponent from "./analysis/parsing/lr0_table_component.js";
12+
import LR1TableComponent from "./analysis/parsing/lr1_table_component.js";
13+
import LALR1TableComponent from "./analysis/parsing/lalr1_table_component.js";
14+
import SLR1TableComponent from "./analysis/parsing/slr1_table_component.js";
1515

16-
const LR0AutomatonComponent = require("./analysis/parsing/lr0_automaton_component.js");
17-
const LR1AutomatonComponent = require("./analysis/parsing/lr1_automaton_component.js");
18-
const LALR1AutomatonComponent = require("./analysis/parsing/lalr1_automaton_component.js");
16+
import LR0AutomatonComponent from "./analysis/parsing/lr0_automaton_component.js";
17+
import LR1AutomatonComponent from "./analysis/parsing/lr1_automaton_component.js";
18+
import LALR1AutomatonComponent from "./analysis/parsing/lalr1_automaton_component.js";
1919

2020
const ROUTES = {
2121
"/": {
@@ -92,7 +92,7 @@ const ROUTES = {
9292
}
9393
};
9494

95-
module.exports = function({ grammar, path }) {
95+
export default function({ grammar, path }) {
9696
if (typeof grammar !== "undefined") {
9797
const route = ROUTES[path];
9898

src/components/application_component.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const EditComponent = require("./edit_component.js");
2-
const ErrorComponent = require("./error_component.js");
3-
const AnalysisComponent = require("./analysis_component.js");
4-
const ModeComponent = require("./mode_component.js");
5-
const TransformComponent = require("./transform_component.js");
1+
import EditComponent from "./edit_component.js";
2+
import ErrorComponent from "./error_component.js";
3+
import AnalysisComponent from "./analysis_component.js";
4+
import ModeComponent from "./mode_component.js";
5+
import TransformComponent from "./transform_component.js";
66

7-
module.exports = function({ spec, updateSpec, mode, edit, transform, analyze, error, grammar, path, transformStack, transformIndex, undoTransformation, redoTransformation, applyTransformation }) {
7+
export default function({ spec, updateSpec, mode, edit, transform, analyze, error, grammar, path, transformStack, transformIndex, undoTransformation, redoTransformation, applyTransformation }) {
88
return (
99
<>
1010
<div id="master">

src/components/blank_slate_component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function() {
1+
export default function() {
22
return (
33
<section class="blank-slate">
44
<div>

src/components/edit_component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function({ spec, specChanged }) {
1+
export default function({ spec, specChanged }) {
22
return (
33
<section id="edit">
44
<div class="spec-wrap">

src/components/error_component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function({ error }) {
1+
export default function({ error }) {
22
return (
33
<section id="error">
44
<code>{error ? error.toString() : ""}</code>

0 commit comments

Comments
 (0)