From be34037803a2798a8d6b20cadea74f6d5f6b1314 Mon Sep 17 00:00:00 2001 From: rhysd Date: Thu, 4 Jun 2015 01:04:57 +0900 Subject: [PATCH] use standard Readline.readline() --- README.md | 8 +++++--- src/core.cr | 4 ++-- src/crisp.cr | 4 ++-- src/readline.cr | 21 --------------------- 4 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 src/readline.cr diff --git a/README.md b/README.md index f3cbb32..74422c7 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,17 @@ This project is a toy box for my dynamic language ideas. ## So Many Tasks -- [ ] Refactorings +- __Refactorings__ - [ ] Make `is_a?` guards more elegant - [ ] Import test cases from Mal - [ ] Add CI - [ ] More OOP (`evaluator`) - - [ ] Use standard `readline` implementation + - [x] Use standard `readline` implementation - [ ] Better lexer and parser - [ ] Add examples -- [ ] Add more language features using Crystal's semantics (e.g. union type) + - [ ] More convenient REPL (e.g. completion) +- __New language features using Crystal's semantics__ + - [ ] Algebraic data type - ... ## Installation diff --git a/src/core.cr b/src/core.cr index 637cd54..a5de839 100644 --- a/src/core.cr +++ b/src/core.cr @@ -1,10 +1,10 @@ require "time" +require "readline" require "./types" require "./error" require "./printer" require "./reader" -require "./readline" module Crisp @@ -274,7 +274,7 @@ end def self.readline(args) head = args.first.unwrap eval_error "1st argument of readline must be string" unless head.is_a? String - my_readline head + Readline.readline head end def self.meta(args) diff --git a/src/crisp.cr b/src/crisp.cr index edd6019..4a6b25c 100755 --- a/src/crisp.cr +++ b/src/crisp.cr @@ -1,8 +1,8 @@ #! /usr/bin/env crystal run require "colorize" +require "readline" -require "./readline" require "./reader" require "./printer" require "./types" @@ -269,7 +269,7 @@ unless ARGV.empty? exit end -while line = my_readline("Crisp> ") +while line = Readline.readline("Crisp> ", true) begin puts rep(line) rescue e diff --git a/src/readline.cr b/src/readline.cr deleted file mode 100644 index e57099a..0000000 --- a/src/readline.cr +++ /dev/null @@ -1,21 +0,0 @@ -# Note: -# Crystal already has "readline" library. -# I implemented a subset of it again for practice. - -@[Link("readline")] -lib LibReadline - fun readline(prompt : UInt8*) : UInt8* - fun add_history(line : UInt8*) -end - -def my_readline(prompt = "") - line = LibReadline.readline(prompt) - if line - LibReadline.add_history(line) - String.new(line) - else - nil - end -ensure - LibC.free(line as Void*) if line -end