Skip to content
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
5 changes: 2 additions & 3 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/coverage
/node_modules
/bundle.js
# Generated/coverage files
coverage/
13 changes: 8 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 12,
"ecmaVersion": 2024,
"requireConfigFile": false,
"sourceType": "script",
"sourceType": "module",
"babelOptions": {
"plugins": [
"@babel/plugin-syntax-class-properties"
"@babel/plugin-syntax-class-properties",
"@babel/plugin-syntax-import-attributes"
]
}
},
"rules": {
"no-unused-vars": ["error", {"argsIgnorePattern": "^_"}]
"no-unused-vars": ["error", {"argsIgnorePattern": "^_"}],
"no-var": "error",
"prefer-const": "error",
"prefer-template": "error"
}
}
23 changes: 1 addition & 22 deletions .github/workflows/node_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 15.x]
node-version: [22.x, 24.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand All @@ -19,24 +19,3 @@ jobs:
- run: npm ci
- run: npm ls -s
- run: npx eslint .
- run: npx tsc
- run: npx nyc npm test
- name: Coveralls Upload
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: node-${{ matrix.node-version }}
parallel: true
- run: npx nyc check-coverage
# TODO bring back per-file thresholds once we get the numbers up
# - run: npx nyc check-coverage --per-file

finish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
/coverage
/.nyc_output
*.tgz
12 changes: 12 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Dependencies
node_modules/

# Build outputs
coverage/

# Generated files
*.json
*.md
*.kni
*.vim

13 changes: 13 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "avoid",
"endOfLine": "lf"
}

122 changes: 60 additions & 62 deletions console.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
'use strict';

var Excerpt = require('./excerpt');
var Wrapper = require('./wrapper');

