Skip to content

Commit

Permalink
fix command-line REPL (#1674)
Browse files Browse the repository at this point in the history
* make repl index runnable

* fix repl parsing of chapters

* fix output of repl
  • Loading branch information
s-kybound authored Apr 15, 2024
1 parent 78c4f26 commit ce94ea0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/repl/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env node

import { Command } from '@commander-js/extra-typings'

import { getReplCommand } from './repl'
Expand Down
2 changes: 1 addition & 1 deletion src/repl/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
validateChapterAndVariantCombo
} from './utils'

export const transpilerCommand = new Command()
export const transpilerCommand = new Command('transpiler')
.addOption(
getVariantOption(Variant.DEFAULT, [Variant.DEFAULT, Variant.GPU, Variant.LAZY, Variant.NATIVE])
)
Expand Down
15 changes: 8 additions & 7 deletions src/repl/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { parseError, type Context } from '..'
export function chapterParser(str: string): Chapter {
let foundChapter: string | undefined

if (/^[0-9]$/.test(str)) {
if (/^-?[0-9]+$/.test(str)) {
// Chapter is fully numeric
const value = parseInt(str)
foundChapter = Object.keys(Chapter).find(chapterName => Chapter[chapterName] === value)
Expand Down Expand Up @@ -66,13 +66,14 @@ export function validChapterVariant(language: Language) {

export function handleResult(result: Result, context: Context, verboseErrors: boolean) {
if (result.status === 'finished' || result.status === 'suspended-non-det') {
if (
result instanceof Closure ||
typeof result === 'function' ||
result.representation !== undefined
) {
return result.toString()
if (result.representation !== undefined) {
return result.representation
}

if (result.value instanceof Closure || typeof result.value === 'function') {
return result.value.toString()
}

return stringify(result.value)
}

Expand Down

0 comments on commit ce94ea0

Please sign in to comment.