github.com/grafana/tanka@v0.26.1-0.20240506093700-c22cfc35c21a/docs/.vscext/heptio.jsonnet/extension/syntaxes/jsonnet.tmLanguage.jsonnet (about)

     1  local identifier = "[a-zA-Z_][a-z0-9A-Z_]*";
     2  
     3  local Include(id) = { include: "#%s" % id };
     4  
     5  local string = {
     6    local escapeCharsPattern = "\\\\([%s\\\\/bfnrt]|(u[0-9a-fA-F]{4}))",
     7    local illegalCharsPattern = "\\\\[^%s\\\\/bfnrtu]",
     8  
     9    escape:: {
    10      single: escapeCharsPattern % "'",
    11      double: escapeCharsPattern % "\"",
    12    },
    13  
    14    illegal:: {
    15      single: illegalCharsPattern % "'",
    16      double: illegalCharsPattern % "\"",
    17    },
    18  };
    19  
    20  local match = {
    21    Simple(name, match):: {
    22      name: name,
    23      match: match,
    24    },
    25  
    26    Span(name, begin, end):: {
    27      name: name,
    28      begin: begin,
    29      end: end,
    30    },
    31  };
    32  
    33  {
    34    "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    35    name: "Jsonnet",
    36    patterns: [
    37      Include("expression"),
    38      Include("keywords"),
    39    ],
    40    repository: {
    41      expression: {
    42        patterns: [
    43          Include("literals"),
    44          Include("comment"),
    45          Include("single-quoted-strings"),
    46          Include("double-quoted-strings"),
    47          Include("triple-quoted-strings"),
    48          Include("builtin-functions"),
    49          Include("functions"),
    50        ]
    51      },
    52      keywords: {
    53        patterns: [
    54          match.Simple("keyword.operator.jsonnet", "[!:~\\+\\-&\\|\\^=<>\\*\\/%]"),
    55          match.Simple("keyword.other.jsonnet", "\\$"),
    56          match.Simple("keyword.other.jsonnet", "\\b(self|super|import|importstr|local|tailstrict)\\b"),
    57          match.Simple("keyword.control.jsonnet", "\\b(if|then|else|for|in|error|assert)\\b"),
    58          match.Simple("storage.type.jsonnet", "\\b(function)\\b"),
    59          match.Simple("variable.parameter.jsonnet", "%s\\s*(:::|\\+:::)" % identifier),
    60          match.Simple("entity.name.type", "%s\\s*(::|\\+::)" % identifier,),
    61          match.Simple("variable.parameter.jsonnet", "%s\\s*(:|\\+:)" % identifier),
    62  
    63        ]
    64      },
    65      literals: {
    66        patterns: [
    67           match.Simple("constant.language.jsonnet", "\\b(true|false|null)\\b"),
    68           match.Simple("constant.numeric.jsonnet", "\\b(\\d+([Ee][+-]?\\d+)?)\\b"),
    69           match.Simple("constant.numeric.jsonnet", "\\b\\d+[.]\\d*([Ee][+-]?\\d+)?\\b"),
    70           match.Simple("constant.numeric.jsonnet", "\\b[.]\\d+([Ee][+-]?\\d+)?\\b"),
    71        ]
    72      },
    73      "builtin-functions": {
    74        patterns: [
    75          match.Simple("support.function.jsonnet", "\\bstd[.](acos|asin|atan|ceil|char|codepoint|cos|exp|exponent)\\b"),
    76          match.Simple("support.function.jsonnet", "\\bstd[.](filter|floor|force|length|log|makeArray|mantissa)\\b"),
    77          match.Simple("support.function.jsonnet", "\\bstd[.](objectFields|objectHas|pow|sin|sqrt|tan|type|thisFile)\\b"),
    78          match.Simple("support.function.jsonnet", "\\bstd[.](acos|asin|atan|ceil|char|codepoint|cos|exp|exponent)\\b"),
    79          match.Simple("support.function.jsonnet", "\\bstd[.](abs|assertEqual|escapeString(Bash|Dollars|Json|Python))\\b"),
    80          match.Simple("support.function.jsonnet", "\\bstd[.](filterMap|flattenArrays|foldl|foldr|format|join)\\b"),
    81          match.Simple("support.function.jsonnet", "\\bstd[.](lines|manifest(Ini|Python(Vars)?)|map|max|min|mod)\\b"),
    82          match.Simple("support.function.jsonnet", "\\bstd[.](set|set(Diff|Inter|Member|Union)|sort)\\b"),
    83          match.Simple("support.function.jsonnet", "\\bstd[.](range|split|stringChars|substr|toString|uniq)\\b"),
    84        ]
    85      },
    86      "single-quoted-strings":
    87        match.Span("string.quoted.double.jsonnet", "'", "'") {
    88          patterns: [
    89            match.Simple("constant.character.escape.jsonnet", string.escape.single),
    90            match.Simple("invalid.illegal.jsonnet", string.illegal.single),
    91          ]
    92        },
    93      "double-quoted-strings":
    94        match.Span("string.quoted.double.jsonnet", "\"", "\"") {
    95          patterns: [
    96            match.Simple("constant.character.escape.jsonnet", string.escape.double),
    97            match.Simple("invalid.illegal.jsonnet", string.illegal.double),
    98          ]
    99        },
   100      "triple-quoted-strings": {
   101        patterns: [
   102          match.Span("string.quoted.triple.jsonnet", "\\|\\|\\|", "\\|\\|\\|"),
   103        ]
   104      },
   105      functions: {
   106        patterns: [
   107          match.Span("meta.function", "\\b([a-zA-Z_][a-z0-9A-Z_]*)\\s*\\(", "\\)") {
   108            beginCaptures: {
   109              "1": { name: "entity.name.function.jsonnet" }
   110            },
   111            patterns: [
   112              Include("expression"),
   113            ],
   114          },
   115        ]
   116      },
   117      comment: {
   118        patterns: [
   119          match.Span("comment.block.jsonnet", "/\\*", "\\*/"),
   120          match.Simple("comment.line.jsonnet", "//.*$"),
   121          match.Simple("comment.block.jsonnet", "#.*$"),
   122        ]
   123      }
   124    },
   125    scopeName: "source.jsonnet"
   126  }