Socket
Socket
Sign inDemoInstall

tree-sitter-c-sharp

Package Overview
Dependencies
13
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.15.0 to 0.16.0

src/scanner.c

368

grammar.js

@@ -28,6 +28,10 @@ const PREC = {

$.comment,
/[\s\u00A0]+/,
$.preprocessor_directive
/[\s\u00A0\uFEFF\u3000]+/,
$.preprocessor_call
],
externals: $ => [
$._preproc_directive_end,
],
conflicts: $ => [

@@ -40,18 +44,21 @@ [$.block, $.initializer_expression],

[$._expression, $.declaration_pattern],
[$._expression, $._simple_name],
[$._expression, $._simple_name, $.generic_name],
[$._expression, $._simple_name, $.parameter],
[$.nullable_type, $.binary_expression],
[$.from_clause, $._reserved_identifier],
[$._simple_name, $.enum_member_declaration],
[$._name, $._expression],
[$._simple_name, $.type_parameter],
[$._simple_name, $.generic_name],
[$._simple_name, $.constructor_declaration],
[$.qualified_name, $.explicit_interface_specifier],
[$.qualified_name, $.member_access_expression],
[$.from_clause, $._reserved_identifier],
[$._type, $.array_creation_expression],
[$._type, $.stack_alloc_array_creation_expression],
[$._type, $.attribute],
[$.parameter_modifier, $.this_expression],
[$.parameter, $._simple_name],
[$.parameter, $.tuple_element, $.declaration_expression],
[$.tuple_element, $.variable_declarator],
],

@@ -106,6 +113,2 @@

identifier: $ => token(seq(optional('@'), /[a-zA-Z_][a-zA-Z_0-9]*/)), // identifier_token in Roslyn
global: $ => 'global',
_identifier_or_global: $ => choice($.global, $.identifier),
_name: $ => choice(

@@ -167,3 +170,3 @@ $.alias_qualified_name,

event_field_declaration: $ => seq(
event_field_declaration: $ => prec.dynamic(1, seq(
repeat($.attribute_list),

@@ -174,3 +177,3 @@ repeat($.modifier),

';'
),
)),

@@ -199,6 +202,9 @@ modifier: $ => prec.right(choice(

variable_declaration: $ => seq($._type, commaSep1($.variable_declarator)),
variable_declaration: $ => seq(
field('type', $._type),
commaSep1($.variable_declarator)
),
variable_declarator: $ => seq(
$.identifier,
choice($.identifier, $.tuple_pattern),
optional($.bracketed_argument_list),

@@ -214,14 +220,14 @@ optional($.equals_value_clause)

tuple_pattern: $ => seq(
'(',
commaSep1(choice($.identifier, $.discard)),
')'
),
argument: $ => prec(1, seq(
optional($.name_colon),
optional(choice('ref', 'out', 'in')),
choice(
seq(
optional(choice('ref','out', 'in')),
$._expression
),
seq(
'out',
$._type,
$.identifier
)
$._expression,
$.declaration_expression
)

@@ -264,4 +270,4 @@ )),

optional($.parameter_modifier),
optional($._type),
$.identifier,
optional(field('type', $._type)),
field('name', $.identifier),
optional($.equals_value_clause)

@@ -299,4 +305,4 @@ ),

'operator',
$._type,
$.parameter_list,
field('type', $._type),
field('parameters', $.parameter_list),
$._function_body,

@@ -306,4 +312,4 @@ ),

_function_body: $ => choice(
$.block,
seq($.arrow_expression_clause, ';'),
field('body', $.block),
seq(field('body', $.arrow_expression_clause), ';'),
';' // Only applies to interfaces

@@ -324,7 +330,7 @@ ),

repeat($.modifier),
$.return_type,
field('type', $.return_type),
optional($.explicit_interface_specifier),
$.identifier,
optional($.type_parameter_list),
$.parameter_list,
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('parameters', $.parameter_list),
repeat($.type_parameter_constraints_clause),

@@ -363,6 +369,6 @@ $._function_body,

repeat($.modifier),
$._type,
field('type', $._type),
'operator',
$._overloadable_operator,
$.parameter_list,
field('operator', $._overloadable_operator),
field('parameters', $.parameter_list),
$._function_body,

@@ -392,7 +398,7 @@ ),

'event',
$._type,
field('type', $._type),
optional($.explicit_interface_specifier),
$.identifier,
field('name', $.identifier),
choice(
$._accessor_list,
field('accessors', $.accessor_list),
';'

@@ -402,3 +408,3 @@ )

_accessor_list: $ => seq(
accessor_list: $ => seq(
'{',

@@ -419,9 +425,9 @@ repeat($.accessor_declaration),

repeat($.modifier),
$._type,
field('type', $._type),
optional($.explicit_interface_specifier),
'this',
$.bracketed_parameter_list,
field('parameters', $.bracketed_parameter_list),
choice(
$._accessor_list,
seq($.arrow_expression_clause, ';')
field('accessors', $.accessor_list),
seq(field('value', $.arrow_expression_clause), ';')
)

@@ -435,8 +441,14 @@ ),

repeat($.modifier),
$._type,
field('type', $._type),
optional($.explicit_interface_specifier),
$.identifier,
field('name', $.identifier),
choice(
seq($._accessor_list, optional(seq('=', $._expression, ';'))), // grammar.txt does not allow bodyless properties.
seq($.arrow_expression_clause, ';')
seq(
field('accessors', $.accessor_list),
optional(seq('=', field('value', $._expression), ';'))
), // grammar.txt does not allow bodyless properties.
seq(
field('value', $.arrow_expression_clause),
';'
)
),

@@ -449,5 +461,5 @@ ),

'enum',
$.identifier,
optional($.base_list),
$.enum_member_declaration_list,
field('name', $.identifier),
field('bases', optional($.base_list)),
field('body', $.enum_member_declaration_list),
optional(';')

@@ -467,4 +479,4 @@ ),

