All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dingyi222666.monarch.languages.LanguageHcl.kt Maven / Gradle / Ivy

package io.github.dingyi222666.monarch.languages

import io.github.dingyi222666.monarch.common.*
 import io.github.dingyi222666.monarch.loader.dsl.*
import io.github.dingyi222666.monarch.types.IMonarchLanguage

public val HclLanguage: IMonarchLanguage by lazy {
  buildMonarchLanguage {
    tokenPostfix = ".hcl"
    defaultToken = ""
    keywords("var", "local", "path", "for_each", "any", "string", "number", "bool", "true", "false",
        "null", "if ", "else ", "endif ", "for ", "in", "endfor")
    operators("=", ">=", "<=", "==", "!=", "+", "-", "*", "/", "%", "&&", "||", "!", "<", ">", "?",
        "...", ":")
    symbols("[=>](?!@symbols)".token("@brackets")
        "@symbols".action {
          cases {
            "@operators" and "operator"
            "@default" and ""
          }
        }
        "\\d*\\d+[eE]([\\-+]?\\d+)?".token("number.float")
        "\\d*\\.\\d+([eE][\\-+]?\\d+)?".token("number.float")
        "\\d[\\d']*".token("number")
        "\\d".token("number")
        "[;,.]".token("delimiter")
        "\"".action("string").state("@string")
        "'".token("invalid")
      }
      "heredoc" rules {
        "<<[-]*\\s*[\"]?([\\w\\-]+)[\"]?".action {
          token = "string.heredoc.delimiter"
          next = "@heredocBody.${'$'}1"
        }
      }
      "heredocBody" rules {
        "([\\w\\-]+)${'$'}".action {
          cases {
            "${'$'}1==${'$'}S2" actionArray {
              action("string.heredoc.delimiter") {
                next = "@popall"
              }
            }
            "@default" and "string.heredoc"
          }
        }
        ".".token("string.heredoc")
      }
      whitespace {
        "[ \\t\\r\\n]+".token("")
        "\\/\\*".action("comment").state("@comment")
        "\\/\\/.*${'$'}".token("comment")
        "#.*${'$'}".token("comment")
      }
      comment {
        "[^\\/*]+".token("comment")
        "\\*\\/".action("comment").state("@pop")
        "[\\/*]".token("comment")
      }
      string {
        "\\${'$'}\\{".action {
          token = "delimiter"
          next = "@stringExpression"
        }
        "[^\\\\\"\\${'$'}]+".token("string")
        "@escapes".token("string.escape")
        "\\\\.".token("string.escape.invalid")
        "\"".action("string").state("@popall")
      }
      "stringInsideExpression" rules {
        "[^\\\\\"]+".token("string")
        "@escapes".token("string.escape")
        "\\\\.".token("string.escape.invalid")
        "\"".action("string").state("@pop")
      }
      "stringExpression" rules {
        "\\}".action {
          token = "delimiter"
          next = "@pop"
        }
        "\"".action("string").state("@stringInsideExpression")
        include("@terraform")
      }
    }
  }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy