Browse Source

use standard Readline.readline()

master
rhysd 9 years ago
parent
commit
be34037803
4 changed files with 9 additions and 28 deletions
  1. +5
    -3
      README.md
  2. +2
    -2
      src/core.cr
  3. +2
    -2
      src/crisp.cr
  4. +0
    -21
      src/readline.cr

+ 5
- 3
README.md View File

@ -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

+ 2
- 2
src/core.cr View File

@ -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)

+ 2
- 2
src/crisp.cr View File

@ -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

+ 0
- 21
src/readline.cr View File

@ -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

Loading…
Cancel
Save