tree-sitter-preproc-code-split 0.20.3

Preproc grammar for the tree-sitter parsing library
Documentation
{
  "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
  "name": "preproc",
  "rules": {
    "translation_unit": {
      "type": "REPEAT",
      "content": {
        "type": "SYMBOL",
        "name": "_top_level_item"
      }
    },
    "_top_level_item": {
      "type": "CHOICE",
      "members": [
        {
          "type": "SYMBOL",
          "name": "string_literal"
        },
        {
          "type": "SYMBOL",
          "name": "char_literal"
        },
        {
          "type": "SYMBOL",
          "name": "raw_string_literal"
        },
        {
          "type": "SYMBOL",
          "name": "comment"
        },
        {
          "type": "SYMBOL",
          "name": "nothing"
        },
        {
          "type": "SYMBOL",
          "name": "define"
        },
        {
          "type": "SYMBOL",
          "name": "undef"
        },
        {
          "type": "SYMBOL",
          "name": "preproc_if"
        },
        {
          "type": "SYMBOL",
          "name": "preproc_include"
        },
        {
          "type": "SYMBOL",
          "name": "preproc_nothing"
        },
        {
          "type": "SYMBOL",
          "name": "integer_literal"
        }
      ]
    },
    "identifier": {
      "type": "PATTERN",
      "value": "[a-zA-Z_]\\w*"
    },
    "nothing": {
      "type": "TOKEN",
      "content": {
        "type": "CHOICE",
        "members": [
          {
            "type": "PATTERN",
            "value": "[^R\"'\\/#0-9]+"
          },
          {
            "type": "STRING",
            "value": "R"
          },
          {
            "type": "STRING",
            "value": "#"
          },
          {
            "type": "STRING",
            "value": "/"
          },
          {
            "type": "STRING",
            "value": "\n"
          }
        ]
      }
    },
    "preproc_continuation_line": {
      "type": "IMMEDIATE_TOKEN",
      "content": {
        "type": "PATTERN",
        "value": ".*\\\\\\r?\\n"
      }
    },
    "preproc_line": {
      "type": "IMMEDIATE_TOKEN",
      "content": {
        "type": "PATTERN",
        "value": ".*"
      }
    },
    "preproc_include": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*include(_next)?[ \\t]*"
        },
        {
          "type": "CHOICE",
          "members": [
            {
              "type": "SYMBOL",
              "name": "string_literal"
            },
            {
              "type": "SEQ",
              "members": [
                {
                  "type": "STRING",
                  "value": "<"
                },
                {
                  "type": "SYMBOL",
                  "name": "path"
                },
                {
                  "type": "STRING",
                  "value": ">"
                }
              ]
            },
            {
              "type": "SYMBOL",
              "name": "identifier"
            }
          ]
        }
      ]
    },
    "path": {
      "type": "TOKEN",
      "content": {
        "type": "PATTERN",
        "value": "[^>]*"
      }
    },
    "define": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*define[ \\t]+"
        },
        {
          "type": "SYMBOL",
          "name": "identifier"
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "preproc_continuation_line"
          }
        },
        {
          "type": "SYMBOL",
          "name": "preproc_line"
        },
        {
          "type": "STRING",
          "value": "\n"
        }
      ]
    },
    "preproc_if": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*(ifdef|ifndef|if).*\\n"
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "_top_level_item"
          }
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "preproc_elif"
          }
        },
        {
          "type": "CHOICE",
          "members": [
            {
              "type": "SYMBOL",
              "name": "preproc_else"
            },
            {
              "type": "BLANK"
            }
          ]
        },
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*endif.*\\n"
        }
      ]
    },
    "preproc_elif": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*elif.*\\n"
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "_top_level_item"
          }
        }
      ]
    },
    "preproc_else": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*else.*\\n"
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "_top_level_item"
          }
        }
      ]
    },
    "undef": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "[ \\t]*#[ \\t]*undef[ \\t]+"
        },
        {
          "type": "SYMBOL",
          "name": "identifier"
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "preproc_continuation_line"
          }
        },
        {
          "type": "SYMBOL",
          "name": "preproc_line"
        },
        {
          "type": "STRING",
          "value": "\n"
        }
      ]
    },
    "preproc_nothing": {
      "type": "SEQ",
      "members": [
        {
          "type": "IMMEDIATE_TOKEN",
          "content": {
            "type": "PATTERN",
            "value": "[ \\t]*#[ \\t]*(error|pragma|line)"
          }
        },
        {
          "type": "REPEAT",
          "content": {
            "type": "SYMBOL",
            "name": "preproc_continuation_line"
          }
        },
        {
          "type": "SYMBOL",
          "name": "preproc_line"
        }
      ]
    },
    "string_literal": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "\"([^\\\\\"]|\\\\(.|\\n))*\""
        }
      ]
    },
    "char_literal": {
      "type": "SEQ",
      "members": [
        {
          "type": "PATTERN",
          "value": "'([^\\\\']|\\\\(.|\\n))*'"
        }
      ]
    },
    "integer_literal": {
      "type": "IMMEDIATE_TOKEN",
      "content": {
        "type": "PATTERN",
        "value": "[0-9]+[0-9']*"
      }
    },
    "comment": {
      "type": "TOKEN",
      "content": {
        "type": "CHOICE",
        "members": [
          {
            "type": "SEQ",
            "members": [
              {
                "type": "STRING",
                "value": "//"
              },
              {
                "type": "PATTERN",
                "value": "(\\\\(.|\\r?\\n)|[^\\\\\\n])*"
              }
            ]
          },
          {
            "type": "SEQ",
            "members": [
              {
                "type": "STRING",
                "value": "/*"
              },
              {
                "type": "PATTERN",
                "value": "[^*]*\\*+([^/*][^*]*\\*+)*"
              },
              {
                "type": "STRING",
                "value": "/"
              }
            ]
          }
        ]
      }
    }
  },
  "extras": [
    {
      "type": "PATTERN",
      "value": "\\s"
    }
  ],
  "conflicts": [],
  "precedences": [],
  "externals": [
    {
      "type": "SYMBOL",
      "name": "raw_string_literal"
    }
  ],
  "inline": [],
  "supertypes": [],
  "reserved": {}
}