Pārlūkot izejas kodu

src/asm_parser.rs: allow initial whitespace

Rich Lane 8 gadi atpakaļ
vecāks
revīzija
0e73d3267b
2 mainītis faili ar 11 papildinājumiem un 1 dzēšanām
  1. 1 1
      src/asm_parser.rs
  2. 10 0
      tests/asm_parser.rs

+ 1 - 1
src/asm_parser.rs

@@ -118,7 +118,7 @@ fn format_parse_error(parse_error: ParseError<State<&str>>) -> String {
 ///
 /// The instructions are not validated and may have invalid names and operand types.
 pub fn parse(input: &str) -> Result<Vec<Instruction>, String> {
-    match many(parser(instruction)).skip(eof()).parse(State::new(input)) {
+    match spaces().with(many(parser(instruction)).skip(eof())).parse(State::new(input)) {
         Ok((insts, _)) => Ok(insts),
         Err(err) => Err(format_parse_error(err)),
     }

+ 10 - 0
tests/asm_parser.rs

@@ -311,3 +311,13 @@ fn test_error_unexpected_character() {
                Err("Parse error at line 2 column 1: unexpected '^', expected end of input"
                    .to_string()));
 }
+
+#[test]
+fn test_initial_whitespace() {
+    assert_eq!(parse(" 
+                      exit"),
+               Ok(vec![Instruction {
+                           name: "exit".to_string(),
+                           operands: vec![],
+                       }]));
+}