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

tree-sitter-rust

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter-rust - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

.eslintrc.json

304

grammar.js
const PREC = {
primary: 12,
method_call: 14,
field: 13,
control_flow_statement: 12,
unary: 11,

@@ -15,3 +17,3 @@ multiplicative: 10,

assign: 0
};
}

@@ -27,6 +29,4 @@ const integer_type = choice('u8', 'i8', 'u16', 'i16', 'u32', 'i32', 'u64', 'i64', 'isize', 'usize')

rules: {
source_file: $ => repeat($._statement_list),
source_file: $ => repeat($._statement),
_statement_list: $ => prec.left(sepTrailing(choice('\n', ';'), $._statement_list, $._statement)),
_statement: $ => choice(

@@ -36,11 +36,37 @@ $._declaration_statement,

$._control_flow_statement,
$.macro_invocation,
$.empty_statement
),
macro_invocation: $ => prec.right(seq(
$.macro_name,
$.macro_arguments,
optional(';')
)),
macro_name: $abc => /[a-zA-Z_][\w]+!/,
macro_arguments: $ => {
const args = choice(
sepBy(',', $._expression),
sepBy(';', $._expression)
)
return choice(
seq('{', args, '}'),
seq('(', args, ')'),
seq('[', args, ']')
)
},
_declaration_statement: $ => choice(
$._item,
$.let_declaration
$.let_declaration,
$.use_declaration,
$.extern_crate_declaration,
$.const_item,
$.static_item
),
_control_flow_statement: $ => choice(
_control_flow_statement: $ => prec(PREC.control_flow_statement, choice(
$.if_expression,

@@ -52,14 +78,96 @@ $.if_let_expression,

$.for_expression
),
)),
_item: $ => choice(
$.mod_item,
$.struct_item,
$.type_item,
$.function_item
),
mod_item: $ => seq(
optional($.visibility_modifier),
'mod',
$.identifier,
choice(
';',
seq(
'{',
repeat(choice(
$._item,
$.use_declaration,
$.extern_crate_declaration
)),
'}'
)
)
),
struct_item: $ => seq(
optional($.visibility_modifier),
'struct',
$.identifier,
choice(
';',
seq(
'{',
sepBy(',', seq($.identifier, ':', $.type_expression)),
'}'
),
seq(
'(',
sepBy(',', $.type_expression),
')',
';'
)
)
),
extern_crate_declaration: $ => seq(
'extern',
'crate',
choice(
$.identifier,
seq($.identifier, 'as', $.identifier)
),
';'
),
const_item: $ => seq(
optional($.visibility_modifier),
'const',
$.identifier,
':',
$.type_expression,
'=',
$._expression,
';'
),
static_item: $ => seq(
optional($.visibility_modifier),
'static',
$.identifier,
':',
$.type_expression,
'=',
$._expression,
';'
),
type_item: $ => seq(
'type',
$.identifier,
'=',
$.type_expression,
';'
),
function_item: $ => seq(
optional($.visibility_modifier),
'fn',
$.identifier,
$.parameters,
optional(choice
(seq('->', $.type_expression)),
optional(choice(
seq('->', $.type_expression)),
'!'

@@ -85,13 +193,48 @@ ),

_pattern: $ => prec.left(choice(
$._expression,
seq('(', commaSep($._expression), ')'),
use_declaration: $ => seq(
optional($.visibility_modifier),
'use',
seq(
repeat($.path),
choice(
choice(
$.identifier,
seq($.identifier, 'as', $.identifier)
),
seq(
'{',
sepBy(',', choice(
$.identifier,
$.self,
seq($.identifier, 'as', $.identifier)
)),
'}'
),
'*'
)
),
';'
),
_pattern: $ => choice(
$._literal,
$.identifier,
seq(
'(',
sepBy(',', choice($._literal, $.identifier)),
')'
),
'_'
)),
),
type_expression: $ => choice(
$.boolean_literal,
integer_type,
float_type,
$.identifier
type_expression: $ => seq(
optional('&'),
choice(
integer_type,
float_type,
$.identifier,
'bool',
'str',
'char'
)
),

@@ -106,3 +249,8 @@

_expression: $ => prec(PREC.primary, choice(
_expression: $ => choice(
$._no_struct_literal_expr,
$.struct_expression
),
_no_struct_literal_expr: $ => prec.left(choice(
$.unary_expression,

@@ -115,3 +263,7 @@ $.binary_expression,

$.identifier,
$.method_call_expression,
$._field_expression,
$.array_expression,
$.tuple_expression,
$.unit_expression,
$.if_expression,

@@ -125,2 +277,3 @@ $.if_let_expression,

$.continue_expression,
$._index_expression,
seq('(', $._expression, ')')

@@ -137,3 +290,3 @@ )),

unary_expression: $ => prec(PREC.unary, seq(
choice('-', '*', '!'),
choice('-', '*', '!', '&', '&mut'),
$._expression

@@ -149,3 +302,8 @@ )),

prec.left(PREC.or, seq($._expression, '||', $._expression)),
$.assignment_expression
prec.left(PREC.bitor, seq($._expression, '|', $._expression)),
prec.left(PREC.bitand, seq($._expression, '&', $._expression)),
prec.left(PREC.bitxor, seq($._expression, '^', $._expression)),
$.assignment_expression,
$.compound_assignment_expr,
$.type_cast_expression
),

@@ -155,2 +313,12 @@

compound_assignment_expr: $ => prec.left(PREC.assign, seq(
$._expression,
choice('+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<=', '>>='),
$._expression
)),
type_cast_expression: $ => seq(
$._expression, 'as', $.type_expression
),
return_expression: $ => prec.left(seq(

@@ -167,3 +335,3 @@ 'return', optional($._expression))

'(',
commaSep($._expression),
sepBy(',', $._expression),
')'

@@ -176,3 +344,3 @@ ),

seq($._expression, ';', $._expression),
commaSep($._expression)
sepBy(',' ,$._expression)
),

@@ -182,5 +350,28 @@ ']'

tuple_expression: $ => seq(
'(',
seq($._expression, ','),
repeat(seq($._expression, ',')),
optional($._expression),
')'
),
unit_expression: $ => '()',
struct_expression: $ => seq(
repeat($.path),
$.identifier,
seq(
'{',
sepBy(',', choice(
$.identifier,
seq($.identifier, ':', $._expression)
)),
'}'
)
),
if_expression: $ => seq(
'if',
$._expression,
$._no_struct_literal_expr,
$.block,

@@ -207,5 +398,5 @@ optional($.else_tail)

'match',
$._expression,
$._no_struct_literal_expr,
'{',
optional(repeat($.match_arm)),
repeat($.match_arm),
'}'

@@ -225,3 +416,3 @@ ),

$._pattern,
optional(repeat(seq('|', $._pattern))),
repeat(seq('|', $._pattern)),
optional(seq('if', $._expression))

@@ -233,3 +424,3 @@ ),

'while',
$._expression,
$._no_struct_literal_expr,
$.block

@@ -249,3 +440,3 @@ ),

'in',
$._expression,
$._no_struct_literal_expr,
$.block

@@ -260,2 +451,4 @@ ),

_index_expression: $ => seq($._expression, '[', $._expression, ']'),
_literal: $ => choice(

@@ -306,3 +499,3 @@ $.string_literal,

'"',
optional(repeat(choice(
repeat(choice(
$.byte_escape,

@@ -312,3 +505,3 @@ '\\"',

/[^"]/
))),
)),
'"'

@@ -334,3 +527,3 @@ ),

byte_escape: $ => {
const hex_digit = /[0-9a-fA-F]/;
const hex_digit = /[0-9a-fA-F]/

@@ -361,15 +554,11 @@ return seq(

identifier: $ => {
const letter = /[a-zA-Z_]/
const digit = /[0-9]/
identifier: $ => /[a-zA-Z_][\w]*/,
return token(seq(
letter,
optional(repeat(choice(letter, digit)))
))
},
_field_expression: $ => prec(PREC.field, seq($._expression, '.', $.identifier)),
method_call_expression: $ => prec(PREC.method_call, seq($._expression, '.', $.identifier, $.arguments)),
parameters: $ => seq(
'(',
commaSep(seq($.identifier, ':', $.type_expression)),
sepBy(',', seq($.identifier, ':', $.type_expression)),
')'

@@ -380,23 +569,28 @@ ),

'{',
choice(
optional($._statement_list),
optional($._expression)
),
repeat($._statement),
optional($._expression),
'}'
),
path: $ => seq(
choice($.identifier, $.self),
'::'
),
visibility_modifier: $ => 'pub',
self: $ => 'self',
super: $ => 'super',
empty_statement: $ => ';'
}
});
})
function sepTrailing (separator, recurSymbol, rule) {
return choice(rule, seq(rule, separator, optional(recurSymbol)))
function sepBy1(sep, rule) {
return seq(rule, repeat(seq(sep, rule)))
}
function commaSep1 (rule) {
return seq(rule, repeat(seq(',', rule)));
function sepBy(sep, rule) {
return optional(sepBy1(sep, rule))
}
function commaSep (rule) {
return optional(commaSep1(rule));
}

8

package.json
{
"name": "tree-sitter-rust",
"version": "0.2.0",
"version": "0.3.0",
"description": "Rust grammar for node-tree-sitter",

@@ -16,8 +16,10 @@ "main": "index.js",

"devDependencies": {
"tree-sitter-cli": "^0.5.0"
"tree-sitter-cli": "^0.5.0",
"eslint": "^3.19.0"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",
"test": "tree-sitter test"
"test": "npm run lint && tree-sitter test",
"lint": "eslint ./grammar.js"
}
}

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