diff --git a/Cargo.toml b/Cargo.toml index 56d4352..dddee04 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["parse", "dump", "serialize", "deserialize", "stringify"] license = "MIT" name = "gura" repository = "https://github.com/gura-conf/gura-rs-parser" -version = "0.5.1" +version = "0.5.2" [dependencies] float-pretty-print = "0.1.0" diff --git a/src/parser.rs b/src/parser.rs index bf20ef5..b1115a6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1310,7 +1310,7 @@ fn number(text: &mut Input) -> RuleResult { // Checks hexadecimal, octal and binary format let prefix = result.get(0..2).unwrap_or(""); - if vec!["0x", "0o", "0b"].contains(&prefix) { + if ["0x", "0o", "0b"].contains(&prefix) { let without_prefix = result[2..].to_string(); let base = match prefix { "0x" => 16, @@ -1489,6 +1489,7 @@ fn pair(text: &mut Input) -> RuleResult { if let GuraType::Indentation(current_indentation_level) = matches(text, vec![Box::new(ws_with_indentation)])? { + println!("current_indentation_level: {}", current_indentation_level); let matched_key = matches(text, vec![Box::new(key)])?; if let GuraType::String(key_value) = matched_key { @@ -1496,6 +1497,7 @@ fn pair(text: &mut Input) -> RuleResult { // Check indentation let last_indentation_block = get_last_indentation_level(text); + println!("last_indentation_block: {:?}", last_indentation_block); // Check if indentation is divisible by 4 if current_indentation_level % 4 != 0 { @@ -1524,6 +1526,16 @@ fn pair(text: &mut Input) -> RuleResult { Ordering::Equal => (), } } else { + // If it's the first pair, the indentation level is should be 0 + if current_indentation_level > 0 { + return Err(GuraError { + pos: pos_before_pair, + line: text.line, + msg: String::from("First pair must have indentation level 0"), + kind: Error::InvalidIndentationError, + }); + } + text.indentation_levels.push(current_indentation_level); } diff --git a/tests/exception_report.rs b/tests/exception_report.rs index 4f43d97..b9f7a44 100644 --- a/tests/exception_report.rs +++ b/tests/exception_report.rs @@ -226,3 +226,9 @@ fn test_duplicated_import_1() { fn test_duplicated_import_2() { test_fail("importing_error_2.ura", Error::DuplicatedImportError, 86, 5); } + +/// Tests issue https://github.com/gura-conf/gura/issues/12 +#[test] +fn test_array_issue_12() { + test_fail("issue_12.ura", Error::InvalidIndentationError, 0, 2); +} diff --git a/tests/exception_report/tests-files/issue_12.ura b/tests/exception_report/tests-files/issue_12.ura new file mode 100644 index 0000000..145c37e --- /dev/null +++ b/tests/exception_report/tests-files/issue_12.ura @@ -0,0 +1,6 @@ + + hosts: [ + "alpha", + "omega" + ] + \ No newline at end of file