joshtemple / lkml

A speedy LookML parser & serializer implemented in pure Python.
MIT License
166 stars 31 forks source link

Move non-breaking leading whitespace to block prefix #83

Closed joshtemple closed 1 year ago

joshtemple commented 1 year ago

Support interval_trigger

Closes #78.

Reassign block prefix whitespace

Previously, parsing text like this...

view: view {
  dimension: d1 {
    ...
  }

  dimension: d2 {
    ...
  }
}

...would assign all whitespace between the two dimensions to the suffix of the first dimension.

It's slightly more accurate to assign the newlines to the suffix of the first dimension and the non-breaking whitespace characters (spaces) to the prefix of the second dimension.

This is useful for a case where we want to dump the second dimension in isolation to a string. In the current version of the code, we lose the leading whitespace, so we get this:

dimension: d2 {
    ...
  }

Note that the word dimension and the closing } are not aligned.

After this change, we get:

  dimension: d2 {
    ...
  }

Which is much more consistent and easier to strip the leading indent off of.