├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── README.md └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | [root] 2 | name = "sylph" 3 | version = "0.1.0" 4 | dependencies = [ 5 | "nom 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 6 | ] 7 | 8 | [[package]] 9 | name = "nom" 10 | version = "2.0.0" 11 | source = "registry+https://github.com/rust-lang/crates.io-index" 12 | 13 | [metadata] 14 | "checksum nom 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "628d6ee18ab0ca1c1feb3331caa6ad2e53f6053b2505662b90d194889bbcd571" 15 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sylph" 3 | version = "0.1.0" 4 | authors = ["Eevee (Lexy Munroe) "] 5 | 6 | [dependencies] 7 | nom = "^2.0" 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sylph 2 | 3 | Don't worry! This will never, ever be finished. 4 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | extern crate nom; 3 | 4 | use std::io::{self, Read}; 5 | use std::str; 6 | 7 | use nom::{IResult, alphanumeric}; 8 | 9 | struct StringLiteral<'a> { 10 | value: &'a str, 11 | } 12 | 13 | struct FunctionCall<'a> { 14 | function_name: &'a str, 15 | argument: StringLiteral<'a>, 16 | } 17 | 18 | 19 | // Parser stuff 20 | named!(string_literal<&[u8], StringLiteral>, 21 | do_parse!( 22 | value: map_res!( 23 | delimited!(tag!("\""), take_until!("\""), tag!("\"")), 24 | str::from_utf8 25 | ) >> 26 | (StringLiteral{value: value}) 27 | ) 28 | ); 29 | 30 | named!(function_call<&[u8], FunctionCall>, 31 | do_parse!( 32 | name: map_res!(alphanumeric, str::from_utf8) >> 33 | tag!("(") >> 34 | arg: string_literal >> 35 | tag!(")") >> 36 | (FunctionCall{ function_name: name, argument: arg }) 37 | ) 38 | ); 39 | 40 | fn print(argument: &StringLiteral) { 41 | println!("{}", argument.value); 42 | } 43 | 44 | fn main() { 45 | let mut buffer = String::new(); 46 | io::stdin().read_to_string(&mut buffer); 47 | let result = function_call(buffer.as_bytes()); 48 | match result { 49 | IResult::Done(_leftovers, call) => { 50 | match call.function_name { 51 | "print" => { 52 | print(&call.argument); 53 | } 54 | _ => panic!("oh no no such function {}", call.function_name), 55 | } 56 | } 57 | IResult::Incomplete(_needed) => { 58 | println!("early termination what"); 59 | } 60 | IResult::Error(err) => { 61 | println!("boom! {:?}", err); 62 | } 63 | } 64 | } 65 | --------------------------------------------------------------------------------