-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update linter, only emit types, refactor to cons
- Loading branch information
Showing
35 changed files
with
1,971 additions
and
1,960 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,106 @@ | ||
#!/usr/bin/env node | ||
import { stepOnceSKI } from "../lib/evaluator/skiEvaluator.js"; | ||
import { generateExpr, SKIExpression } from "../lib/ski/expression.js"; | ||
import { SKITerminalSymbol } from "../lib/ski/terminal.js"; | ||
import { hrtime } from "process"; | ||
|
||
import * as terminalKit from 'terminal-kit' | ||
import { hrtime } from 'process' | ||
import { create } from 'random-seed' | ||
import { Terminal } from 'terminal-kit' | ||
import { SKIExpression, generate } from '../lib/ski/expression' | ||
import { SKITerminalSymbol } from '../lib/ski/terminal' | ||
import { stepOnceSKI } from '../lib' | ||
import rsexport from 'random-seed'; | ||
const { create } = rsexport; | ||
|
||
function colorizeSymbol (sym: SKITerminalSymbol): string { | ||
import tkexport from 'terminal-kit'; | ||
import Terminal from 'terminal-kit/Terminal.js'; | ||
const { terminal } = tkexport; | ||
|
||
function colorizeSymbol(sym: SKITerminalSymbol): string { | ||
switch (sym) { | ||
case SKITerminalSymbol.S: | ||
return ' ^[red]S^ ' | ||
return ' ^[red]S^ '; | ||
case SKITerminalSymbol.K: | ||
return ' ^[green]K^ ' | ||
return ' ^[green]K^ '; | ||
case SKITerminalSymbol.I: | ||
return ' ^[blue]I^ ' | ||
return ' ^[blue]I^ '; | ||
default: | ||
return '?' | ||
return '?'; | ||
} | ||
} | ||
|
||
function colorizeExpression (expr: SKIExpression): string { | ||
function colorizeExpression(expr: SKIExpression): string { | ||
switch (expr.kind) { | ||
case 'terminal': | ||
return colorizeSymbol(expr.sym) | ||
return colorizeSymbol(expr.sym); | ||
case 'non-terminal': { | ||
return [ | ||
'(', | ||
colorizeExpression(expr.lft), | ||
colorizeExpression(expr.rgt), | ||
')' | ||
].join('') | ||
].join(''); | ||
} | ||
} | ||
} | ||
|
||
function formatted (expr: SKIExpression): string { | ||
return '> ' + colorizeExpression(expr) + '\n' | ||
function formatted(expr: SKIExpression): string { | ||
return '> ' + colorizeExpression(expr) + '\n'; | ||
} | ||
|
||
function runTUI (): number { | ||
const term : Terminal = terminalKit.terminal | ||
const seed = hrtime.bigint() | ||
const randomSeed = create(seed.toString()) | ||
const N = 32 | ||
const MAX_ITER = 100 | ||
function runTUI(): number { | ||
const term: Terminal = terminal; | ||
const seed = hrtime.bigint(); | ||
const rs = create(seed.toString()); | ||
const N = 32; | ||
const MAX_ITER = 100; | ||
|
||
let expression = generate(randomSeed, N) | ||
let expression = generateExpr(rs, N); | ||
|
||
term.cyan('Control C or q or Q exits. ' + | ||
's steps once. ' + | ||
'm steps many. ' + | ||
'g regenerates a new expression. \n') | ||
's steps once. ' + | ||
'm steps many. ' + | ||
'g regenerates a new expression. \n'); | ||
|
||
term.grabInput({}) | ||
term.grabInput({}); | ||
term.on('key', (keyName: string) => { | ||
switch (keyName) { | ||
case 'CTRL_C': | ||
case 'q': | ||
case 'Q': | ||
term.grabInput(false) | ||
break | ||
term.grabInput(false); | ||
break; | ||
case 's': { | ||
const stepResult = stepOnceSKI(expression) | ||
expression = stepResult.expr | ||
term(formatted(expression)) | ||
break | ||
const stepResult = stepOnceSKI(expression); | ||
expression = stepResult.expr; | ||
term(formatted(expression)); | ||
break; | ||
} | ||
case 'm': { | ||
let loop = true | ||
let iterations = 0 | ||
let loop = true; | ||
let iterations = 0; | ||
|
||
while (loop && iterations < MAX_ITER) { | ||
const stepResult = stepOnceSKI(expression) | ||
expression = stepResult.expr | ||
const stepResult = stepOnceSKI(expression); | ||
expression = stepResult.expr; | ||
if (stepResult.altered) { | ||
term(formatted(expression)) | ||
term(formatted(expression)); | ||
} | ||
loop = stepResult.altered | ||
iterations = iterations + 1 | ||
loop = stepResult.altered; | ||
iterations = iterations + 1; | ||
} | ||
|
||
if (iterations === MAX_ITER) { | ||
term.red(`stopped evaluating after ${iterations.toString()} iterations. \n`) | ||
term.red(`stopped evaluating after ${iterations.toString()} iterations. \n`); | ||
} | ||
|
||
break | ||
break; | ||
} | ||
case 'g': { | ||
expression = generate(randomSeed, N) | ||
term(formatted(expression)) | ||
break | ||
expression = generateExpr(rs, N); | ||
term(formatted(expression)); | ||
break; | ||
} | ||
default: | ||
term.red('unrecognized command key: ' + keyName + '\n') | ||
term.red('unrecognized command key: ' + keyName + '\n'); | ||
} | ||
}) | ||
}); | ||
|
||
return 0 | ||
return 0; | ||
} | ||
|
||
process.exitCode = runTUI() | ||
process.exitCode = runTUI(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
import eslint from '@eslint/js' | ||
import tseslint from 'typescript-eslint' | ||
import path from "path" | ||
import url from "url" | ||
|
||
const __meta_url = new url.URL(import.meta.url) | ||
const __filename = url.fileURLToPath(__meta_url) | ||
const __dirname = path.dirname(__filename) | ||
import eslint from '@eslint/js'; | ||
import tseslint from 'typescript-eslint'; | ||
import stylisticTs from '@stylistic/eslint-plugin-ts'; | ||
|
||
export default tseslint.config( | ||
{ | ||
files: ["**/*.{ts,mjs}"], | ||
files: ['**/*.ts'] | ||
}, | ||
{ | ||
ignores: [ | ||
"**/node_modules/**", | ||
"build/**", | ||
], | ||
ignores: ['**/build/**', '**/node_modules/**'], | ||
}, | ||
eslint.configs.recommended, | ||
...tseslint.configs.strictTypeChecked, | ||
...tseslint.configs.stylisticTypeChecked, | ||
...tseslint.configs.recommendedTypeChecked, | ||
{ | ||
plugins: { | ||
'@typescript-eslint': tseslint.plugin, | ||
'@stylistic/ts': stylisticTs | ||
}, | ||
languageOptions: { | ||
parser: tseslint.parser, | ||
parserOptions: { | ||
project: true, | ||
tsconfigRootDir: __dirname, | ||
}, | ||
}, | ||
}, | ||
rules: { | ||
'@typescript-eslint/no-unsafe-argument': 'error', | ||
'@typescript-eslint/no-unsafe-assignment': 'error', | ||
'@typescript-eslint/no-unsafe-call': 'error', | ||
'@typescript-eslint/no-unsafe-member-access': 'error', | ||
'@typescript-eslint/no-unsafe-return': 'error', | ||
'@stylistic/ts/semi': 'error', | ||
'@stylistic/ts/indent': ['error', 2], | ||
'@stylistic/ts/quotes': ['error', 'single'] | ||
}, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { parseLambda } from '../parser/untyped' | ||
import { parseLambda } from '../parser/untyped.ts'; | ||
|
||
export const [, predLambda] = parseLambda('λn.λf.λx.n(λg.λh.h(gf))(λu.x)(λu.u)') | ||
export const [, predLambda] = parseLambda('λn.λf.λx.n(λg.λh.h(gf))(λu.x)(λu.u)'); |
Oops, something went wrong.