Skip to content

0.41.0

Compare
Choose a tag to compare
@zmstone zmstone released this 15 Feb 09:39
· 58 commits to master since this release
cbfb5f0

Added support for multiline string indentation.

Feature can be summarised as in README.md

  • Quotes next to triple-quotes needs to be escaped, otherwise they are discarded.
    Meaning """a"""" is parsed as a but not a", to crrectly express a", it must be one of below:
    • Escape the last ": """a\"""";
    • Or add ~ around the string value: """~a"~""" (see below).
  • Multiline strings allow indentation (spaces, not tabs).
    If ~\n (or ~\r\n) are the only characters following the opening triple-quote, then it's a multiline string with indentation:
    • The first line ~\n is discarded;
    • The closing triple-quote can be either """ or ~""" (~ allows the string to end with " without escaping).
    • Indentation is allowed but not required for empty lines;
    • Indentation level is determined by the least number of leading spaces among the non-empty lines;
    • If the closing triple-quote takes the whole line, it's allowed to be indented less than other lines,
      but if it's indented more than other lines, the spaces are treated as part of the string.
    • Backslashes are treated as escape characters, i.e. should be escaped with another backslash; (NOTE: changed in 0.42.0)
    • There is no need to escape quotes in multiline strings, but it's allowed. (NOTE: changed in 0.42.0)

Some examples:

rule_engine {
  ignore_sys_message = true
  jq_function_default_timeout = 10s
  rules {
    a_WH_D {
      actions = ["http:a_WH_D"]
      description = ""
      enable = true
      metadata {created_at = 1707562385536}
      name = ""
      sql = """~
        SELECT
          *
        FROM
          "#",
          "$events/message_delivered",
          "$events/message_acked",
          "$events/message_dropped",
          "$events/client_connected",
          "$events/client_disconnected",
          "$events/client_connack",
          "$events/client_check_authz_complete",
          "$events/session_subscribed",
          "$events/session_unsubscribed",
          "$events/delivery_dropped"~"""
    }
    rule_rc0w {
      actions = [
        {
          args {
            mqtt_properties {}
            payload = "${.}"
            qos = 0
            retain = false
            topic = "republish-event/${clientid}"
            user_properties = ""
          }
          function = republish
        },
        {function = console}
      ]
      enable = true
      metadata {created_at = 1707389712653}
      name = ""
      sql = """~
        SELECT
          *
        FROM
          "$events/client_connected",
          "$events/client_disconnected"
      ~"""
    }
    rule_xlu4 {
      actions = [
        {function = console}
      ]
      description = ""
      enable = true
      metadata {created_at = 1706611936022}
      name = ""
      sql = """~
        SELECT
          *
        FROM
          "t/#"
      ~"""
    }
  }
}