|
|
|
@ -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!()
|
|
|
|
|
},
|
|
|
|
|