repeat($.attribute_list),
$.identifier,
optional(seq('=', $._expression))
field('name', $.identifier),
optional(seq('=', field('value', $._expression)))
),

@@ -476,7 +488,7 @@

'class',
$.identifier,
optional($.type_parameter_list),
optional($.base_list),
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('bases', optional($.base_list)),
repeat($.type_parameter_constraints_clause),
$.declaration_list,
field('body', $.declaration_list),
optional(';')

@@ -495,7 +507,7 @@ ),

'interface',
$.identifier,
optional($.type_parameter_list),
optional($.base_list),
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('bases', optional($.base_list)),
repeat($.type_parameter_constraints_clause),
$.declaration_list,
field('body', $.declaration_list),
optional(';')

@@ -508,7 +520,7 @@ ),

'struct',
$.identifier,
optional($.type_parameter_list),
optional($.base_list),
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('bases', optional($.base_list)),
repeat($.type_parameter_constraints_clause),
$.declaration_list,
field('body', $.declaration_list),
optional(';')

@@ -521,6 +533,6 @@ ),

'delegate',
$.return_type,
$.identifier,
optional($.type_parameter_list),
$.parameter_list,
field('type', $.return_type),
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('parameters', $.parameter_list),
repeat($.type_parameter_constraints_clause),

@@ -532,4 +544,4 @@ ';'

'namespace',
$._name,
$.declaration_list,
field('name', $._name),
field('body', $.declaration_list),
optional(';')

@@ -545,4 +557,3 @@ ),

$.predefined_type,
// $.ref_type, // TODO: Conflicts with 'ref' modifier...
// $.tuple_type, // TODO: Conflicts with everything
$.tuple_type, // TODO: Conflicts with everything
),

@@ -552,3 +563,6 @@

array_type: $ => prec(PREC.POSTFIX, seq($._type, $.array_rank_specifier)),
array_type: $ => prec(PREC.POSTFIX, seq(
field('type', $._type),
field('rank', $.array_rank_specifier)
)),

@@ -559,7 +573,15 @@ // grammar.txt marks this non-optional and includes omitted_array_size_expression in

nullable_type: $ => prec(1, seq($._type, '?')),
// When used in a nullable type, the '?' operator binds tighter than the
// binary operators `as` and `is`. But in a conditional expression, the `?`
// binds *looser*. This weird double precedence is required in order to
// preserve the conflict, so that `?` can be used in both ways, depending
// on what follows.
nullable_type: $ => choice(
prec(PREC.EQUAL + 1, seq($._type, '?')),
prec(PREC.COND - 1, seq($._type, '?'))
),
pointer_type: $ => prec(1, seq($._type, '*')),
pointer_type: $ => prec(PREC.POSTFIX, seq($._type, '*')),
predefined_type: $ => choice(
predefined_type: $ => token(choice(
'bool',

@@ -581,3 +603,3 @@ 'byte',

// void is handled in return_type for better matching
),
)),

