Tree Query Parser

Class Library
C#
GitHub Repository

What It Is

A parser to structure queries of a hierarchical data structure

Status

Last Reviewed:

I use it all over this site right now.

Details

In invented my own form of SQL to query a tree structure. This code allows you to write something like this:

SELECT children
  OF /some/path/ 
  WHERE
    foo = "bar" AND
    bar = "baz"
  ORDER BY
   baz DESC,
   bar

The code will parse this text into a C# object called a TreeQuery which has strongly-typed properties for all the information. You can then use this to query your data structure.

The biggest difference from SQL is that it takes a “scope” (children above) and a “target” (/some/path/ above). Also – and obviously – there’s a ton of SQL stuff that’s not there: joins and such. The goal is to select a point on a tree, and explain what content you from that point.

(To be clear, this is just a parser. You have the implement the actual query logic yourself. This is just a bridge between plain text and a C# object you can examine and manipulate.)

It’s built on Parlot, which is the parsing engine behind Fluid.

Lots of documentation at the repo URL.