Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.

Play with explicit AST #20

Merged
merged 7 commits into from
Oct 8, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve AST diagram
  • Loading branch information
Marko Mikulicic committed Oct 7, 2020
commit 9503b4a865cd0b5350943ed654f26df856e901b7
14 changes: 7 additions & 7 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ use serde_json::Value;
/// For example, the JSONPath `$.foo.bar` yields this AST:
///
/// ```text
/// *
/// ^
/// / \
/// * \___ DotName("bar")
/// ^ \___ DotName("bar")
/// / \
/// * \___ DotName("foo")
/// ^ \___ DotName("foo")
/// /
/// Root ___/
/// ```
///
/// A more complicated example: `$.foo[1,2]["bar"]`:
///
/// ```text
/// *
/// ^
/// / \
/// * \___ Union
/// ^ \___ Union
/// / \ \
/// * \___ Union \
/// ^ \___ Union \
/// / \ [Field("bar")]
/// * \
/// ^ \
/// / \ [Number(1), Number(2)]
/// / \
/// Root ___/ \___ DotName("foo")
Copy link
Contributor

@glyn glyn Oct 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two diagrams still seem inconsistent. I'd expect the part of the tree nearest the root to be identical in both cases since $.foo is a common prefix of both selectors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because the expressions have right to left precedence

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still don't get it. $.foo.bar produces the AST:

Sel(Sel(Root, DotName("foo")), DotName("bar"))

and $.foo[1,2]["bar"] produces:

Sel(Sel(Sel(Root, DotName("foo")), Union([Number(1), Number(2)])), Union([Field("bar")]))

Root appears inside Sel(Root, DotName("foo")) in both cases. Shouldn't this subtree look the same in both diagrams?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh :brainfart:; fixed

Expand Down