@@ -595,3 +617,3 @@ ref_type: $ => seq(

',',
$.argument,
$.tuple_element,
)),

@@ -601,3 +623,6 @@ ')'

tuple_element: $ => seq($._type, optional($.identifier)),
tuple_element: $ => seq(
field('type', $._type),
field('name', optional($.identifier))
),

@@ -648,9 +673,9 @@ _statement: $ => choice(

'(',
optional(choice($.variable_declaration, commaSep1($._expression))),
field('initializer', optional(choice($.variable_declaration, commaSep1($._expression)))),
';',
optional($._expression),
field('condition', optional($._expression)),
';',
optional(commaSep1($._expression)),
field('update', optional(commaSep1($._expression))),
')',
$._statement
field('body', $._statement)
),

@@ -664,9 +689,12 @@

choice(
seq($._type, $.identifier), // for_each_statement
$._expression, // for_each_variable_statement
seq(
field('type', $._type),
field('left', $.identifier)
), // for_each_statement
field('left', $._expression), // for_each_variable_statement
),
'in',
$._expression,
field('right', $._expression),
')',
$._statement
field('body', $._statement)
),

@@ -688,10 +716,11 @@

'(',
$._expression,
field('condition', $._expression),
')',
$._statement,
optional($.else_clause)
field('consequence', $._statement),
optional(seq(
'else',
field('alternative', $._statement)
))
)),
else_clause: $ => seq('else', $._statement),
labeled_statement: $ => seq(

@@ -728,4 +757,8 @@ alias($.identifier, $.label_name),

'(',
$._expression,
field('value', $._expression),
')',
field('body', $.switch_body)
),
switch_body: $ => seq(
'{',

@@ -762,3 +795,6 @@ repeat($.switch_section),

declaration_pattern: $ => seq($._type, $._variable_designation),
declaration_pattern: $ => seq(
field('type', $._type),
$._variable_designation
),

@@ -813,3 +849,3 @@ _variable_designation: $ => choice(

'try',
$.block,
field('body', $.block),
repeat($.catch_clause),

@@ -823,6 +859,11 @@ optional($.finally_clause),

optional($.catch_filter_clause),
$.block
field('body', $.block)
),
catch_declaration: $ => seq('(', $._type, optional($.identifier), ')'),
catch_declaration: $ => seq(
'(',
field('type', $._type),
field('name', optional($.identifier)),
')'
),

@@ -907,5 +948,5 @@ catch_filter_clause: $ => seq('when', '(', $._expression, ')'),

'(',
$._type,
field('type', $._type),
')',
$._expression
field('value', $._expression)
)),

@@ -925,8 +966,12 @@

conditional_expression: $ => prec.right(PREC.COND, seq(
$._expression, '?', $._expression, ':', $._expression
field('condition', $._expression),
'?',
field('consequence', $._expression),
':',
field('alternative', $._expression)
)),
declaration_expression: $ => seq(
$._type,
$._variable_designation
field('type', $._type),
field('name', $.identifier)
),

@@ -936,9 +981,7 @@

'default',
optional(
seq(
'(',
$._type,
')'
)
)
optional(seq(
'(',
field('type', $._type),
')'
))
)),

@@ -1023,5 +1066,5 @@

member_access_expression: $ => prec(PREC.DOT, seq(
$._expression,
field('expression', choice($._expression, $._type, $._name)),
choice('.', '->'),
$._simple_name
field('name', $._simple_name)
)),

@@ -1036,5 +1079,5 @@

'new',
$._type,
optional($.argument_list),
optional($.initializer_expression)
field('type', $._type),
field('arguments', optional($.argument_list)),
field('initializer', optional($.initializer_expression))
)),

@@ -1155,5 +1198,5 @@

'(',
$._expression,
field('value', $._expression),
',',
$._type,
field('type', $._type),
')'

@@ -1218,3 +1261,2 @@ ),

$.conditional_expression,
// $.declaration_expression,
$.default_expression,

@@ -1249,15 +1291,6 @@ $.element_access_expression,

$.type_of_expression,
$._type,
$.identifier,
$._simple_name,
alias($._reserved_identifier, $.identifier),
// Literals
$.null_literal,
$.boolean_literal,
$.character_literal,
$.real_literal, // Don't combine real and integer literals together
$.integer_literal,
$.string_literal, // Or strings and verbatim strings
$.verbatim_string_literal
$._literal
),

