difftreelog
feat(parser) import statement parsing
in: master
2 files changed
crates/jsonnet-parser/src/expr.rsdiffbeforeafterboth197 /// a = 3197 /// a = 3198 Bind(BindSpec),198 Bind(BindSpec),199 /// import "hello"199 /// import "hello"200 Import(String),200 Import(PathBuf),201 /// importStr "file.txt"201 /// importStr "file.txt"202 ImportStr(String),202 ImportStr(PathBuf),203 /// error "I'm broken"203 /// error "I'm broken"204 Error(LocExpr),204 Error(LocExpr),205 /// a(b, c)205 /// a(b, c)crates/jsonnet-parser/src/lib.rsdiffbeforeafterboth23 /// Standard C-like comments23 /// Standard C-like comments24 rule comment()24 rule comment()25 = "//" (!['\n'][_])* "\n"25 = "//" (!['\n'][_])* "\n"26 / "/*" (!("*/")[_])* "*/"26 / "/*" ("\\*/" / "\\\\" / (!("*/")[_]))* "*/"27 / "#" (!['\n'][_])* "\n"27 / "#" (!['\n'][_])* "\n"282829 rule single_whitespace() = quiet!{([' ' | '\r' | '\n' | '\t'] / comment())} / expected!("<whitespace>")29 rule single_whitespace() = quiet!{([' ' | '\r' | '\n' | '\t'] / comment())} / expected!("<whitespace>")89 / "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}89 / "@'" str:$(("''" / (!['\''][_]))*) "'" {str.replace("''", "'")}90 / "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}90 / "@\"" str:$(("\"\"" / (!['"'][_]))*) "\"" {str.replace("\"\"", "\"")}91 // TODO: This is temporary workaround, i still dont know how to write this correctly btw.91 // TODO: This is temporary workaround, i still dont know how to write this correctly btw.92 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<1, 1> whole_line())+) " "*<0, 0> "|||" {deent(str)}92 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<1, 1> whole_line())+) " "*<0, 0> "|||" {deent(str)}93 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<2, 2> whole_line())+) " "*<1, 1> "|||" {deent(str)}93 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<2, 2> whole_line())+) " "*<1, 1> "|||" {deent(str)}94 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<3, 3> whole_line())+) " "*<2, 2> "|||" {deent(str)}94 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<3, 3> whole_line())+) " "*<2, 2> "|||" {deent(str)}95 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<4, 4> whole_line())+) " "*<3, 3> "|||" {deent(str)}95 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<4, 4> whole_line())+) " "*<3, 3> "|||" {deent(str)}96 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<5, 5> whole_line())+) " "*<4, 4> "|||" {deent(str)}96 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<5, 5> whole_line())+) " "*<4, 4> "|||" {deent(str)}97 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<6, 6> whole_line())+) " "*<5, 5> "|||" {deent(str)}97 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<6, 6> whole_line())+) " "*<5, 5> "|||" {deent(str)}98 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<7, 7> whole_line())+) " "*<6, 6> "|||" {deent(str)}98 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<7, 7> whole_line())+) " "*<6, 6> "|||" {deent(str)}99 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<8, 8> whole_line())+) " "*<7, 7> "|||" {deent(str)}99 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<8, 8> whole_line())+) " "*<7, 7> "|||" {deent(str)}100 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<9, 9> whole_line())+) " "*<8, 8> "|||" {deent(str)}100 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<9, 9> whole_line())+) " "*<8, 8> "|||" {deent(str)}101 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<10, 10> whole_line())+) " "*<9, 9> "|||" {deent(str)}101 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<10, 10> whole_line())+) " "*<9, 9> "|||" {deent(str)}102 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<11, 11> whole_line())+) " "*<10, 10> "|||" {deent(str)}102 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<11, 11> whole_line())+) " "*<10, 10> "|||" {deent(str)}103 / "|||" (!['\n']single_whitespace())+ "\n" str:$((" "*<12, 12> whole_line())+) " "*<11, 10> "|||" {deent(str)}103 / "|||" (!['\n']single_whitespace())* "\n" str:$((" "*<12, 12> whole_line())+) " "*<11, 10> "|||" {deent(str)}104104105 pub rule field_name(s: &ParserSettings) -> expr::FieldName105 pub rule field_name(s: &ParserSettings) -> expr::FieldName106 = name:id() {expr::FieldName::Fixed(name)}106 = name:id() {expr::FieldName::Fixed(name)}192 / local_expr(s)192 / local_expr(s)193 / if_then_else_expr(s)193 / if_then_else_expr(s)194195 / l(s,<keyword("import") _ path:string() {Expr::Import(PathBuf::from(path))}>)196 / l(s,<keyword("importstr") _ path:string() {Expr::ImportStr(PathBuf::from(path))}>)194197195 / l(s,<keyword("function") _ "(" _ params:params(s) _ ")" _ expr:expr(s) {Expr::Function(params, expr)}>)198 / l(s,<keyword("function") _ "(" _ params:params(s) _ ")" _ expr:expr(s) {Expr::Function(params, expr)}>)196 / l(s,<assertion:assertion(s) _ ";" _ expr:expr(s) { Expr::AssertExpr(assertion, expr) }>)199 / l(s,<assertion:assertion(s) _ ";" _ expr:expr(s) { Expr::AssertExpr(assertion, expr) }>)366 );369 );367 }370 }371372 #[test]373 fn imports() {374 assert_eq!(375 parse!("import \"hello\""),376 el!(Expr::Import(PathBuf::from("hello"))),377 );378 }368379369 #[test]380 #[test]370 fn empty_object() {381 fn empty_object() {