tree-sitter-c
Advanced tools
Comparing version 0.2.0 to 0.2.1
111
grammar.js
@@ -36,11 +36,16 @@ const PREC = { | ||
[$._type_specifier, $.macro_type_specifier], | ||
[$.sized_type_specifier], | ||
], | ||
rules: { | ||
translation_unit: $ => repeat(choice( | ||
translation_unit: $ => repeat($._top_level_item), | ||
_top_level_item: $ => choice( | ||
$._preproc_statement, | ||
$.function_definition, | ||
$.declaration, | ||
$._empty_declaration | ||
)), | ||
$._statement, | ||
$._empty_declaration, | ||
$.linkage_specification | ||
), | ||
@@ -50,2 +55,3 @@ // Preprocesser | ||
_preproc_statement: $ => choice( | ||
$.preproc_if, | ||
$.preproc_ifdef, | ||
@@ -69,3 +75,6 @@ $.preproc_include, | ||
$.identifier, | ||
optional($.preproc_arg), | ||
optional(seq( | ||
/[ \t]+/, | ||
$.preproc_arg | ||
)), | ||
'\n' | ||
@@ -93,10 +102,15 @@ ), | ||
preproc_if: $ => seq( | ||
'#if', | ||
$._expression, | ||
'\n', | ||
repeat($._top_level_item), | ||
optional($.preproc_else), | ||
'#endif' | ||
), | ||
preproc_ifdef: $ => seq( | ||
choice('#ifdef', '#ifndef'), | ||
$.identifier, | ||
repeat(choice( | ||
$._preproc_statement, | ||
$.function_definition, | ||
$.declaration | ||
)), | ||
repeat($._top_level_item), | ||
optional($.preproc_else), | ||
@@ -108,7 +122,3 @@ '#endif' | ||
'#else', | ||
repeat(choice( | ||
$._preproc_statement, | ||
$.function_definition, | ||
$.declaration | ||
)) | ||
repeat($._top_level_item) | ||
), | ||
@@ -143,2 +153,18 @@ | ||
linkage_specification: $ => seq( | ||
'extern', | ||
$.string_literal, | ||
choice( | ||
$.function_definition, | ||
$.declaration, | ||
$.declaration_list | ||
) | ||
), | ||
declaration_list: $ => seq( | ||
'{', | ||
repeat($._top_level_item), | ||
'}' | ||
), | ||
_declarator: $ => choice( | ||
@@ -210,7 +236,3 @@ $.pointer_declarator, | ||
'{', | ||
repeat(choice( | ||
$.declaration, | ||
$._empty_declaration, | ||
$._statement | ||
)), | ||
repeat($._top_level_item), | ||
'}' | ||
@@ -250,3 +272,3 @@ ), | ||
)), | ||
$.identifier | ||
optional($.identifier) | ||
), | ||
@@ -348,3 +370,7 @@ | ||
expression_statement: $ => seq( | ||
optional($._expression), ';' | ||
optional(choice( | ||
$._expression, | ||
$.comma_expression | ||
)), | ||
';' | ||
), | ||
@@ -442,6 +468,13 @@ | ||
$.string_literal, | ||
$.concatenated_string, | ||
$.char_literal, | ||
seq('(', $._expression, ')') | ||
$.parenthesized_expression | ||
), | ||
comma_expression: $ => seq( | ||
$._expression, | ||
',', | ||
choice($._expression, $.comma_expression) | ||
), | ||
conditional_expression: $ => prec.right(PREC.CONDITIONAL, seq( | ||
@@ -542,2 +575,8 @@ $._expression, | ||
parenthesized_expression: $ => seq( | ||
'(', | ||
choice($._expression, $.comma_expression), | ||
')' | ||
), | ||
type_name: $ => seq( | ||
@@ -551,4 +590,6 @@ repeat($.type_qualifier), | ||
'{', | ||
$._initializer_list_contents, | ||
optional(','), | ||
optional(seq( | ||
$._initializer_list_contents, | ||
optional(',') | ||
)), | ||
'}' | ||
@@ -575,7 +616,10 @@ ), | ||
number_literal: $ => token(choice( | ||
/\d+(\.\d+)?/, | ||
/\d+u/, | ||
seq('0x', /[0-9a-fA-f]+/), | ||
seq('0b', /[01]+/) | ||
number_literal: $ => token(seq( | ||
choice( | ||
/\d+(\.\d+)?/, | ||
/\d+u/, | ||
seq('0x', /[0-9a-fA-f]+/), | ||
seq('0b', /[01]+/) | ||
), | ||
repeat(choice('u', 'l', 'U', 'L')) | ||
)), | ||
@@ -592,5 +636,10 @@ | ||
concatenated_string: $ => seq( | ||
$.string_literal, | ||
repeat1($.string_literal) | ||
), | ||
string_literal: $ => token(seq( | ||
'"', | ||
repeat(choice(/[^"]/, '\\"')), | ||
repeat(choice(/[^\\"\n]/, /\\./)), | ||
'"') | ||
@@ -616,3 +665,3 @@ ), | ||
'(', | ||
$._type_specifier, | ||
$.type_name, | ||
')' | ||
@@ -619,0 +668,0 @@ ), |
{ | ||
"name": "tree-sitter-c", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "C grammar for node-tree-sitter", | ||
@@ -17,8 +17,8 @@ "main": "index.js", | ||
"devDependencies": { | ||
"tree-sitter-cli": "^0.5.0" | ||
"tree-sitter-cli": "^0.5.3" | ||
}, | ||
"scripts": { | ||
"build": "tree-sitter generate && node-gyp build", | ||
"test": "tree-sitter test" | ||
"test": "tree-sitter test && tree-sitter parse examples/* --quiet --time" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
3243774
21
3943