Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tree-sitter-c

Package Overview
Dependencies
Maintainers
5
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter-c - npm Package Compare versions

Comparing version 0.16.0 to 0.16.1

178

grammar.js

@@ -28,3 +28,3 @@ const PREC = {

extras: $ => [
/\s/,
/\s|\\\r?\n/,
$.comment,

@@ -40,2 +40,3 @@ ],

$._non_case_statement,
$._assignment_left_expression,
],

@@ -76,3 +77,9 @@

preprocessor('include'),
field('path', choice($.string_literal, $.system_lib_string))
field('path', choice(
$.string_literal,
$.system_lib_string,
$.identifier,
alias($.preproc_call_expression, $.call_expression),
)),
'\n'
),

@@ -111,5 +118,75 @@

_preproc_expression: $ => choice(
$.identifier,
alias($.preproc_call_expression, $.call_expression),
$.number_literal,
$.char_literal,
$.preproc_defined,
alias($.preproc_unary_expression, $.unary_expression),
alias($.preproc_binary_expression, $.binary_expression),
alias($.preproc_parenthesized_expression, $.parenthesized_expression)
),
preproc_parenthesized_expression: $ => seq(
'(',
$._preproc_expression,
')'
),
preproc_defined: $ => choice(
prec(PREC.CALL, seq('defined', '(', $.identifier, ')')),
seq('defined', $.identifier),
),
preproc_unary_expression: $ => prec.left(PREC.UNARY, seq(
field('operator', choice('!', '~', '-', '+')),
field('argument', $._preproc_expression)
)),
preproc_call_expression: $ => prec(PREC.CALL, seq(
field('function', $.identifier),
field('arguments', alias($.preproc_argument_list, $.argument_list))
)),
preproc_argument_list: $ => seq(
'(',
commaSep($._preproc_expression),
')'
),
preproc_binary_expression: $ => {
const table = [
['+', PREC.ADD],
['-', PREC.ADD],
['*', PREC.MULTIPLY],
['/', PREC.MULTIPLY],
['%', PREC.MULTIPLY],
['||', PREC.LOGICAL_OR],
['&&', PREC.LOGICAL_AND],
['|', PREC.INCLUSIVE_OR],
['^', PREC.EXCLUSIVE_OR],
['&', PREC.BITWISE_AND],
['==', PREC.EQUAL],
['!=', PREC.EQUAL],
['>', PREC.RELATIONAL],
['>=', PREC.RELATIONAL],
['<=', PREC.RELATIONAL],
['<', PREC.RELATIONAL],
['<<', PREC.SHIFT],
['>>', PREC.SHIFT],
];
return choice(...table.map(([operator, precedence]) => {
return prec.left(precedence, seq(
field('left', $._preproc_expression),
field('operator', operator),
field('right', $._preproc_expression)
))
}));
},
// Main Grammar
function_definition: $ => seq(
optional($.ms_call_modifier),
$._declaration_specifiers,

@@ -141,3 +218,4 @@ field('declarator', $._declarator),

$.type_qualifier,
$.attribute_specifier
$.attribute_specifier,
$.ms_declspec_modifier
)),

@@ -148,3 +226,4 @@ field('type', $._type_specifier),

$.type_qualifier,
$.attribute_specifier
$.attribute_specifier,
$.ms_declspec_modifier
))

@@ -170,2 +249,38 @@ ),

