Add basic keyword, string system

main
Elnu 2 years ago
parent 46acbce60e
commit 24e33aa550

@ -12,13 +12,21 @@ pub fn parse(file_path: &str) {
let file = RpyParser::parse(Rule::file, &unparsed_file)
.expect("unsuccessful parse") // unwrap the parse result
.next().unwrap(); // get and unwrap the `file` rule; never fails
for record in file.into_inner() {
match record.as_rule() {
for line in file.into_inner() {
match line.as_rule() {
Rule::line => {
for field in record.into_inner().map(|pairs| pairs.as_str()) {
println!("'{field}'");
println!("Line:");
for token in line.into_inner() {
match token.as_rule() {
Rule::token => {
println!("{}", token.as_str());
},
_ => {
println!("{}", token.as_str());
}
}
}
println!()
},
Rule::EOI => (),
_ => unreachable!(),

@ -4,14 +4,25 @@ WHITESPACE = _{ " " }
// characters are anything but newlines
char = { !NEWLINE ~ ANY }
// token definition
// http://pest.rs/book/grammars/syntax.html#atomic
inner = @{ char* }
token = { string | keyword }
// has to be atomic for no implicit separate (spaces)
keyword = @{ (!(WHITESPACE | NEWLINE) ~ ANY)+ }
// strings cannot contain quotes
// TODO: escaped quotes
string_data = @{ (!"\"" ~ ANY)* }
string = ${ "\"" ~ string_data ~ "\"" }
// comments are a # followed by
// any number of non-newline characters
COMMENT = _{ "#" ~ char* }
// statements are comprised of at least one character
statement = { char+ }
// lines are comprised of a statement
line = { statement }
line = { token+ }
file = { SOI ~ (line ~ ("\r\n" | "\n")*)* ~ "\n"* ~ EOI }
file = { SOI ~ line ~ (NEWLINE+ ~ line)* ~ NEWLINE* ~ EOI }
Loading…
Cancel
Save