1 of 27

copperline & nom

Building interactive command line tools

2 of 27

copperline + nom = REPL

3 of 27

Configuration

emacs vs vi

UTF-8 vs Ascii

4 of 27

use copperline::{Encoding,EditMode};

let cfg = copperline::Config { encoding: Encoding::Utf8,mode: EditMode::Vi};

5 of 27

>>

# Prompt

!!

6 of 27

let mut cl = Copperline::new();while let Ok(line) =

cl.read_line(">> ", &cfg) {

// do stuff}

7 of 27

Rewrite

History

8 of 27

while let Ok(line) =

cl.read_line(">> ", &cfg) {

handle(&line); // prevent a clone!cl.add_history(line);

}

9 of 27

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

Input

10 of 27

copperline + nom = REPL

11 of 27

C-C-C-Combinator!

12 of 27

0

cp

{parsing}

13 of 27

named!(quote_parser(&[u8]) -> &str,chain!(tag!("quote") ~space ~venue: map_res!(alpha,std::str::from_utf8) ~stock: map_res!(alpha,std::str::from_utf8) ,�� || (venue, stock)));

14 of 27

tag!("quote")

15 of 27

space

space?

16 of 27

map_res!(alphanumeric,std::str::from_utf8)

17 of 27

chain!(tag!("quote") ~stock: alpha ,|| stock)

18 of 27

named!(quote_parser(&[u8])

-> &str,

// parser(s)

);

19 of 27

named!(quote_parser(&[u8]) -> (&str, &str)chain!(tag!("quote") ~space ~venue: map_res!(alpha,std::str::from_utf8) ~stock: map_res!(alpha,std::str::from_utf8) ,�� || (venue, stock)));

20 of 27

named!(commands(&[u8]) -> Command,alt!(tag!("check") => {|_| Command::Check } |tag!("quote") => {|_| Command::Quote }));

21 of 27

named!(venue_stock<&[u8], (&str, &str)>,chain!(space ~venue: an_string ~space ~stock: an_string ,�� || (venue, stock)));

22 of 27

named!(an_string<&str>,map_res!(alphanumeric,std::str::from_utf8));

23 of 27

named!(usize_digit<usize>,map_res!(numeric_string,std::str::FromStr::from_str));

24 of 27

Prototype

https://github.com/hjr3/stockfighter

25 of 27

Demo

26 of 27

About Me

Herman J. Radtke III

VP of Eng at Nordstromrack.com | HauteLook

@hermanradtke on twitter

github.com/hjr3

27 of 27

Attribution