Multiline arrays, better debugging

main
Elnu 2 years ago
parent 3794a1d607
commit 5442a8fc87

@ -8,6 +8,13 @@ multiple lines"
'this is a single quote string'
'this also has escaped \'quotes\''
this is cool # comment
[ "this", "is", "an", "array" ]
any empty array []
[
"this", # test
"is",
"an",
"array"
]
["this","is","an","array"]
huh

@ -24,7 +24,14 @@ fn describe_token(pair: pest::iterators::Pair<Rule>) {
_ => unreachable!(),
}
},
_ => contents.into_inner().as_str().to_owned(),
Rule::array => {
println!("array: Start array");
for token in contents.into_inner() {
describe_token(token);
}
"End array".to_string()
}
_ => contents.as_str().to_owned(),
};
println!("{:?}: {}", contents_rule, str);
}
@ -37,33 +44,8 @@ pub fn parse(file_path: &str) {
for line in file.into_inner() {
match line.as_rule() {
Rule::line => {
println!("Line:");
for token in line.into_inner() {
match token.as_rule() {
Rule::token => {
let token = token.into_inner().next().unwrap();
match token.as_rule() {
Rule::string => {
let string_data = token.into_inner().next().unwrap();
let str = string_data.as_str();
println!("string: {}", match string_data.as_rule() {
Rule::single_quote_string_data => str.replace("\\'", "'"),
Rule::double_quote_string_data => str.replace("\\\"", "\""),
_ => unreachable!(),
});
},
Rule::array => {
println!("Array:");
for element in token.into_inner() {
describe_token(element);
}
}
Rule::keyword => println!("keyword: {}", token.as_str()),
_ => unreachable!(),
};
},
_ => unreachable!(),
}
describe_token(token);
}
println!()
},

@ -29,7 +29,10 @@ string = ${
}
// ARRAY
array = { "[" ~ token ~ ("," ~ token)* ~ "]"}
array = {
"[" ~ "]"
| "[" ~ NEWLINE* ~ token ~ ("," ~ NEWLINE* ~ token)* ~ NEWLINE* ~ "]"
}
// comments are a # followed by
// any number of non-newline characters

Loading…
Cancel
Save