@@ -1286,12 +1319,35 @@

['??', PREC.EQUAL],
['as', PREC.EQUAL],
].map(([operator, precedence]) =>
prec.left(precedence, seq($._expression, operator, $._expression))
prec.left(precedence, seq(
field('left', $._expression),
field('operator', operator),
field('right', $._expression)
))
).concat(
prec.left(PREC.EQUAL, seq($._expression, 'is', $._type))
prec.left(PREC.EQUAL, seq(
field('left', $._expression),
field('operator', choice('is', 'as')),
field('right', $._type)
))
)
),
identifier: $ => token(seq(optional('@'), /[a-zA-Z_][a-zA-Z_0-9]*/)), // identifier_token in Roslyn
global: $ => 'global',
_identifier_or_global: $ => choice($.global, $.identifier),
// Literals - grammar.txt is useless here as it just refs to lexical specification
_literal: $ => choice(
$.null_literal,
$.boolean_literal,
$.character_literal,
// Don't combine real and integer literals together
$.real_literal,
$.integer_literal,
// Or strings and verbatim strings
$.string_literal,
$.verbatim_string_literal
),
boolean_literal: $ => choice(

@@ -1396,33 +1452,13 @@ 'true',

// We could line this up with grammar.txt *_trivia at some point.
// Will need to understand how structured_trivia is implemented.
preprocessor_directive: $ => token(
seq(
// TODO: Nothing should come before the # on a line except whitespace
'#',
choice(
'if',
'define',
'endif',
'undef',
'warning',
'error',
'line',
'region',
'endregion',
'pragma warning',
'pragma checksum',
'nullable',
// Individiual code can be broken up by #if #else #elif etc. Parsing all the code ignoring the tokens can cause
// syntax errors. What we do instead is always parse the #if block but then completely ignore the #else and #elif blocks.
// It's not perfect as sometimes only valid combinations of names would compile or the defined names might be re-used.
seq(
choice('else', seq('elif', /.*/)),
repeat(choice(/[^#]/, /#[\s\u00A0]*(else|elif|define|undef|warning|error|line|region|endregion|pragma|nullable)/)), // Consume "disabled" code
/#[\s\u00A0]*endif/
),
),
/.*/
)
preprocessor_call: $ => seq(
$.preprocessor_directive,
repeat(choice(
$.identifier,
$._literal,
token(prec(-1, /[^\s]+/))
)),
$._preproc_directive_end
),
preprocessor_directive: $ => /#[a-z]\w*/,
}

@@ -1429,0 +1465,0 @@ })

{
"name": "tree-sitter-c-sharp",
"version": "0.15.0",
"version": "0.16.0",
"description": "C# grammar for tree-sitter",

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

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

@@ -19,0 +19,0 @@ "scripts": {

@@ -78,2 +78,3 @@ tree-sitter-c-sharp

* [Official C# 6 Language Spec](https://github.com/dotnet/csharplang/blob/master/spec/) provides chapters that formally define the language grammar.
* [Roslyn C# language grammar export](https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4)
* [Roslyn C# language grammar export](https://github.com/dotnet/roslyn/blob/master/src/Compilers/CSharp/Portable/Generated/CSharp.Generated.g4)
* [SharpLab](https://sharplab.io) (web-based syntax tree playground based on Roslyn)

@@ -1,5 +0,4 @@

examples/Newtonsoft.Json/Src/Newtonsoft.Json/Linq/JToken.cs
examples/nunit/src/CommonAssemblyInfo.cs
examples/nunit/src/NUnitFramework/tests/Assertions/CollectionAssertTest.cs
examples/orchard/src/Orchard.Web/Modules/Orchard.Projections/Drivers/NavigationQueryPartDriver.cs
examples/orchard/src/Orchard/Mvc/Routes/RoutePublisher.cs
examples/Newtonsoft.Json/Src/Newtonsoft.Json.Tests/Serialization/SerializationErrorHandlingTests.cs
examples/Newtonsoft.Json/Src/Newtonsoft.Json.Tests/TestFixtureBase.cs
examples/Newtonsoft.Json/Src/Newtonsoft.Json/JsonReader.cs
examples/nunit/src/NUnitFramework/tests/Internal/RuntimeFrameworkTests.cs

Sorry, the diff of this file is not supported yet

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc