parse_from_stdin

Function parse_from_stdin 

Source
pub fn parse_from_stdin() -> Parser
Expand description

Create a parser for the standard input. The source is set to the console and the name is the empty string to indicate this. Errors reading from standard input are ignored for robustness in pipelines.

Examples found in repository?
examples/book_building_parse_integer_2.rs (line 10)
9fn main() {
10    let mut parser = trivet::parse_from_stdin();
11    match parse_unsigned_integer(&mut parser) {
12        Ok(value) => println!("{}", value),
13        Err(err) => println!("ERROR: {}", err),
14    }
15}
More examples
Hide additional examples
examples/book_math_parser.rs (line 106)
105pub fn main() -> ParseResult<()> {
106    let mut parser = parse_from_stdin();
107    parser.consume_ws();
108    while !parser.is_at_eof() {
109        let number = parse_top_expr_ws(&mut parser)?;
110        println!("  {}", number);
111    }
112    Ok(())
113}
examples/book_numbers_float.rs (line 2)
1fn main() {
2    let mut parser = trivet::parse_from_stdin();
3    while !parser.is_at_eof() {
4        match parser.parse_f64_ws() {
5            Err(err) => {
6                println!("ERROR: {}", err);
7            }
8            Ok(value) => {
9                println!("  {}", value);
10            }
11        }
12    }
13}
examples/integers.rs (line 14)
12fn main() -> ParseResult<()> {
13    // Make a new parser and wrap the standard input.
14    let mut parser = trivet::parse_from_stdin();
15    match parse_unsigned_integer(&mut parser) {
16        Err(err) => {
17            println!("{}", err);
18        }
19        Ok(value) => {
20            println!("{}", value);
21        }
22    }
23    Ok(())
24}
examples/passthrough.rs (line 7)
6pub fn main() -> ParseResult<()> {
7    let mut parser = parse_from_stdin();
8    while !parser.is_at_eof() {
9        // Read some bytes and then write them out.
10        let value = parser.peek_n(57);
11        // We can't use value.len() because that is in bytes, not characters.
12        for _ in value.chars() {
13            parser.consume();
14        }
15        print!("{}", value);
16    }
17    Ok(())
18}
examples/book_cookbook_json_names.rs (line 8)
7pub fn main() -> ParseResult<()> {
8    let mut parser = parse_from_stdin();
9    let mut jp = JSONParser::new();
10    let doc = jp.parse_value_ws(&mut parser)?;
11
12    // Look for and print any element for name at the top level, but only if the
13    // input is a JSON object.
14    if let JSON::Object(map) = doc {
15        if let Some(value) = map.get("name") {
16            println!("name is {}", value);
17        }
18    }
19    Ok(())
20}