summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-05-09 10:32:15 +0200
committerMatthias Beyer <mail@beyermatthias.de>2020-05-09 10:41:15 +0200
commit2362aa34cd7409ba02fc5f42e4e07bd318530275 (patch)
tree9e1836abc572a8c32a4b74c28f34edb28b4289e1
parentdc4c5a3fdd0f01d331e9e53ed4038e4653f5bea1 (diff)
Add logging in resolver
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--src/resolver.rs70
1 files changed, 50 insertions, 20 deletions
diff --git a/src/resolver.rs b/src/resolver.rs
index ea7fbd3..acbaeb6 100644
--- a/src/resolver.rs
+++ b/src/resolver.rs
@@ -11,42 +11,72 @@ pub fn resolve<'doc, O>(obj: &'doc O, tokens: &Token, error_if_not_found: bool)
-> Result<Option<&'doc O>>
where O: Object<'doc>
{
+ trace!("Resolving Token: {:?}", tokens);
match obj.get_type() {
ObjectType::Map => {
+ trace!("Found object type Map");
match tokens {
- Token::Identifier { ref ident, .. } => match obj.at_key(ident)? {
- None => if error_if_not_found {
- Err(Error::IdentifierNotFoundInDocument(ident.to_owned()))
- } else {
- Ok(None)
+ Token::Identifier { ref ident, .. } => {
+ trace!("Checking object at ident {}", ident);
+ match obj.at_key(ident)? {
+ None => if error_if_not_found {
+ trace!("Not found, erroring");
+ Err(Error::IdentifierNotFoundInDocument(ident.to_owned()))
+ } else {
+ trace!("Not found, not erroring");
+ Ok(None)
+ }
+ Some(sub_document) => {
+ trace!("Found sub-document, getting next token");
+ match tokens.next() {
+ Some(next) => resolve(sub_document, next, error_if_not_found),
+ None => {
+ trace!("No next token, returning");
+ Ok(Some(sub_document))
+ },
+ }
+ },
}
- Some(sub_document) => match tokens.next() {
- Some(next) => resolve(sub_document, next, error_if_not_found),
- None => Ok(Some(sub_document)),
- },
},
- Token::Index { idx, .. } => Err(Error::NoIndexInTable(*idx)),
+ Token::Index { idx, .. } => {
+ trace!("Token is index, but cannot index at document, erroring...");
+ Err(Error::NoIndexInTable(*idx))
+ },
}
},
ObjectType::Array => {
+ trace!("Found object type Array");
match tokens {
- Token::Index { idx, .. } => match tokens.next() {
- Some(next) => {
- if let Some(subobj) = obj.at_index(*idx)? {
- resolve(subobj, next, error_if_not_found)
- } else {
- Ok(None)
- }
- },
- None => Ok(Some(obj)),
+ Token::Index { idx, .. } => {
+ trace!("Checking object at index {}", idx);
+ match tokens.next() {
+ Some(next) => {
+ trace!("There is another token...");
+ if let Some(subobj) = obj.at_index(*idx)? {
+ trace!("And there's a subobject, resolving...");
+ resolve(subobj, next, error_if_not_found)
+ } else {
+ trace!("But no subobject at this index. Returning");
+ Ok(None)
+ }
+ },
+ None => {
+ trace!("No more tokens, returning array at index {}", idx);
+ obj.at_index(*idx)
+ },
+ }
+ },
+ Token::Identifier { ref ident, .. } => {
+ trace!("Token is identifier, but cannot get identifier when having array, erroring...");
+ Err(Error::NoIdentifierInArray(ident.clone()))
},
- Token::Identifier { ref ident, .. } => Err(Error::NoIdentifierInArray(ident.clone())),
}
},
ObjectType::Atom => {
+ trace!("Object is an atom, cannot resolve further");
match tokens {
Token::Identifier { ref ident, .. } => Err(Error::QueryingValueAsTable(ident.clone())),
Token::Index { idx, .. } => Err(Error::QueryingValueAsArray(*idx)),