浏览代码

use standard Readline.readline()

master
rhysd 9 年前
父节点
当前提交
be34037803
共有 4 个文件被更改,包括 9 次插入28 次删除
  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 查看文件

@ -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 查看文件

@ -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 查看文件

@ -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 查看文件

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

正在加载...
取消
保存