# Aligning input form of a sequence of Queries

Is there a way to modify the parser, or define options, to align the indentation of a sequence of Queries on a Dataset?

Given:

ds = <|"a" -> 1, "b" -> <|"c" -> 2|>, "d" -> <|"e" -> 3, "f" -> <|"g" -> 4|>|>|> // Dataset;

A sequence of queries is indented like this:

ds[
{"b" -> {"c" -> foo}}][
{"d" -> {"e" -> bar}}][
{"d" -> {"f" -> {"g" -> baz}}}][
{"d" -> {{"f" -> quz}}}]


There are 2 problems with this format in practice with realistic workflows where queries are often lengthy and need to be modified repeatedly:

1. The lines are staggered - it would be desirable to have them left-aligned, as applications with many lines continues to accumulate that slope, making spot-checking of depth more difficult than it should be.

2. The open bracket "[" of each query appears on the line above it, making it more difficult than necessary to highlight a query (eg, to delete it). It would be more modular to confine each on its own line, but doing so results in a syntax error:

 Syntax::sntxb: Expression cannot begin with "[{d->{e->bar}}][{d->{f->{g->baz}}}]".


Interestingly, writing out Query solves the 2nd problem but not the first:

ds //
Query[{"b" -> {"c" -> foo}}] /*
Query[ {"d" -> {"e" -> bar}}] /*
Query[ {"d" -> {"f" -> {"g" -> baz}}}] /*
Query[ {"d" -> {{"f" -> quz}}}]


Note, chaining queries using RightComposition reverses the indentation compared to \, which also works.

• You can use Code cell style. – Kuba Nov 23 '16 at 18:49
• @Kuba, great, can you give an example? Any downstream effects? – alancalvitti Nov 23 '16 at 18:50
• They are gray :) and also have InitializationCell->True option but this can be switched on notebook or stylesheet level if you need it. As to examples, select bracket and Alt+8 – Kuba Nov 23 '16 at 18:53
• @Kuba, converting to Code style seems to work for issue 1 but not for 2, where it still throws a syntax error. – alancalvitti Nov 23 '16 at 19:16
• Right, the same as with /., don't have a quick solution for you, sorry. – Kuba Nov 23 '16 at 19:18