{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "nextflow",
  "scopeName": "source.nextflow",
  "keyEquivalent": "^~N",
  "patterns": [
    {
      "include": "#nfl-rules"
    }
  ],
  "repository": {
    "nfl-rules": {
      "patterns": [
        {
          "include": "#process-def"
        },
        {
          "include": "#workflow-def"
        },
        {
          "include": "#code-block"
        },
        {
          "include": "#include-statement"
        },
        {
          "include": "#implicit-variables"
        },
        {
          "comment": "method call and parens",
          "begin": "(\\w*\\()",
          "beginCaptures": {
            "1": {
              "patterns": [
                {
                  "include": "source.nextflow-groovy"
                }
              ]
            }
          },
          "end": "\\)",
          "patterns": [
            {
              "include": "#nfl-rules"
            }
          ]
        },
        {
          "comment": "braces",
          "begin": "{",
          "end": "}",
          "patterns": [
            {
              "include": "#nfl-rules"
            }
          ]
        },
        {
          "include": "source.nextflow-groovy"
        }
      ]
    },
    "process-def": {
      "name": "process.nextflow",
      "begin": "^\\s*(process)\\s+(\\w+|\"[^\"]+\"|'[^']+')\\s*{",
      "beginCaptures": {
        "1": {
          "name": "keyword.nextflow"
        },
        "2": {
          "name": "function.nextflow"
        }
      },
      "end": "}",
      "patterns": [
        {
          "include": "#process-body"
        }
      ]
    },
    "process-body": {
      "patterns": [
        {
          "name": "entity.name.function.nextflow",
          "match": "(?:accelerator|afterScript|beforeScript|cache|cpus|conda|container|containerOptions|clusterOptions|debug|disk|echo|errorStrategy|executor|ext|label|machineType|maxErrors|maxForks|maxRetries|memory|module|penv|pod|publishDir|queue|resourceLabels|scratch|stageInMode|stageOutMode|storeDir|tag|time)\\b"
        },
        {
          "name": "constant.block.nextflow",
          "match": "(?:input|output|when|script|shell|exec):"
        },
        {
          "name": "entity.name.function.nextflow",
          "match": "\\b(tuple|set|path|file|val|stdout)(\\(|\\s)"
        },
        {
          "include": "#implicit-variables"
        },
        {
          "comment": "method call and parens",
          "begin": "(\\w*\\()",
          "beginCaptures": {
            "1": {
              "patterns": [
                {
                  "include": "source.nextflow-groovy"
                }
              ]
            }
          },
          "end": "\\)",
          "patterns": [
            {
              "include": "#process-body"
            }
          ]
        },
        {
          "comment": "braces",
          "begin": "{",
          "end": "}",
          "patterns": [
            {
              "include": "#process-body"
            }
          ]
        },
        {
          "include": "source.nextflow-groovy#comments"
        },
        {
          "include": "source.nextflow-groovy#support-functions"
        },
        {
          "include": "source.nextflow-groovy#keyword"
        },
        {
          "include": "source.nextflow-groovy#values"
        },
        {
          "include": "source.nextflow-groovy#anonymous-classes-and-new"
        },
        {
          "include": "source.nextflow-groovy#types"
        },
        {
          "include": "source.nextflow-groovy#parens"
        },
        {
          "include": "source.nextflow-groovy#closures"
        },
        {
          "include": "source.nextflow-groovy#braces"
        }
      ]
    },
    "workflow-def": {
      "name": "workflow.nextflow",
      "begin": "^\\s*(workflow)(?:\\s+(\\w+|\"[^\"]+\"|'[^']+'))?\\s*{",
      "beginCaptures": {
        "1": {
          "name": "keyword.nextflow"
        },
        "2": {
          "name": "constant.nextflow"
        }
      },
      "end": "}",
      "patterns": [
        {
          "include": "#workflow-body"
        }
      ]
    },
    "workflow-body": {
      "patterns": [
        {
          "include": "#implicit-variables"
        },
        {
          "name": "constant.block.nextflow",
          "match": "(?:take|main|emit):"
        },
        {
          "name": "entity.name.function.nextflow",
          "match": "(?<=[\\s\\.])(branch|buffer|close|collate|collect|collectFile|combine|concat|count|countBy|cross|distinct|dump|filter|first|flatMap|flatten|groupTuple|ifEmpty|join|last|map|max|merge|min|mix|multiMap|randomSample|reduce|set|splitCsv|splitFasta|splitFastq|splitText|sum|take|tap|toInteger|toList|toSortedList|transpose|unique|until|view)(?=[{\\(\\s])"
        },
        {
          "comment": "Channel factory single line",
          "match": "\\b((?:C|c)hannel\\.)((fromList|fromPath|fromFilePairs|fromSRA|from|of|empty|value|watchPath)\\W)?",
          "captures": {
            "1": {
              "name": "keyword.nextflow"
            },
            "2": {
              "name": "entity.name.function.nextflow"
            }
          }
        },
        {
          "comment": "Channel factory multi-line",
          "begin": "\\b((?:C|c)hannel)\\s*$",
          "beginCaptures": {
            "1": {
              "name": "keyword.nextflow"
            }
          },
          "end": "(^\\s*)(?:(\\.)(fromList|fromPath|fromFilePairs|fromSRA|from|of|empty|value|watchPath)\\W)?",
          "endCaptures": {
            "1": {
              "name": "keyword.nextflow"
            },
            "2": {
              "name": "keyword.nextflow"
            },
            "3": {
              "name": "entity.name.function.nextflow"
            }
          }
        },
        {
          "comment": "method call and parens",
          "begin": "(\\w*\\()",
          "beginCaptures": {
            "1": {
              "patterns": [
                {
                  "include": "source.nextflow-groovy"
                }
              ]
            }
          },
          "end": "\\)",
          "patterns": [
            {
              "include": "#workflow-body"
            }
          ]
        },
        {
          "comment": "braces",
          "begin": "{",
          "end": "}",
          "patterns": [
            {
              "include": "#workflow-body"
            }
          ]
        },
        {
          "include": "source.nextflow-groovy#comments"
        },
        {
          "include": "source.nextflow-groovy#support-functions"
        },
        {
          "include": "source.nextflow-groovy#keyword"
        },
        {
          "include": "source.nextflow-groovy#values"
        },
        {
          "include": "source.nextflow-groovy#anonymous-classes-and-new"
        },
        {
          "include": "source.nextflow-groovy#types"
        },
        {
          "include": "source.nextflow-groovy#parens"
        },
        {
          "include": "source.nextflow-groovy#closures"
        },
        {
          "include": "source.nextflow-groovy#braces"
        }
      ]
    },
    "include-statement": {
      "patterns": [
        {
          "match": "^\\b(include)\\b",
          "name": "keyword.nextflow"
        },
        {
          "match": "\\b(from)\\b",
          "name": "keyword.nextflow"
        }
      ]
    },
    "implicit-variables": {
      "patterns": [
        {
          "match": "(?<=[^\\.\\w]|^)(params|nextflow|workflow|launchDir|moduleDir|projectDir|workDir)\\b",
          "name": "variable.language.nextflow"
        }
      ]
    }
  }
}
