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.1.0 to 0.2.0

samples/hello

151

grammar.js
const PREC = {
primary: 12,
unary: 11,

@@ -32,2 +33,3 @@ multiplicative: 10,

$._expression_statement,
$._control_flow_statement,
$.empty_statement

@@ -41,2 +43,11 @@ ),

_control_flow_statement: $ => choice(
$.if_expression,
$.if_let_expression,
$.match_expression,
$.while_expression,
$.loop_expression,
$.for_expression
),
_item: $ => choice(

@@ -72,3 +83,7 @@ $.function_item

_pattern: $ => $.identifier,
_pattern: $ => prec.left(choice(
$._expression,
seq('(', commaSep($._expression), ')'),
'_'
)),

@@ -89,5 +104,6 @@ type_expression: $ => choice(

_expression: $ => choice(
_expression: $ => prec(PREC.primary, choice(
$.unary_expression,
$.binary_expression,
$.range_expression,
$.call_expression,

@@ -97,7 +113,23 @@ $.return_expression,

$.identifier,
$.array_expression,
$.if_expression,
$.if_let_expression,
$.match_expression,
$.while_expression,
$.loop_expression,
$.for_expression,
$.break_expression,
$.continue_expression,
seq('(', $._expression, ')')
),
)),
range_expression: $ => prec.left(PREC.range, choice(
seq($._expression, '..', $._expression),
seq($._expression, '..'),
seq('..', $._expression),
'..'
)),
unary_expression: $ => prec(PREC.unary, seq(
token(choice('-', '*', '!')),
choice('-', '*', '!'),
$._expression

@@ -107,6 +139,6 @@ )),

binary_expression: $ => choice(
prec.left(PREC.multiplicative, seq($._expression, token(choice('*', '/', '%')), $._expression)),
prec.left(PREC.additive, seq($._expression, token(choice('+', '-')), $._expression)),
prec.left(PREC.comparative, seq($._expression, token(choice('==', '!=', '<', '<=', '>', '>=')), $._expression)),
prec.left(PREC.shift, seq($._expression, token(choice('<<', '>>')), $._expression)),
prec.left(PREC.multiplicative, seq($._expression, choice('*', '/', '%'), $._expression)),
prec.left(PREC.additive, seq($._expression, choice('+', '-'), $._expression)),
prec.left(PREC.comparative, seq($._expression, choice('==', '!=', '<', '<=', '>', '>='), $._expression)),
prec.left(PREC.shift, seq($._expression, choice('<<', '>>'), $._expression)),
prec.left(PREC.and, seq($._expression, '&&', $._expression)),

@@ -134,2 +166,84 @@ prec.left(PREC.or, seq($._expression, '||', $._expression)),

array_expression: $ => seq(
'[',
choice(
seq($._expression, ';', $._expression),
commaSep($._expression)
),
']'
),
if_expression: $ => seq(
'if',
$._expression,
$.block,
optional($.else_tail)
),
if_let_expression: $ => seq(
'if',
'let',
$._pattern,
'=',
$._expression,
$.block,
optional($.else_tail)
),
else_tail: $ => seq(
'else',
choice($.block, $.if_expression, $.if_let_expression)
),
match_expression: $ => seq(
'match',
$._expression,
'{',
optional(repeat($.match_arm)),
'}'
),
match_arm: $ => seq(
$.match_pattern,
'=>',
choice(
seq($._expression, ','),
$.block
)
),
match_pattern: $ => seq(
$._pattern,
optional(repeat(seq('|', $._pattern))),
optional(seq('if', $._expression))
),
while_expression: $ => seq(
optional(seq($.loop_label, ':')),
'while',
$._expression,
$.block
),
loop_expression: $ => seq(
optional(seq($.loop_label, ':')),
'loop',
$.block
),
for_expression: $ => seq(
optional(seq($.loop_label, ':')),
'for',
$._pattern,
'in',
$._expression,
$.block
),
loop_label: $ => seq('\'', $.identifier),
break_expression: $ => seq('break', optional($.loop_label)),
continue_expression: $ => seq('continue', optional($.loop_label)),
_literal: $ => choice(

@@ -172,3 +286,3 @@ $.string_literal,

return token(choice(
return prec.right(choice(
integer_literal,

@@ -184,2 +298,3 @@ floating_point_literal

'\\"',
'\\\n',
/[^"]/

@@ -209,10 +324,8 @@ ))),

return token(seq(
return seq(
'\\', choice('n', 'r', 't', '0', '\\', seq('x', hex_digit, hex_digit))
))
)
},
boolean_literal: $ => token(choice(
'true', 'false'
)),
boolean_literal: $ => choice('true', 'false'),

@@ -236,4 +349,12 @@ comment: $ => choice(

identifier: $ => (/[\a_$][\a\d_$]*/),
identifier: $ => {
const letter = /[a-zA-Z_]/
const digit = /[0-9]/
return token(seq(
letter,
optional(repeat(choice(letter, digit)))
))
},
parameters: $ => seq(

@@ -240,0 +361,0 @@ '(',

2

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,10 +0,14 @@

## tree-sitter-rust
# tree-sitter-rust
[![Build Status](https://travis-ci.org/MaximSokolov/tree-sitter-rust.svg?branch=master)](https://travis-ci.org/MaximSokolov/tree-sitter-rust)
Rust grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
#### References
### References
* [The Rust Reference](https://doc.rust-lang.org/reference.html)
* [The Rust Grammar Reference.](https://doc.rust-lang.org/grammar.html) It provides chapters that formally define the language grammar.
* [The Rust Grammar Reference](https://doc.rust-lang.org/grammar.html)
* [The Rust Reference.](https://doc.rust-lang.org/reference.html) While Rust does not have a specification, the reference tries to describe its working in detail. It tends to be out of date.
* [Syntax Index.](https://doc.rust-lang.org/book/syntax-index.html) This appendix from The Book contains examples of all syntax in Rust cross-referenced with the section of The Book that describes it.

@@ -71,2 +71,6 @@ {

"type": "SYMBOL",
"name": "_control_flow_statement"
},
{
"type": "SYMBOL",
"name": "empty_statement"

@@ -89,2 +93,31 @@ }

},
"_control_flow_statement": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "if_expression"
},
{
"type": "SYMBOL",
"name": "if_let_expression"
},
{
"type": "SYMBOL",
"name": "match_expression"
},
{
"type": "SYMBOL",
"name": "while_expression"
},
{
"type": "SYMBOL",
"name": "loop_expression"
},
{
"type": "SYMBOL",
"name": "for_expression"
}
]
},
"_item": {

@@ -218,4 +251,63 @@ "type": "CHOICE",

"_pattern": {
"type": "SYMBOL",
"name": "identifier"
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
{
"type": "STRING",
"value": "_"
}
]
}
},

@@ -311,47 +403,147 @@ "type_expression": {

"_expression": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "unary_expression"
},
{
"type": "SYMBOL",
"name": "binary_expression"
},
{
"type": "SYMBOL",
"name": "call_expression"
},
{
"type": "SYMBOL",
"name": "return_expression"
},
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
"type": "PREC",
"value": 12,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "unary_expression"
},
{
"type": "SYMBOL",
"name": "binary_expression"
},
{
"type": "SYMBOL",
"name": "range_expression"
},
{
"type": "SYMBOL",
"name": "call_expression"
},
{
"type": "SYMBOL",
"name": "return_expression"
},
{
"type": "SYMBOL",
"name": "_literal"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "array_expression"
},
{
"type": "SYMBOL",
"name": "if_expression"
},
{
"type": "SYMBOL",
"name": "if_let_expression"
},
{
"type": "SYMBOL",
"name": "match_expression"
},
{
"type": "SYMBOL",
"name": "while_expression"
},
{
"type": "SYMBOL",
"name": "loop_expression"
},
{
"type": "SYMBOL",
"name": "for_expression"
},
{
"type": "SYMBOL",
"name": "break_expression"
},
{
"type": "SYMBOL",
"name": "continue_expression"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
}
},
"range_expression": {
"type": "PREC_LEFT",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ".."
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ".."
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ".."
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
{
"type": "STRING",
"value": ".."
}
]
}
},
"unary_expression": {

@@ -364,20 +556,17 @@ "type": "PREC",

{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "!"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "-"
},
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "!"
}
]
},

@@ -405,20 +594,17 @@ {

{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "%"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "*"
},
{
"type": "STRING",
"value": "/"
},
{
"type": "STRING",
"value": "%"
}
]
},

@@ -443,16 +629,13 @@ {

{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "-"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "+"
},
{
"type": "STRING",
"value": "-"
}
]
},

@@ -477,32 +660,29 @@ {

{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=="
},
{
"type": "STRING",
"value": "!="
},
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": "<="
},
{
"type": "STRING",
"value": ">"
},
{
"type": "STRING",
"value": ">="
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "=="
},
{
"type": "STRING",
"value": "!="
},
{
"type": "STRING",
"value": "<"
},
{
"type": "STRING",
"value": "<="
},
{
"type": "STRING",
"value": ">"
},
{
"type": "STRING",
"value": ">="
}
]
},