module.exports = class Console {
constructor(writer) {
this.writer = writer;
this.wrapper = new Wrapper(writer);
this.excerpt = new Excerpt();
this.options = [];
this.cursor = this.excerpt;
}

write(lift, text, drop) {
this.cursor.digest(lift, text, drop);
}

break() {
this.cursor.break();
}

paragraph() {
this.cursor.paragraph();
}

startOption() {
var option = new Excerpt();
this.cursor = option;
this.options.push(option);
}

stopOption() {
this.cursor = this.excerpt;
}

flush() {
this.writer.write('\n');
}

pardon() {
this.writer.write('?\n');
}

display() {
this.excerpt.write(this.wrapper);
for (var i = 0; i < this.options.length; i++) {
var number = i + 1;
var lead = (number + '. ').slice(0, 3) + ' ';
this.wrapper.word(lead);
this.wrapper.flush = true;
this.wrapper.push(' ', ' ');
this.options[i].write(this.wrapper);
this.wrapper.pop();
}
}

clear() {
this.excerpt = new Excerpt();
this.options = [];
this.cursor = this.excerpt;
}
import Excerpt from './excerpt.js';
import Wrapper from './wrapper.js';

export default class Console {
constructor(writer) {
this.writer = writer;
this.wrapper = new Wrapper(writer);
this.excerpt = new Excerpt();
this.options = [];
this.cursor = this.excerpt;
}

write(lift, text, drop) {
this.cursor.digest(lift, text, drop);
}

break() {
this.cursor.break();
}

paragraph() {
this.cursor.paragraph();
}

startOption() {
const option = new Excerpt();
this.cursor = option;
this.options.push(option);
}

stopOption() {
this.cursor = this.excerpt;
}

flush() {
this.writer.write('\n');
}

pardon() {
this.writer.write('?\n');
}

display() {
this.excerpt.write(this.wrapper);
for (let i = 0; i < this.options.length; i++) {
const number = i + 1;
const lead = `${`${number}. `.slice(0, 3)} `;
this.wrapper.word(lead);
this.wrapper.flush = true;
this.wrapper.push(' ', ' ');
this.options[i].write(this.wrapper);
this.wrapper.pop();
}
}

clear() {
this.excerpt = new Excerpt();
this.options = [];
this.cursor = this.excerpt;
}
}
143 changes: 54 additions & 89 deletions describe.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,81 @@
'use strict';
const types = {};

module.exports = describe;
const describe = node => {
return types[node.type](node);
};

function describe(node) {
return types[node.type](node);
}
export default describe;

var types = {};
types.text = node => node.text;

types.text = function text(node) {
return node.text;
};
types.echo = node => S(node.expression);

types.echo = function echo(node) {
return S(node.expression);
};
types.opt = node => `(Q ${node.question.join(' ')}) (A ${node.answer.join(' ')})`;

types.opt = function opt(node) {
return '(Q ' + node.question.join(' ') + ') (A ' + node.answer.join(' ') + ')';
};
types.goto = _node => '';

types.goto = function goto(_node) {
return '';
};
types.call = node => `${node.label}(${node.args.map(S).join(' ')}) esc ${node.branch}`;

types.call = function call(node) {
return node.label + '(' + node.args.map(S).join(' ') + ') esc ' + node.branch;
};
types.def = node => `(${node.locals.join(' ')})`;

types.def = function def(node) {
return '(' + node.locals.join(' ') + ')';
};
types.jump = node => `${node.branch} if ${S(node.condition)}`;

types.jump = function jump(node) {
return node.branch + ' if ' + S(node.condition);
types.switch = node => {
let desc = '';
if (node.variable) {
desc += `(${node.variable}+${node.value}) ${S(node.expression)}`;
} else {
desc += S(node.expression);
}
desc += ` (${node.branches.join(' ')}) W(${node.weights.map(S).join(' ')})`;
return desc;
};

types.switch = function _switch(node) {
var desc = '';
if (node.variable) {
desc += '(' + node.variable + '+' + node.value + ') ' + S(node.expression);
} else {
desc += S(node.expression);
}
desc += ' (' + node.branches.join(' ') + ') W(' + node.weights.map(S).join(' ') + ')';
return desc;
};
types.set = node => `${node.variable} ${S(node.expression)}`;

types.set = function set(node) {
return node.variable + ' ' + S(node.expression);
};
types.move = node => `${S(node.source)} -> ${S(node.target)}`;

types.move = function move(node) {
return S(node.source) + ' -> ' + S(node.target);
};
types.cue = node => node.cue;

types.cue = function cue(node) {
return node.cue;
};
types.br = _node => '';

types.br = function br(_node) {
return '';
};
types.par = _node => '';

types.par = function par(_node) {
return '';
};
types.rule = _node => '';

types.rule = function rule(_node) {
return '';
};
types.startJoin = _node => '';

types.startJoin = function startJoin(_node) {
return '';
};
types.stopJoin = _node => '';

types.stopJoin = function stopJoin(_node) {
return '';
};
types.delimit = _node => '';

types.delimit = function delimit(_node) {
return '';
};
types.ask = _node => '';

types.ask = function ask(_node) {
return '';
types.read = node => {
let label = node.variable;
if (node.cue != null) {
label += ` ${node.cue}`;
}
return label;
};

types.read = function ask(node) {
var label = node.variable;
if (node.cue != null) {
label += ' ' + node.cue;
}
return label;
const S = args => {
if (args[0] === 'val' || args[0] === 'get') {
return args[1];
} else if (args[0] === 'var') {
return `(${args[0]} ${V(args[1], args[2])})`;
} else {
return `(${args[0]} ${args.slice(1).map(S).join(' ')})`;
}
};

function S(args) {
if (args[0] === 'val' || args[0] === 'get') {
return args[1];
} else if (args[0] === 'var') {
return '(' + args[0] + ' ' + V(args[1], args[2]) + ')';
} else {
return '(' + args[0] + ' ' + args.slice(1).map(S).join(' ') + ')';
}
}

function V(source, target) {
var r = '';
for (var i = 0; i < target.length; i++) {
r += source[i];
r += '{' + S(target[i]) + '}';
}
const V = (source, target) => {
let r = '';
let i;
for (i = 0; i < target.length; i++) {
r += source[i];
return r;
}
r += `{${S(target[i])}}`;
}
r += source[i];
return r;
};
Loading