Skip to content

Commit

Permalink
Fixed #12
Browse files Browse the repository at this point in the history
+ Fixed Clippy warning
+ Bumped version to 0.5.2
  • Loading branch information
Genarito committed Oct 7, 2023
1 parent 9cd3fa6 commit 4a5863f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 13 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1489,13 +1489,15 @@ 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 {
maybe_match(text, vec![Box::new(ws)])?;

// 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 {
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/exception_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions tests/exception_report/tests-files/issue_12.ura
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

hosts: [
"alpha",
"omega"
]

0 comments on commit 4a5863f

Please sign in to comment.