@@ -527,16 +707,13 @@ {

{
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<<"
},
{
"type": "STRING",
"value": ">>"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "<<"
},
{
"type": "STRING",
"value": ">>"
}
]
},

@@ -703,2 +880,464 @@ {

},
"array_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
"if_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "else_tail"
},
{
"type": "BLANK"
}
]
}
]
},
"if_let_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "STRING",
"value": "let"
},
{
"type": "SYMBOL",
"name": "_pattern"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "else_tail"
},
{
"type": "BLANK"
}
]
}
]
},
"else_tail": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "else"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "SYMBOL",
"name": "if_expression"
},
{
"type": "SYMBOL",
"name": "if_let_expression"
}
]
}
]
},
"match_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "match"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "match_arm"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
"match_arm": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "match_pattern"
},
{
"type": "STRING",
"value": "=>"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ","
}
]
},
{
"type": "SYMBOL",
"name": "block"
}
]
}
]
},
"match_pattern": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_pattern"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "SYMBOL",
"name": "_pattern"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "if"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
},
{
"type": "BLANK"
}
]
}
]
},
"while_expression": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "loop_label"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "while"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"loop_expression": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "loop_label"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "loop"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"for_expression": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "loop_label"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "for"
},
{
"type": "SYMBOL",
"name": "_pattern"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "block"
}
]
},
"loop_label": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
"break_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "break"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "loop_label"
},
{
"type": "BLANK"
}
]
}
]
},
"continue_expression": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "continue"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "loop_label"
},
{
"type": "BLANK"
}
]
}
]
},
"_literal": {

@@ -730,3 +1369,4 @@ "type": "CHOICE",

"number_literal": {
"type": "TOKEN",
"type": "PREC_RIGHT",
"value": 0,
"content": {

@@ -1078,2 +1718,6 @@ "type": "CHOICE",

{
"type": "STRING",
"value": "\\\n"
},
{
"type": "PATTERN",

@@ -1203,70 +1847,64 @@ "value": "[^\"]"

"byte_escape": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "n"
},
{
"type": "STRING",
"value": "r"
},
{
"type": "STRING",
"value": "t"
},
{
"type": "STRING",
"value": "0"
},
{
"type": "STRING",
"value": "\\"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "x"
},
{
"type": "PATTERN",
"value": "[0-9a-fA-F]"
},
{
"type": "PATTERN",
"value": "[0-9a-fA-F]"
}
]
}
]
}
]
}
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "n"
},
{
"type": "STRING",
"value": "r"
},
{
"type": "STRING",
"value": "t"
},
{
"type": "STRING",
"value": "0"
},
{
"type": "STRING",
"value": "\\"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "x"
},
{
"type": "PATTERN",
"value": "[0-9a-fA-F]"
},
{
"type": "PATTERN",
"value": "[0-9a-fA-F]"
}
]
}
]
}
]
},
"boolean_literal": {
"type": "TOKEN",
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "true"
},
{
"type": "STRING",
"value": "false"
}
]
}
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "true"
},
{
"type": "STRING",
"value": "false"
}
]
},

@@ -1323,4 +1961,36 @@ "comment": {

"identifier": {
"type": "PATTERN",
"value": "[\\a_$][\\a\\d_$]*"
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[a-zA-Z_]"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[a-zA-Z_]"
},
{
"type": "PATTERN",
"value": "[0-9]"
}
]
}
},
{
"type": "BLANK"
}
]
}
]
}
},

@@ -1327,0 +1997,0 @@ "parameters": {

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc