copperline & nom
Building interactive command line tools
copperline + nom = REPL
Configuration
emacs vs vi
UTF-8 vs Ascii
use copperline::{Encoding,EditMode};
let cfg = copperline::Config {� encoding: Encoding::Utf8,� mode: EditMode::Vi�};
>>
# Prompt
!!
let mut cl = Copperline::new();�while let Ok(line) =
cl.read_line(">> ", &cfg) {�
// do stuff�}
Rewrite
History
while let Ok(line) =
cl.read_line(">> ", &cfg) {�
handle(&line); // prevent a clone!�cl.add_history(line);
}
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
Input
copperline + nom = REPL
C-C-C-Combinator!
0
cp
{parsing}
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)� )�);
�tag!("quote")
�space
space?
map_res!(� alphanumeric,� std::str::from_utf8�)
chain!(� tag!("quote") ~� stock: alpha ,� || stock�)
named!(quote_parser(&[u8])
-> &str,�
// parser(s)
);
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)� )�);
named!(commands(&[u8]) -> Command,� alt!(� tag!("check") => {|_| Command::Check } |� tag!("quote") => {|_| Command::Quote }� )�);
named!(venue_stock<&[u8], (&str, &str)>,� chain!(� space ~� venue: an_string ~� space ~� stock: an_string ,�� || (venue, stock)� )�);
named!(an_string<&str>,� map_res!(� alphanumeric,� std::str::from_utf8� )�);
named!(usize_digit<usize>,� map_res!(� numeric_string,� std::str::FromStr::from_str� )�);
Prototype
https://github.com/hjr3/stockfighter
Demo
About Me
Herman J. Radtke III
VP of Eng at Nordstromrack.com | HauteLook
@hermanradtke on twitter
github.com/hjr3
Attribution