ms_declspec_modifier: $ => seq(
'__declspec',
'(',
$.identifier,
')',
),
ms_based_modifier: $ => seq(
'__based',
$.argument_list,
),
ms_call_modifier: $ => choice(
'__cdecl',
'__clrcall',
'__stdcall',
'__fastcall',
'__thiscall',
'__vectorcall'
),
ms_restrict_modifier: $ => '__restrict',
ms_unsigned_ptr_modifier: $ => '__uptr',
ms_signed_ptr_modifier: $ => '__sptr',
ms_unaligned_ptr_modifier: $ => choice('_unaligned', '__unaligned'),
ms_pointer_modifier: $ => choice(
$.ms_unaligned_ptr_modifier,
$.ms_restrict_modifier,
$.ms_unsigned_ptr_modifier,
$.ms_signed_ptr_modifier,
),
declaration_list: $ => seq(

@@ -229,4 +344,8 @@ '{',

pointer_declarator: $ => prec.dynamic(1, prec.right(seq(
optional($.ms_based_modifier),
'*',
repeat($.ms_pointer_modifier),
repeat($.type_qualifier),

@@ -236,3 +355,5 @@ field('declarator', $._declarator)

pointer_field_declarator: $ => prec.dynamic(1, prec.right(seq(
optional($.ms_based_modifier),
'*',
repeat($.ms_pointer_modifier),
repeat($.type_qualifier),

@@ -242,3 +363,5 @@ field('declarator', $._field_declarator)

pointer_type_declarator: $ => prec.dynamic(1, prec.right(seq(
optional($.ms_based_modifier),
'*',
repeat($.ms_pointer_modifier),
repeat($.type_qualifier),

@@ -252,7 +375,8 @@ field('declarator', $._type_declarator)

function_declarator: $ => prec(1, seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
repeat($.attribute_specifier)
)),
function_declarator: $ => prec(1,
seq(
field('declarator', $._declarator),
field('parameters', $.parameter_list),
repeat($.attribute_specifier),
)),
function_field_declarator: $ => prec(1, seq(

@@ -387,2 +511,3 @@ field('declarator', $._field_declarator),

'struct',
optional($.ms_declspec_modifier),
choice(

@@ -399,2 +524,3 @@ seq(

'union',
optional($.ms_declspec_modifier),
choice(

@@ -604,11 +730,13 @@ seq(

_assignment_left_expression: $ => choice(
$.identifier,
$.call_expression,
$.field_expression,
$.pointer_expression,
$.subscript_expression,
$.parenthesized_expression
),
assignment_expression: $ => prec.right(PREC.ASSIGNMENT, seq(
field('left', choice(
$.identifier,
$.call_expression,
$.field_expression,
$.pointer_expression,
$.subscript_expression,
$.parenthesized_expression
)),
field('left', $._assignment_left_expression),
choice(

@@ -790,3 +918,3 @@ '=',

char_literal: $ => seq(
choice('L\'', '\''),
choice('L\'', 'u\'', 'U\'', 'u8\'', '\''),
choice(

@@ -805,3 +933,3 @@ $.escape_sequence,

string_literal: $ => seq(
choice('L"', '"'),
choice('L"', 'u"', 'U"', 'u8"', '"'),
repeat(choice(

@@ -811,6 +939,6 @@ token.immediate(prec(1, /[^\\"\n]+/)),

)),
'"'
'"',
),
escape_sequence: $ => token.immediate(seq(
escape_sequence: $ => token(prec(1, seq(
'\\',

@@ -824,3 +952,3 @@ choice(

)
)),
))),

@@ -890,3 +1018,4 @@ system_lib_string: $ => token(seq(

preprocessor('if'),
field('condition', $.preproc_arg),
field('condition', $._preproc_expression),
'\n',
repeat(content($)),

@@ -912,3 +1041,4 @@ field('alternative', optional(elseBlock($))),

preprocessor('elif'),
field('condition', $.preproc_arg),
field('condition', $._preproc_expression),
'\n',
repeat(content($)),

@@ -915,0 +1045,0 @@ field('alternative', optional(elseBlock($))),

9

package.json
{
"name": "tree-sitter-c",
"version": "0.16.0",
"version": "0.16.1",
"description": "C grammar for node-tree-sitter",

@@ -16,3 +16,3 @@ "main": "index.js",

"devDependencies": {
"tree-sitter-cli": "^0.15.14"
"tree-sitter-cli": "^0.16.5"
},

@@ -28,6 +28,7 @@ "scripts": {

"file-types": [
"c"
"c",
"h"
]
}
]
}
}

@@ -402,2 +402,6 @@ [

"named": true
},
{
"type": "preproc_defined",
"named": true
}

@@ -527,2 +531,6 @@ ]

"named": true
},
{
"type": "preproc_defined",
"named": true
}

@@ -616,2 +624,6 @@ ]

"named": true
},
{
"type": "preproc_defined",
"named": true
}

@@ -996,2 +1008,6 @@ ]

{
"type": "ms_declspec_modifier",
"named": true
},
{
"type": "storage_class_specifier",

@@ -1216,2 +1232,6 @@ "named": true

{
"type": "ms_declspec_modifier",
"named": true
},
{
"type": "storage_class_specifier",

@@ -1449,2 +1469,10 @@ "named": true

{
"type": "ms_call_modifier",
"named": true
},
{
"type": "ms_declspec_modifier",
"named": true
},
{
"type": "storage_class_specifier",

@@ -1686,2 +1714,69 @@ "named": true

{
"type": "ms_based_modifier",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "argument_list",
"named": true
}
]
}
},
{
"type": "ms_call_modifier",
"named": true,
"fields": {}
},
{
"type": "ms_declspec_modifier",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "ms_pointer_modifier",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "ms_restrict_modifier",
"named": true
},
{
"type": "ms_signed_ptr_modifier",
"named": true
},
{
"type": "ms_unaligned_ptr_modifier",
"named": true
},
{
"type": "ms_unsigned_ptr_modifier",
"named": true
}
]
}
},
{
"type": "ms_unaligned_ptr_modifier",
"named": true,
"fields": {}
},
{
"type": "parameter_declaration",

@@ -1724,2 +1819,6 @@ "named": true,

{
"type": "ms_declspec_modifier",
"named": true
},
{
"type": "storage_class_specifier",

@@ -1788,2 +1887,6 @@ "named": true

"named": true
},
{
"type": "preproc_defined",
"named": true
}

@@ -1821,2 +1924,10 @@ ]

{
"type": "ms_based_modifier",
"named": true
},
{
"type": "ms_pointer_modifier",
"named": true
},
{
"type": "type_qualifier",

@@ -1911,2 +2022,17 @@ "named": true

{
"type": "preproc_defined",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
{
"type": "preproc_elif",

@@ -1934,4 +2060,32 @@ "named": true,

{
"type": "preproc_arg",
"type": "binary_expression",
"named": true
},
{
"type": "call_expression",
"named": true
},
{
"type": "char_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "number_literal",
"named": true
},
{
"type": "parenthesized_expression",
"named": true
},
{
"type": "preproc_defined",
"named": true
},
{
"type": "unary_expression",
"named": true
}

@@ -2122,4 +2276,32 @@ ]

{
"type": "preproc_arg",
"type": "binary_expression",
"named": true
},
{
"type": "call_expression",
"named": true
},
{
"type": "char_literal",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "number_literal",
"named": true
},
{
"type": "parenthesized_expression",
"named": true
},
{
"type": "preproc_defined",
"named": true
},
{
"type": "unary_expression",
"named": true
}

@@ -2285,2 +2467,10 @@ ]

{
"type": "call_expression",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "string_literal",

@@ -2421,2 +2611,12 @@ "named": true

}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "ms_declspec_modifier",
"named": true
}
]
}

@@ -2638,2 +2838,6 @@ },

"named": true
},
{
"type": "preproc_defined",
"named": true
}

@@ -2690,2 +2894,12 @@ ]

}
},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "ms_declspec_modifier",
"named": true
}
]
}

@@ -2766,2 +2980,34 @@ },

{
"type": "#define",
"named": false
},
{
"type": "#elif",
"named": false
},
{
"type": "#else",
"named": false
},
{
"type": "#endif",
"named": false
},
{
"type": "#if",
"named": false
},
{
"type": "#ifdef",
"named": false
},
{
"type": "#ifndef",
"named": false
},
{
"type": "#include",
"named": false
},
{
"type": "%",

@@ -2915,2 +3161,10 @@ "named": false

{
"type": "U\"",
"named": false
},
{
"type": "U'",
"named": false
},
{
"type": "[",

@@ -2940,2 +3194,42 @@ "named": false

{
"type": "__based",
"named": false
},
{
"type": "__cdecl",
"named": false
},
{
"type": "__clrcall",
"named": false
},
{
"type": "__declspec",
"named": false
},
{
"type": "__fastcall",
"named": false
},
{
"type": "__stdcall",
"named": false
},
{
"type": "__thiscall",
"named": false
},
{
"type": "__unaligned",
"named": false
},
{
"type": "__vectorcall",
"named": false
},
{
"type": "_unaligned",
"named": false
},
{
"type": "auto",

@@ -2965,2 +3259,6 @@ "named": false

{
"type": "defined",
"named": false
},
{
"type": "do",

@@ -3018,2 +3316,14 @@ "named": false

{
"type": "ms_restrict_modifier",
"named": true
},
{
"type": "ms_signed_ptr_modifier",
"named": true
},
{
"type": "ms_unsigned_ptr_modifier",
"named": true
},
{
"type": "null",

@@ -3095,2 +3405,18 @@ "named": true

{
"type": "u\"",
"named": false
},
{
"type": "u'",
"named": false
},
{
"type": "u8\"",
"named": false
},
{
"type": "u8'",
"named": false
},
{
"type": "union",

@@ -3097,0 +3423,0 @@ "named": false

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc