generated from ElnuDev/rust-project
Multiline arrays, better debugging
This commit is contained in:
parent
3794a1d607
commit
5442a8fc87
3 changed files with 21 additions and 29 deletions
|
@ -8,6 +8,13 @@ multiple lines"
|
||||||
'this is a single quote string'
|
'this is a single quote string'
|
||||||
'this also has escaped \'quotes\''
|
'this also has escaped \'quotes\''
|
||||||
this is cool # comment
|
this is cool # comment
|
||||||
[ "this", "is", "an", "array" ]
|
any empty array []
|
||||||
|
[
|
||||||
|
"this", # test
|
||||||
|
"is",
|
||||||
|
"an",
|
||||||
|
"array"
|
||||||
|
]
|
||||||
|
["this","is","an","array"]
|
||||||
|
|
||||||
huh
|
huh
|
36
src/lib.rs
36
src/lib.rs
|
@ -24,7 +24,14 @@ fn describe_token(pair: pest::iterators::Pair<Rule>) {
|
||||||
_ => unreachable!(),
|
_ => 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);
|
println!("{:?}: {}", contents_rule, str);
|
||||||
}
|
}
|
||||||
|
@ -37,33 +44,8 @@ pub fn parse(file_path: &str) {
|
||||||
for line in file.into_inner() {
|
for line in file.into_inner() {
|
||||||
match line.as_rule() {
|
match line.as_rule() {
|
||||||
Rule::line => {
|
Rule::line => {
|
||||||
println!("Line:");
|
|
||||||
for token in line.into_inner() {
|
for token in line.into_inner() {
|
||||||
match token.as_rule() {
|
describe_token(token);
|
||||||
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!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
println!()
|
println!()
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,7 +29,10 @@ string = ${
|
||||||
}
|
}
|
||||||
|
|
||||||
// ARRAY
|
// ARRAY
|
||||||
array = { "[" ~ token ~ ("," ~ token)* ~ "]"}
|
array = {
|
||||||
|
"[" ~ "]"
|
||||||
|
| "[" ~ NEWLINE* ~ token ~ ("," ~ NEWLINE* ~ token)* ~ NEWLINE* ~ "]"
|
||||||
|
}
|
||||||
|
|
||||||
// comments are a # followed by
|
// comments are a # followed by
|
||||||
// any number of non-newline characters
|
// any number of non-newline characters
|
||||||
|
|
Loading…
Add table
Reference in a new issue