tree-sitter-c-sharp
Advanced tools
Comparing version 0.19.0 to 0.19.1
@@ -0,0 +0,0 @@ try { |
@@ -0,0 +0,0 @@ # tree-sitter-c-sharp |
292
grammar.js
const PREC = { | ||
DOT: 17, | ||
INVOCATION: 16, | ||
POSTFIX: 16, | ||
PREFIX: 15, | ||
UNARY: 15, | ||
CAST: 14, | ||
DOT: 18, | ||
INVOCATION: 18, | ||
POSTFIX: 18, | ||
PREFIX: 17, | ||
UNARY: 17, | ||
CAST: 17, | ||
RANGE: 16, | ||
SWITCH: 15, | ||
WITH: 14, | ||
MULT: 13, | ||
@@ -18,8 +21,6 @@ ADD: 12, | ||
LOGOR: 4, | ||
COND: 3, | ||
ASSIGN: 2, | ||
SEQ: 1, | ||
TERNARY: 1, | ||
COALESCING: 3, | ||
COND: 2, | ||
ASSIGN: 1, | ||
SELECT: 0, | ||
TYPE_PATTERN: -2, | ||
}; | ||
@@ -35,3 +36,3 @@ | ||
/[\s\u00A0\uFEFF\u3000]+/, | ||
$.preprocessor_call | ||
$._preprocessor_call | ||
], | ||
@@ -59,2 +60,6 @@ | ||
[$.type_pattern, $.declaration_pattern], | ||
[$.type_pattern, $.declaration_pattern, $.recursive_pattern], | ||
[$.type_pattern, $.tuple_element], | ||
[$._name, $._expression], | ||
@@ -64,2 +69,3 @@ [$._simple_name, $.type_parameter], | ||
[$._simple_name, $.constructor_declaration], | ||
[$._simple_name, $.name_colon], | ||
@@ -76,4 +82,7 @@ [$.qualified_name, $.explicit_interface_specifier], | ||
[$._type, $.stack_alloc_array_creation_expression], | ||
[$._type, $._nullable_base_type], | ||
[$._type, $._nullable_base_type, $.array_creation_expression], | ||
[$._nullable_base_type, $.stack_alloc_array_creation_expression], | ||
[$.parameter_modifier, $.this_expression], | ||
[$.parameter, $.this_expression], | ||
[$.parameter, $._simple_name], | ||
@@ -84,5 +93,12 @@ [$.parameter, $.tuple_element], | ||
[$.parameter, $.declaration_expression], | ||
[$.tuple_element], | ||
[$.tuple_element, $.declaration_expression], | ||
[$.tuple_element, $.variable_declarator] | ||
[$.tuple_element, $.variable_declarator], | ||
[$.array_creation_expression, $.element_access_expression], | ||
[$.constant_pattern, $._name], | ||
[$.constant_pattern, $._name, $._expression], | ||
[$.constant_pattern, $._expression], | ||
], | ||
@@ -102,4 +118,6 @@ | ||
repeat($.global_attribute_list), | ||
repeat($.global_statement), | ||
repeat($._namespace_member_declaration) | ||
choice( | ||
seq(repeat($.global_statement), repeat($._namespace_member_declaration)), | ||
$.file_scoped_namespace_declaration | ||
) | ||
), | ||
@@ -126,2 +144,3 @@ | ||
$.record_declaration, | ||
$.record_struct_declaration, | ||
$.struct_declaration, | ||
@@ -142,3 +161,4 @@ $.using_directive, | ||
$.delegate_declaration, | ||
$.record_declaration | ||
$.record_declaration, | ||
$.record_struct_declaration | ||
), | ||
@@ -149,2 +169,3 @@ | ||
using_directive: $ => seq( | ||
optional('global'), | ||
'using', | ||
@@ -214,3 +235,3 @@ optional(choice( | ||
attribute_argument: $ => seq( | ||
optional(choice($.name_equals,$.name_colon)), | ||
optional(choice($.name_equals, $.name_colon)), | ||
$._expression | ||
@@ -319,3 +340,3 @@ ), | ||
$.parameter, | ||
$.parameter_array | ||
$._parameter_array | ||
)), | ||
@@ -325,3 +346,3 @@ | ||
repeat($.attribute_list), | ||
optional($.parameter_modifier), | ||
optional(alias(choice('ref', 'out', 'this', 'in'), $.parameter_modifier)), | ||
optional(field('type', $._type)), | ||
@@ -332,5 +353,5 @@ field('name', $.identifier), | ||
parameter_modifier: $ => prec.right(choice('ref', 'out', 'this', 'in')), | ||
parameter_modifier: $ => choice('ref', 'out', 'this', 'in'), | ||
parameter_array: $ => seq( | ||
_parameter_array: $ => seq( | ||
repeat($.attribute_list), | ||
@@ -490,3 +511,3 @@ 'params', | ||
bracketed_parameter_list: $ => seq('[', commaSep1($.parameter), ']'), | ||
bracketed_parameter_list: $ => seq('[', $._formal_parameter_list, ']'), | ||
@@ -599,5 +620,18 @@ property_declaration: $ => seq( | ||
repeat($.type_parameter_constraints_clause), | ||
field('body', $._record_base), | ||
field('body', $._record_body), | ||
), | ||
record_struct_declaration: $ => seq( | ||
repeat($.attribute_list), | ||
repeat($.modifier), | ||
'record', | ||
'struct', | ||
field('name', $.identifier), | ||
field('type_parameters', optional($.type_parameter_list)), | ||
field('parameters', optional($.parameter_list)), | ||
field('bases', optional(alias($.record_base, $.base_list))), | ||
repeat($.type_parameter_constraints_clause), | ||
field('body', $._record_body), | ||
), | ||
record_base: $ => choice( | ||
@@ -613,3 +647,3 @@ seq(':', commaSep1($.identifier)), | ||
_record_base: $ => choice( | ||
_record_body: $ => choice( | ||
$.declaration_list, | ||
@@ -626,2 +660,11 @@ ';' | ||
file_scoped_namespace_declaration: $ => seq( | ||
'namespace', | ||
field('name', $._name), | ||
';', | ||
repeat($.extern_alias_directive), | ||
repeat($.using_directive), | ||
repeat($._type_declaration) | ||
), | ||
_type: $ => choice( | ||
@@ -649,10 +692,11 @@ $.implicit_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, '?')) | ||
nullable_type: $ => seq($._nullable_base_type, '?'), | ||
_nullable_base_type: $ => choice( | ||
$.array_type, | ||
$._name, | ||
$.pointer_type, | ||
$.function_pointer_type, | ||
$.predefined_type, | ||
$.tuple_type | ||
), | ||
@@ -907,3 +951,3 @@ | ||
type_pattern: $ => prec(PREC.TYPE_PATTERN, $._type), | ||
type_pattern: $ => $._type, | ||
@@ -934,3 +978,20 @@ parenthesized_pattern: $ => seq('(', $._pattern, ')'), | ||
constant_pattern: $ => prec.right($._expression), | ||
//We may need to expand this list if more things can be evaluated at compile time | ||
constant_pattern: $ => choice( | ||
$.binary_expression, | ||
$.default_expression, | ||
$.interpolated_string_expression, | ||
$.parenthesized_expression, | ||
$.postfix_unary_expression, | ||
$.prefix_unary_expression, | ||
$.size_of_expression, | ||
$.tuple_expression, | ||
$.type_of_expression, | ||
$.member_access_expression, | ||
$.invocation_expression, | ||
$.cast_expression, | ||
$._simple_name, | ||
$._literal | ||
), | ||
@@ -973,5 +1034,7 @@ declaration_pattern: $ => seq( | ||
)), | ||
expression_colon: $ => seq($._expression, ':'), | ||
subpattern: $ => seq( | ||
optional($.name_colon), | ||
optional($.expression_colon), | ||
$._pattern | ||
@@ -1078,7 +1141,7 @@ ), | ||
array_creation_expression: $ => seq( | ||
array_creation_expression: $ => prec.dynamic(PREC.UNARY, seq( | ||
'new', | ||
$.array_type, | ||
optional($.initializer_expression) | ||
), | ||
)), | ||
@@ -1186,12 +1249,16 @@ initializer_expression: $ => seq( | ||
'{{', | ||
token.immediate(prec(1, /[^{"\\\n]+/)), | ||
$._interpolated_string_text_fragment, | ||
$.escape_sequence | ||
), | ||
_interpolated_string_text_fragment: $ => token.immediate(prec(1, /[^{"\\\n]+/)), | ||
interpolated_verbatim_string_text: $ => choice( | ||
'{{', | ||
/[^{"]+/, | ||
$._interpolated_verbatim_string_text_fragment, | ||
'""' | ||
), | ||
_interpolated_verbatim_string_text_fragment: $ => token.immediate(prec(1, /[^{"]+/)), | ||
interpolation: $ => seq( | ||
@@ -1214,3 +1281,3 @@ '{', | ||
is_pattern_expression: $ => prec.left(PREC.EQUAL, seq( | ||
is_pattern_expression: $ => prec.left(PREC.REL, seq( | ||
field('expression', $._expression), | ||
@@ -1341,3 +1408,3 @@ 'is', | ||
range_expression: $ => prec.right(seq( | ||
range_expression: $ => prec.right(PREC.RANGE, seq( | ||
optional($._expression), | ||
@@ -1379,3 +1446,3 @@ '..', | ||
switch_expression: $ => prec(PREC.UNARY, seq( | ||
switch_expression: $ => prec(PREC.SWITCH, seq( | ||
$._expression, | ||
@@ -1410,3 +1477,4 @@ 'switch', | ||
with_expression: $ => seq($._expression, 'with', '{', optional($.with_initializer_expression), '}'), | ||
with_expression: $ => prec.left(PREC.WITH, | ||
seq($._expression, 'with', '{', optional($.with_initializer_expression), '}')), | ||
@@ -1486,4 +1554,3 @@ with_initializer_expression: $ => commaSep1($.simple_assignment_expression), | ||
['>=', PREC.REL], // greater_than_or_equal_expression | ||
['>', PREC.REL], // greater_than_expression | ||
['??', PREC.TERNARY], // coalesce_expression | ||
['>', PREC.REL] // greater_than_expression | ||
].map(([operator, precedence]) => | ||
@@ -1495,6 +1562,11 @@ prec.left(precedence, seq( | ||
)) | ||
) | ||
), | ||
prec.right(PREC.COALESCING, seq( | ||
field('left', $._expression), | ||
field('operator', '??'), // coalesce_expression | ||
field('right', $._expression) | ||
)) | ||
), | ||
as_expression: $ => prec.left(PREC.EQUAL, seq( | ||
as_expression: $ => prec.left(PREC.REL, seq( | ||
field('left', $._expression), | ||
@@ -1505,3 +1577,3 @@ field('operator', 'as'), | ||
is_expression: $ => prec.left(PREC.EQUAL, seq( | ||
is_expression: $ => prec.left(PREC.REL, seq( | ||
field('left', $._expression), | ||
@@ -1512,3 +1584,4 @@ field('operator', 'is'), | ||
_identifier_token: $ => token(seq(optional('@'), /[a-zA-Zα-ωΑ-Ωµ_][a-zA-Zα-ωΑ-Ωµ_0-9]*/)), // identifier_token in Roslyn | ||
// Unicode categories: L = Letter, Nl Letter_Number, = Nd = Decimal_Number, Pc = Connector_Punctuation, Cf = Format, Mn = Nonspacing_Mark, Mc = Spacing_Mark | ||
_identifier_token: $ => token(seq(optional('@'), /[\p{L}\p{Nl}_][\p{L}\p{Nl}\p{Nd}\p{Pc}\p{Cf}\p{Mn}\p{Mc}]*/)), | ||
identifier: $ => choice($._identifier_token, $._contextual_keywords), | ||
@@ -1594,3 +1667,3 @@ | ||
repeat(choice( | ||
token.immediate(prec(1, /[^"\\\n]+/)), | ||
$._string_literal_fragment, | ||
$.escape_sequence | ||
@@ -1601,2 +1674,4 @@ )), | ||
_string_literal_fragment: $ => token.immediate(prec(1, /[^"\\\n]+/)), | ||
verbatim_string_literal: $ => token(seq( | ||
@@ -1614,10 +1689,7 @@ '@"', | ||
comment: $ => token(choice( | ||
seq('//', /.*/), | ||
seq('//', /[^\n\r]*/), | ||
seq( | ||
'/*', | ||
repeat(choice( | ||
/[^*]/, | ||
/\*[^/]/ | ||
)), | ||
'*/' | ||
/[^*]*\*+([^/*][^*]*\*+)*/, | ||
'/' | ||
) | ||
@@ -1670,13 +1742,103 @@ )), | ||
preprocessor_call: $ => seq( | ||
$.preprocessor_directive, | ||
repeat(choice( | ||
$.identifier, | ||
$._literal, | ||
token(prec(-1, /[^\s]+/)) | ||
)), | ||
_preprocessor_call: $ => seq( | ||
$._preproc_directive_start, | ||
choice( | ||
$.nullable_directive, | ||
$.define_directive, | ||
$.undef_directive, | ||
$.if_directive, | ||
$.else_directive, | ||
$.elif_directive, | ||
$.endif_directive, | ||
$.region_directive, | ||
$.endregion_directive, | ||
$.error_directive, | ||
$.warning_directive, | ||
$.line_directive, | ||
$.pragma_directive | ||
), | ||
$._preproc_directive_end | ||
), | ||
preprocessor_directive: $ => /#[ \t]*[a-z]\w*/, | ||
_preproc_directive_start: $ => /#[ \t]*/, | ||
nullable_directive: $ => seq( | ||
'nullable', | ||
choice('disable', 'enable', 'restore'), | ||
optional(choice('annotations', 'warnings')) | ||
), | ||
// Preprocessor | ||
define_directive: $ => seq('define', $.identifier), | ||
undef_directive: $ => seq('undef', $.identifier), | ||
if_directive: $ => seq('if', $._preproc_expression), | ||
else_directive: $ => 'else', | ||
elif_directive: $ => seq('elif', $._preproc_expression), | ||
endif_directive: $ => 'endif', | ||
region_directive: $ => seq('region', optional($.preproc_message)), | ||
endregion_directive: $ => seq('endregion', optional($.preproc_message)), | ||
error_directive: $ => seq('error', $.preproc_message), | ||
warning_directive: $ => seq('warning', $.preproc_message), | ||
line_directive: $ => seq('line', | ||
choice( | ||
'default', | ||
'hidden', | ||
seq($.preproc_integer_literal, optional($.preproc_string_literal)) | ||
) | ||
), | ||
pragma_directive: $ => seq('pragma', | ||
choice( | ||
seq('warning', | ||
choice('disable', 'restore'), | ||
commaSep( | ||
choice( | ||
$.identifier, | ||
alias($.preproc_integer_literal, $.integer_literal), | ||
))), | ||
seq('checksum', $.preproc_string_literal, $.preproc_string_literal, $.preproc_string_literal) | ||
) | ||
), | ||
preproc_message: $ => /[^\n\r]+/, | ||
preproc_integer_literal: $ => /[0-9]+/, | ||
preproc_string_literal: $ => /"[^"]*"/, | ||
_preproc_expression: $ => choice( | ||
$.identifier, | ||
$.boolean_literal, | ||
alias($.preproc_integer_literal, $.integer_literal), | ||
alias($.preproc_string_literal, $.verbatim_string_literal), | ||
alias($.preproc_unary_expression, $.prefix_unary_expression), | ||
alias($.preproc_binary_expression, $.binary_expression), | ||
alias($.preproc_parenthesized_expression, $.parenthesized_expression) | ||
), | ||
preproc_parenthesized_expression: $ => seq( | ||
'(', | ||
$._preproc_expression, | ||
')' | ||
), | ||
preproc_unary_expression: $ => prec.left(PREC.UNARY, seq( | ||
field('operator', '!'), | ||
field('argument', $._preproc_expression) | ||
)), | ||
preproc_binary_expression: $ => { | ||
const table = [ | ||
['||', PREC.LOGOR], | ||
['&&', PREC.LOGAND], | ||
['==', PREC.EQUAL], | ||
['!=', PREC.EQUAL], | ||
]; | ||
return choice(...table.map(([operator, precedence]) => { | ||
return prec.left(precedence, seq( | ||
field('left', $._preproc_expression), | ||
field('operator', operator), | ||
field('right', $._preproc_expression) | ||
)) | ||
})); | ||
}, | ||
} | ||
@@ -1683,0 +1845,0 @@ }) |
{ | ||
"name": "tree-sitter-c-sharp", | ||
"version": "0.19.0", | ||
"version": "0.19.1", | ||
"description": "C# grammar for tree-sitter", | ||
@@ -8,5 +8,10 @@ "main": "bindings/node", | ||
"parser", | ||
"tree-sitter", | ||
"lexer" | ||
], | ||
"author": "Max Brunsfeld", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tree-sitter/tree-sitter-c-sharp.git" | ||
}, | ||
"author": "The Tree-Sitter C# Team", | ||
"license": "MIT", | ||
@@ -17,3 +22,3 @@ "dependencies": { | ||
"devDependencies": { | ||
"tree-sitter-cli": "^0.19.1" | ||
"tree-sitter-cli": "^0.19.4" | ||
}, | ||
@@ -20,0 +25,0 @@ "scripts": { |
@@ -1,7 +0,6 @@ | ||
tree-sitter-c-sharp | ||
=========================== | ||
# tree-sitter-c-sharp | ||
[![Build Status](https://github.com/tree-sitter/tree-sitter-c-sharp/workflows/build/badge.svg)](https://github.com/tree-sitter/tree-sitter-c-sharp/actions?query=workflow%3Abuild) | ||
C# grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter) based on an export of the Roslyn grammar export with various changes in order to: | ||
C# grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter) based upon the Roslyn grammar with changes in order to: | ||
@@ -18,42 +17,4 @@ - Deal with differences between the parsing technologies | ||
- [ ] `async` and `await` cannot be used as identifiers | ||
- [ ] `async`, `var` and `await` cannot be used as identifiers | ||
#### C# 7.0 (complete) | ||
- [x] Tuples | ||
- [x] Discards | ||
- [x] Basic pattern matching | ||
- [x] Recursive pattern matching | ||
- [x] Ref locals and return | ||
- [x] Local function statements | ||
- [x] Expression bodied constructors | ||
- [x] Expression bodied destructors/finalizers | ||
- [x] Throw expressions | ||
- [x] Binary and `_` literal support | ||
#### C# 7.1 (complete) | ||
- [x] `async` main method | ||
- [x] Default literals (as `default_expression`) | ||
- [x] Inferred tuple element names | ||
- [x] Generic type pattern matching | ||
#### C# 7.2 (complete) | ||
- [x] `in` parameter modifiers | ||
- [x] `ref readonly` method returns | ||
- [x] `readonly struct` | ||
- [x] `ref struct` | ||
- [x] Non-named trailing arguments | ||
- [x] `_` leading binary and hex literals | ||
- [x] `private protected` modifier | ||
- [x] Conditional `ref` expressions | ||
#### C# 7.3 (complete) | ||
- [x] `stackalloc` array initializers | ||
- [x] `unmanaged` generic type parameter constraint | ||
- [x] Attributes attached to auto property backing fields | ||
- [x] `out` support for parameters on initializers, constructors etc. | ||
#### C# 8.0 (complete) | ||
@@ -70,2 +31,3 @@ | ||
- [x] Null-coalescing assignment | ||
- [x] using statement without braces | ||
@@ -94,6 +56,17 @@ #### C# 9.0 (complete) | ||
#### C# 10.0 | ||
- [x] global using directives | ||
- [x] File-scoped namespace declaration | ||
- [x] Extended property patterns | ||
- [x] Allow const interpolated strings | ||
- [x] Record types can seal ToString() | ||
- [x] Allow both assignment and declaration in the same deconstruction | ||
- [x] Allow AsyncMethodBuilder attribute on methods | ||
- [x] Record structs | ||
### References | ||
* [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) | ||
* [SharpLab](https://sharplab.io) (web-based syntax tree playground based on Roslyn) | ||
- [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) | ||
- [SharpLab](https://sharplab.io) (web-based syntax tree playground based on Roslyn) |
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 |
console.log("Trying to require index.js in JavaScript"); | ||
require('.') | ||
console.log("Require successfull"); |
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 not supported yet
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 not supported yet
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 not supported yet
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
22797871
32
18383
0
70
2