Support SELF keyword in Podlang parser (#368)
* Support SELF keyword in Podlang parser * Add pretty-printing for SELF
This commit is contained in:
parent
0606a4098b
commit
c7b39f21f0
5 changed files with 39 additions and 5 deletions
|
|
@ -68,7 +68,8 @@ literal_value = {
|
|||
literal_raw |
|
||||
literal_pod_id |
|
||||
literal_string |
|
||||
literal_int
|
||||
literal_int |
|
||||
self_keyword
|
||||
}
|
||||
|
||||
// Primitive literal types
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ mod tests {
|
|||
middleware::{
|
||||
hash_str, CustomPredicate, CustomPredicateBatch, CustomPredicateRef, Key,
|
||||
NativePredicate, Params, PodId, PodType, Predicate, RawValue, StatementTmpl,
|
||||
StatementTmplArg, Value, Wildcard, KEY_SIGNER, KEY_TYPE,
|
||||
StatementTmplArg, Value, Wildcard, KEY_SIGNER, KEY_TYPE, SELF,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -877,6 +877,7 @@ mod tests {
|
|||
Equal(?E["int"], {})
|
||||
Equal(?F["bool"], {})
|
||||
Equal(?G["sk"], {})
|
||||
Equal(?H["self"], SELF)
|
||||
)
|
||||
"#,
|
||||
Value::from(pk).to_podlang_string(),
|
||||
|
|
@ -895,6 +896,8 @@ mod tests {
|
|||
Equal(?D["string"], "hello")
|
||||
Equal(?E["int"], 123)
|
||||
Equal(?F["bool"], true)
|
||||
Equal(?G["sk"], SecretKey(random_secret_key_base_64))
|
||||
Equal(?H["self"], SELF)
|
||||
)
|
||||
*/
|
||||
|
||||
|
|
@ -902,8 +905,6 @@ mod tests {
|
|||
let processed = parse(&input, ¶ms, &[])?;
|
||||
let request_templates = processed.request_templates;
|
||||
|
||||
assert_eq!(request_templates.len(), 7);
|
||||
|
||||
let expected_templates = vec![
|
||||
StatementTmpl {
|
||||
pred: Predicate::Native(NativePredicate::Equal),
|
||||
|
|
@ -933,6 +934,10 @@ mod tests {
|
|||
pred: Predicate::Native(NativePredicate::Equal),
|
||||
args: vec![sta_ak(("G", 6), "sk"), sta_lit(Value::from(sk))],
|
||||
},
|
||||
StatementTmpl {
|
||||
pred: Predicate::Native(NativePredicate::Equal),
|
||||
args: vec![sta_ak(("H", 7), "self"), sta_lit(Value::from(SELF))],
|
||||
},
|
||||
];
|
||||
|
||||
assert_eq!(request_templates, expected_templates);
|
||||
|
|
|
|||
|
|
@ -507,6 +507,16 @@ mod tests {
|
|||
assert_round_trip(&input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_round_trip_self() {
|
||||
let input = r#"
|
||||
self_test(Pod) = AND(
|
||||
Equal(?Pod["self"], SELF)
|
||||
)
|
||||
"#;
|
||||
assert_round_trip(input);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pretty_print_demonstration() {
|
||||
let input = r#"
|
||||
|
|
|
|||
|
|
@ -817,6 +817,7 @@ fn process_literal_value(
|
|||
})?;
|
||||
Ok(Value::from(secret_key))
|
||||
}
|
||||
Rule::self_keyword => Ok(Value::from(middleware::SELF)),
|
||||
_ => unreachable!("Unexpected rule: {:?}", inner_lit.as_rule()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue