{
  "name": "wasm",
  "scopeName": "source.wat",
  "patterns": [
    {
      "include": "#comments"
    },
    {
      "include": "#strings"
    },
    {
      "include": "#instructions"
    },
    {
      "include": "#types"
    },
    {
      "include": "#modules"
    },
    {
      "include": "#constants"
    },
    {
      "include": "#invalid"
    }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "comment": "Line comment",
          "name": "comment.line.wat",
          "match": "(;;).*$",
          "captures": {
            "1": {
              "name": "punctuation.definition.comment.wat"
            }
          }
        },
        {
          "comment": "Block comment",
          "name": "comment.block.wat",
          "begin": "\\(;",
          "beginCaptures": {
            "0": {
              "name": "punctuation.definition.comment.wat"
            }
          },
          "end": ";\\)",
          "endCaptures": {
            "0": {
              "name": "punctuation.definition.comment.wat"
            }
          }
        }
      ]
    },
    "strings": {
      "comment": "String literal",
      "name": "string.quoted.double.wat",
      "begin": "\"",
      "end": "\"",
      "beginCaptures": {
        "0": {
          "name": "punctuation.definition.string.begin"
        }
      },
      "endCaptures": {
        "0": {
          "name": "punctuation.definition.string.end"
        }
      },
      "patterns": [
        {
          "name": "constant.character.escape.wat",
          "match": "\\\\(n|t|\\\\|'|\"|[0-9a-fA-F]{2})"
        }
      ]
    },
    "instructions": {
      "patterns": [
        {
          "comment": "Non-trapping float-to-int conversions",
          "patterns": [
            {
              "comment": "Conversion instruction [nontrapping-float-to-int-conversions]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32|i64)\\.trunc_sat_f(?:32|64)_[su]\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "Sign-extension operators",
          "patterns": [
            {
              "comment": "Numeric instruction (i32) [sign-extension-ops]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32)\\.(?:extend(?:8|16)_s)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Numeric instruction (i64) [sign-extension-ops]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i64)\\.(?:extend(?:8|16|32)_s)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "Bulk memory operations",
          "patterns": [
            {
              "comment": "Memory instruction [bulk-memory-operations]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(memory)\\.(?:copy|fill|init|drop)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "Fixed-width SIMD",
          "patterns": [
            {
              "comment": "Vector instruction (v128) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(v128)\\.(?:const|and|or|xor|not|andnot|bitselect|load|store)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (i8x16) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i8x16)\\.(?:splat|replace_lane|add|sub|mul|neg|shl|shr_[su]|eq|ne|lt_[su]|le_[su]|gt_[su]|ge_[su]|min_[su]|max_[su]|any_true|all_true|extract_lane_[su]|add_saturate_[su]|sub_saturate_[su]|avgr_u|narrow_i16x8_[su])\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (i16x8) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i16x8)\\.(?:splat|replace_lane|add|sub|mul|neg|shl|shr_[su]|eq|ne|lt_[su]|le_[su]|gt_[su]|ge_[su]|min_[su]|max_[su]|any_true|all_true|extract_lane_[su]|add_saturate_[su]|sub_saturate_[su]|avgr_u|load8x8_[su]|narrow_i32x4_[su]|widen_(low|high)_i8x16_[su])\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (i32x4) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32x4)\\.(?:splat|replace_lane|add|sub|mul|neg|shl|shr_[su]|eq|ne|lt_[su]|le_[su]|gt_[su]|ge_[su]|min_[su]|max_[su]|any_true|all_true|extract_lane|load16x4_[su]|trunc_sat_f32x4_[su]|widen_(low|high)_i16x8_[su])\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (i64x2) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i64x2)\\.(?:splat|replace_lane|add|sub|mul|neg|shl|shr_[su]|extract_lane|load32x2_[su])\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (f32x4) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f32x4)\\.(?:splat|replace_lane|add|sub|mul|neg|extract_lane|eq|ne|lt|le|gt|ge|abs|min|max|div|sqrt|convert_i32x4_[su])\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (f64x2) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f64x2)\\.(?:splat|replace_lane|add|sub|mul|neg|extract_lane|eq|ne|lt|le|gt|ge|abs|min|max|div|sqrt)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (v8x16) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(v8x16)\\.(?:load_splat|shuffle|swizzle)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (v16x8) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(v16x8)\\.load_splat\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (v32x4) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(v32x4)\\.load_splat\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Vector instruction (v64x2) [simd]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(v64x2)\\.load_splat\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "Threads",
          "patterns": [
            {
              "comment": "Atomic instruction (i32) [threads]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32)\\.(atomic)\\.(?:load(?:8_u|16_u)?|store(?:8|16)?|wait|(rmw)\\.(?:add|sub|and|or|xor|xchg|cmpxchg)|(rmw8|rmw16)\\.(?:add_u|sub_u|and_u|or_u|xor_u|xchg_u|cmpxchg_u))\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                },
                "2": {
                  "name": "support.class.wat"
                },
                "3": {
                  "name": "support.class.wat"
                },
                "4": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Atomic instruction (i64) [threads]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i64)\\.(atomic)\\.(?:load(?:8_u|16_u|32_u)?|store(?:8|16|32)?|wait|(rmw)\\.(?:add|sub|and|or|xor|xchg|cmpxchg)|(rmw8|rmw16|rmw32)\\.(?:add_u|sub_u|and_u|or_u|xor_u|xchg_u|cmpxchg_u))\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                },
                "2": {
                  "name": "support.class.wat"
                },
                "3": {
                  "name": "support.class.wat"
                },
                "4": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Atomic instruction [threads]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(atomic)\\.(?:notify|fence)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Shared modifier [threads]",
              "name": "storage.modifier.wat",
              "match": "\\bshared\\b"
            }
          ]
        },
        {
          "comment": "Reference types",
          "patterns": [
            {
              "comment": "Reference instruction [reference-types]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(ref)\\.(?:null|is_null|func|extern)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Table instruction [reference-types]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(table)\\.(?:get|size|grow|fill|init|copy)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Type name [reference-types]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:externref|funcref|nullref)\\b"
            }
          ]
        },
        {
          "comment": "Tail Call",
          "patterns": [
            {
              "comment": "Control instruction [tail-call]",
              "name": "keyword.control.wat",
              "match": "\\breturn_call(?:_indirect)?\\b"
            }
          ]
        },
        {
          "comment": "Exception handling",
          "patterns": [
            {
              "comment": "Control instruction [exception-handling]",
              "name": "keyword.control.wat",
              "match": "\\b(?:try|catch|throw|rethrow|br_on_exn)\\b"
            },
            {
              "comment": "Module element [exception-handling]",
              "name": "storage.type.wat",
              "match": "(?<=\\()event\\b"
            }
          ]
        },
        {
          "comment": "Binaryen extensions",
          "patterns": [
            {
              "comment": "Pseudo stack instruction [binaryen]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32|i64|f32|f64|externref|funcref|nullref|exnref)\\.(?:push|pop)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "MVP",
          "patterns": [
            {
              "comment": "Memory instruction (i32) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32)\\.(?:load|load(?:8|16)(?:_[su])?|store(?:8|16)?)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Memory instruction (i64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i64)\\.(?:load|load(?:8|16|32)(?:_[su])?|store(?:8|16|32)?)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Memory instruction (f32/f64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f32|f64)\\.(?:load|store)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Memory instruction [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(memory)\\.(?:size|grow)\\b",
              "captures": {
                "1": {
                  "name": "support.class.memory.wat"
                }
              }
            },
            {
              "comment": "Memory instruction attribute [mvp]",
              "match": "\\b(offset|align)=\\b",
              "captures": {
                "1": {
                  "name": "entity.other.attribute-name.wat"
                }
              }
            },
            {
              "comment": "Variable instruction (local) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(local)\\.(?:get|set|tee)\\b",
              "captures": {
                "1": {
                  "name": "support.class.local.wat"
                }
              }
            },
            {
              "comment": "Variable instruction (global) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(global)\\.(?:get|set)\\b",
              "captures": {
                "1": {
                  "name": "support.class.global.wat"
                }
              }
            },
            {
              "comment": "Numeric instruction (i32/i64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32|i64)\\.(const|eqz|eq|ne|lt_[su]|gt_[su]|le_[su]|ge_[su]|clz|ctz|popcnt|add|sub|mul|div_[su]|rem_[su]|and|or|xor|shl|shr_[su]|rotl|rotr)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Numeric instruction (f32/f64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f32|f64)\\.(const|eq|ne|lt|gt|le|ge|abs|neg|ceil|floor|trunc|nearest|sqrt|add|sub|mul|div|min|max|copysign)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Conversion instruction (i32) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i32)\\.(wrap_i64|trunc_(f32|f64)_[su]|reinterpret_f32)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Conversion instruction (i64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i64)\\.(extend_i32_[su]|trunc_f(32|64)_[su]|reinterpret_f64)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Conversion instruction (f32) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f32)\\.(convert_i(32|64)_[su]|demote_f64|reinterpret_i32)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Conversion instruction (f64) [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(f64)\\.(convert_i(32|64)_[su]|promote_f32|reinterpret_i64)\\b",
              "captures": {
                "1": {
                  "name": "support.class.type.wat"
                }
              }
            },
            {
              "comment": "Control instruction [mvp]",
              "name": "keyword.control.wat",
              "match": "\\b(?:unreachable|nop|block|loop|if|then|else|end|br|br_if|br_table|return|call|call_indirect)\\b"
            },
            {
              "comment": "Parametric instruction [mvp]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(?:drop|select)\\b"
            }
          ]
        },
        {
          "comment": "GC Instructions",
          "patterns": [
            {
              "comment": "Reference Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(ref)\\.(?:eq|test|cast)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Struct Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(struct)\\.(?:new_canon|new_canon_default|get|get_s|get_u|set)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Array Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(array)\\.(?:new_canon|new_canon_default|get|get_s|get_u|set|len|new_canon_fixed|new_canon_data|new_canon_elem)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "i31 Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(i31)\\.(?:new|get_s|get_u)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Branch Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(?:br_on_non_null|br_on_cast|br_on_cast_fail)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            },
            {
              "comment": "Reference Instructions [GC]",
              "name": "keyword.operator.word.wat",
              "match": "\\b(extern)\\.(?:internalize|externalize)\\b",
              "captures": {
                "1": {
                  "name": "support.class.wat"
                }
              }
            }
          ]
        }
      ]
    },
    "types": {
      "patterns": [
        {
          "comment": "Fixed-width SIMD",
          "patterns": [
            {
              "comment": "Type name [simd]",
              "name": "entity.name.type.wat",
              "match": "\\bv128\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "Reference types",
          "patterns": [
            {
              "comment": "Type name [reference-types]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:externref|funcref|nullref)\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "Exception handling",
          "patterns": [
            {
              "comment": "Type name [exception-handling]",
              "name": "entity.name.type.wat",
              "match": "\\bexnref\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "MVP",
          "patterns": [
            {
              "comment": "Type name [mvp]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:i32|i64|f32|f64)\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "GC Types",
          "patterns": [
            {
              "comment": "Type name [GC]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:i8|i16|ref|funcref|externref|anyref|eqref|i31ref|nullfuncref|nullexternref|structref|arrayref|nullref)\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "GC Heap Types",
          "patterns": [
            {
              "comment": "Type name [GC]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:type|func|extern|any|eq|nofunc|noextern|struct|array|none)\\b(?!\\.)"
            }
          ]
        },
        {
          "comment": "GC Structured and sub Types",
          "patterns": [
            {
              "comment": "Type name [GC]",
              "name": "entity.name.type.wat",
              "match": "\\b(?:struct|array|sub|final|rec|field|mut)\\b(?!\\.)"
            }
          ]
        }
      ]
    },
    "modules": {
      "patterns": [
        {
          "comment": "Bulk memory operations",
          "patterns": [
            {
              "comment": "Passive modifier [bulk-memory-operations]",
              "match": "(?<=\\(data)\\s+(passive)\\b",
              "captures": {
                "1": {
                  "name": "storage.modifier.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "MVP",
          "patterns": [
            {
              "comment": "Module element [mvp]",
              "name": "storage.type.wat",
              "match": "(?<=\\()(?:module|import|export|memory|data|table|elem|start|func|type|param|result|global|local)\\b"
            },
            {
              "comment": "Mutable global modifier [mvp]",
              "name": "storage.modifier.wat",
              "match": "(?<=\\()\\s*(mut)\\b",
              "captures": {
                "1": {
                  "name": "storage.modifier.wat"
                }
              }
            },
            {
              "comment": "Function name [mvp]",
              "match": "(?<=\\(func|\\(start|call|return_call|ref\\.func)\\s+(\\$[0-9A-Za-z!#$%&'*+\\-./:<=>?@\\\\^_`|~]*)",
              "captures": {
                "1": {
                  "name": "entity.name.function.wat"
                }
              }
            },
            {
              "comment": "Function name(s) (elem) [mvp]",
              "begin": "\\)\\s+(\\$[0-9A-Za-z!#$%&'*+\\-./:<=>?@\\\\^_`|~]*)",
              "beginCaptures": {
                "1": {
                  "name": "entity.name.function.wat"
                }
              },
              "end": "\\)",
              "patterns": [
                {
                  "name": "entity.name.function.wat",
                  "match": "(?<=\\s)\\$[0-9A-Za-z!#$%&'*+\\-./:<=>?@\\\\^_`|~]*"
                }
              ]
            },
            {
              "comment": "Function type [mvp]",
              "match": "(?<=\\(type)\\s+(\\$[0-9A-Za-z!#$%&'*+\\-./:<=>?@\\\\^_`|~]*)",
              "captures": {
                "1": {
                  "name": "support.type.function.wat"
                }
              }
            },
            {
              "comment": "Variable name or branch label [mvp]",
              "name": "variable.other.wat",
              "match": "\\$[0-9A-Za-z!#$%&'*+\\-./:<=>?@\\\\^_`|~]*\\b"
            }
          ]
        }
      ]
    },
    "constants": {
      "patterns": [
        {
          "comment": "Fixed-width SIMD",
          "patterns": [
            {
              "comment": "Vector literal (i8x16) [simd]",
              "name": "constant.numeric.vector.wat",
              "match": "\\b(i8x16)(?:\\s+0x[0-9a-fA-F]{1,2}){16}\\b",
              "captures": {
                "1": {
                  "name": "support.type.wat"
                }
              }
            },
            {
              "comment": "Vector literal (i16x8) [simd]",
              "name": "constant.numeric.vector.wat",
              "match": "\\b(i16x8)(?:\\s+0x[0-9a-fA-F]{1,4}){8}\\b",
              "captures": {
                "1": {
                  "name": "support.type.wat"
                }
              }
            },
            {
              "comment": "Vector literal (i32x4) [simd]",
              "name": "constant.numeric.vector.wat",
              "match": "\\b(i32x4)(?:\\s+0x[0-9a-fA-F]{1,8}){4}\\b",
              "captures": {
                "1": {
                  "name": "support.type.wat"
                }
              }
            },
            {
              "comment": "Vector literal (i64x2) [simd]",
              "name": "constant.numeric.vector.wat",
              "match": "\\b(i64x2)(?:\\s+0x[0-9a-fA-F]{1,16}){2}\\b",
              "captures": {
                "1": {
                  "name": "support.type.wat"
                }
              }
            }
          ]
        },
        {
          "comment": "MVP",
          "patterns": [
            {
              "comment": "Floating point literal",
              "name": "constant.numeric.float.wat",
              "match": "[+-]?\\b[0-9][0-9]*(?:\\.[0-9][0-9]*)?(?:[eE][+-]?[0-9]+)?\\b"
            },
            {
              "comment": "Floating point hexadecimal literal",
              "name": "constant.numeric.float.wat",
              "match": "[+-]?\\b0x([0-9a-fA-F]*\\.[0-9a-fA-F]+|[0-9a-fA-F]+\\.?)[Pp][+-]?[0-9]+\\b"
            },
            {
              "comment": "Floating point infinity",
              "name": "constant.numeric.float.wat",
              "match": "[+-]?\\binf\\b"
            },
            {
              "comment": "Floating point literal (NaN)",
              "name": "constant.numeric.float.wat",
              "match": "[+-]?\\bnan:0x[0-9a-fA-F][0-9a-fA-F]*\\b"
            },
            {
              "comment": "Integer literal",
              "name": "constant.numeric.integer.wat",
              "match": "[+-]?\\b(?:0x[0-9a-fA-F][0-9a-fA-F]*|\\d[\\d]*)\\b"
            }
          ]
        }
      ]
    },
    "invalid": {
      "patterns": [
        {
          "name": "invalid.wat",
          "match": "[^\\s()]+"
        }
      ]
    }
  }
}
