Skip to main content

GRAMMAR

Constant GRAMMAR 

Source
pub const GRAMMAR: &str = "module.exports = grammar({\n  name: \'ccomment\',\n\n  externals: $ => [\n    $.raw_string_literal,\n  ],\n\n  rules: {\n    translation_unit: $ => repeat($._top_level_item),\n    \n    _top_level_item: $ => choice(\n      $.string_literal,\n      $.char_literal,\n      $.raw_string_literal,\n      $.comment,\n      $.nothing,\n      $.define,\n    ),\n\n    nothing: $ => token(\n      choice(\n        /[^R\"\'\\/#]+/,\n        \'R\',\n        \'#\',\n      )\n    ),\n\n    preproc_continuation_line: $ => token(\n      ///([^\\\\\\n]|\\\\[^\\n])*\\\\\\r*\\n/\n      /.*\\\\\\r?\\n/\n    ),\n\n    preproc_line: $ => token(\n      ///[^\\n]*\\n/\n      /.*\\n/\n    ),\n    \n    define: $ => seq(\n      /#[ \\t]*define[ \\t]+/,\n      repeat($.preproc_continuation_line),\n      $.preproc_line,\n    ),\n    \n    string_literal: $ => seq(\n      /\"([^\\\\\"]|\\\\(.|\\n))*\"/,\n    ),\n    \n    char_literal: $ => seq(\n      /\'([^\\\\\']|\\\\(.|\\n))*\'/,\n    ),\n    \n    // http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890\n    comment: $ => token(choice(\n      seq(\'//\', /(\\\\(.|\\r?\\n)|[^\\\\\\n])*/),\n      seq(\n        \'/*\',\n        /[^*]*\\*+([^/*][^*]*\\*+)*/,\n      \'/\'\n    )\n    )),\n  },\n\n});\n";
Expand description

The source of the Ccomment tree-sitter grammar description.