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

tree-sitter-solidity

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tree-sitter-solidity - npm Package Compare versions

Comparing version 1.0.12 to 1.1.0

queries/tags.scm

33

bindings/node/index.js
try {
module.exports = require("../../build/Release/tree_sitter_solidity_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
module.exports = require("../../build/Release/tree_sitter_solidity_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_solidity_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
try {
module.exports = require("../../build/Debug/tree_sitter_solidity_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
throw error1
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

@@ -6,3 +6,3 @@ // Precedence is used by the parser to determine which rule to apply when there are two rules that can be applied.

STRING: 2,
COMMA: -1,

@@ -28,3 +28,3 @@ OBJECT: -1,

NEW: 13,
MEMBER: 14
MEMBER: 1
}

@@ -43,3 +43,3 @@

],
// The word token allows tree-sitter to appropriately handle scenario's where an identifier includes a keyword.

@@ -51,2 +51,15 @@ // Documentation: https://tree-sitter.github.io/tree-sitter/creating-parsers#keywords

[$._primary_expression, $.type_name],
[$.member_expression, $.type_name],
[$.identifier, $.type_name],
[$._primary_expression, $._identifier_path],
[$._primary_expression, $.member_expression, $._identifier_path],
[$.member_expression, $._identifier_path],
[$.member_expression, $.array_access],
[$.member_expression, $._array_type],
[$.array_access, $._array_type],
[$._call_arguments, $.tuple_expression],
[$._parameter_list, $.fallback_receive_definition],

@@ -56,6 +69,14 @@ [$._primary_expression, $.type_cast_expression],

[$._yul_expression, $.yul_assignment],
[$.pragma_value, $._solidity],
[$.variable_declaration_tuple, $.tuple_expression],
[$._decimal_number, $._hex_number],
[$._yul_statement, $.yul_assignment],
[$.yul_label, $.yul_identifier],
[$.fallback_receive_definition, $._function_type]
],
rules: {
// -- [ Program ] --
// -- [ Program ] --
source_file: $ => seq(

@@ -65,3 +86,3 @@ repeat($._source_unit),

// -- [ Source Element ] --
// -- [ Source Element ] --
_source_unit: $ => choice(

@@ -72,3 +93,3 @@ $._directive,

// -- [ Directives ] --
// -- [ Directives ] --
_directive: $ => choice(

@@ -82,13 +103,25 @@ $.pragma_directive,

"pragma",
"solidity",
repeat(field("version_constraint", $._pragma_version_constraint)),
choice($.solidity_pragma_token, $.any_pragma_token),
$._semicolon,
),
solidity_pragma_token: $ => prec(10, seq(
$._solidity,
repeat(seq(field("version_constraint", $._pragma_version_constraint), optional(choice("||", "-")))),
)),
any_pragma_token: $ => seq(
$.identifier,
$.pragma_value,
),
_solidity: $ => prec(1, "solidity"),
pragma_value: $ => prec(0, /[^;]+/),
_pragma_version_constraint: $ => seq(
optional($._solidity_version_comparison_operator),
$._solidity_version,
optional($.solidity_version_comparison_operator),
$.solidity_version,
),
_solidity_version: $ => /\d+(.\d+(.\d+)?)?/,
_solidity_version_comparison_operator: $ => choice("<=", "<", "^", ">", ">=", "~", "="),
solidity_version: $ => /"?\.? ?(\d|\*)+(\. ?(\d|\*)+ ?(\.(\d|\*)+)?)?"?/,
solidity_version_comparison_operator: $ => choice("<=", "<", "^", ">", ">=", "~", "="),

@@ -118,5 +151,5 @@ // Import

),
_single_import: $ => seq(
"*",
choice("*", $.identifier),
optional(

@@ -129,3 +162,3 @@ seq(

),
_multiple_import: $ => seq(

@@ -147,6 +180,7 @@ '{',

// -- [ Declarations ] --
// -- [ Declarations ] --
_declaration: $ => choice(
$.contract_declaration,
$.interface_declaration,
$.error_declaration,
$.library_declaration,

@@ -157,4 +191,7 @@ $.struct_declaration,

$.constant_variable_declaration,
$.user_defined_type_definition,
),
user_defined_type_definition: $ => seq('type', $.identifier, 'is', $.primitive_type, $._semicolon),
constant_variable_declaration: $ => seq(

@@ -164,7 +201,7 @@ field("type", $.type_name),

field("name", $.identifier),
'=',
'=',
field("value", $._expression),
$._semicolon
),
// Contract Declarations

@@ -179,2 +216,5 @@ contract_declaration: $ => seq(

error_declaration: $ => seq('error', $.identifier, '(', commaSep($.error_parameter), ')', $._semicolon),
error_parameter: $ => seq($.type_name, optional($.identifier)),
interface_declaration: $ => seq(

@@ -194,3 +234,3 @@ 'interface',

_class_heritage: $ => seq(
"is",
"is",
commaSep1($.inheritance_specifier)

@@ -200,3 +240,3 @@ ),

inheritance_specifier: $ => seq(
field("ancestor", $._user_defined_type),
field("ancestor", $.user_defined_type),
optional(field("ancestor_arguments", $._call_arguments)),

@@ -207,20 +247,24 @@ ),

"{",
repeat(choice(
$.function_definition,
$.modifier_definition,
$.state_variable_declaration,
$.struct_declaration,
$.enum_declaration,
$.event_definition,
$.using_directive,
$.constructor_definition,
$.fallback_receive_definition,
)),
repeat($._contract_member),
"}",
),
_contract_member: $ => choice(
$.function_definition,
$.modifier_definition,
$.error_declaration,
$.state_variable_declaration,
$.struct_declaration,
$.enum_declaration,
$.event_definition,
$.using_directive,
$.constructor_definition,
$.fallback_receive_definition,
$.user_defined_type_definition,
),
struct_declaration: $ => seq(
'struct',
field("struct_name", $.identifier),
'{',
'{',
repeat1($.struct_member),

@@ -243,4 +287,4 @@ '}',

),
event_definition: $ => seq(

@@ -263,4 +307,4 @@ 'event', field('name', $.identifier), $._event_parameter_list , optional('anonymous'), $._semicolon

using_directive: $ => seq(
'using',
alias($._user_defined_type, $.type_alias),
'using',
alias($.user_defined_type, $.type_alias),
'for',

@@ -287,3 +331,4 @@ field("source", choice($.any_source_type, $.type_name)),

$.emit_statement,
$.assembly_statement
$.assembly_statement,
$.revert_statement,
),

@@ -311,5 +356,8 @@

$.yul_continue,
$.yul_function_definition
$.yul_function_definition,
$.yul_label,
$._yul_literal
),
yul_label: $ => seq($.identifier, ":"),
yul_leave: $ => "leave",

@@ -319,6 +367,6 @@ yul_break: $ => "break",

yul_identifier: $ => /[a-zA-Z$_]+/,
yul_identifier: $ => $.identifier, ///[a-zA-Z$_]+/,
_yul_expression: $ => choice($.yul_path, $.yul_function_call, $._yul_literal),
yul_path: $ => prec.left(dotSep1($.yul_identifier)),
// -- Yul Literals --

@@ -344,11 +392,15 @@ _yul_literal: $ => choice(

seq('(', commaSep1($.yul_identifier), ')')
)),
)),
optional(seq(':=', field("right", $.yul_function_call)))),
)),
_yul_assignment_operator: $ => choice(":=", seq(":", "=")),
yul_assignment: $ => prec.left(PREC.ASSIGN, choice(
seq($.yul_path, ':=', $._yul_expression),
seq(commaSep1($.yul_path), optional(seq(':=', $.yul_function_call))),
seq($.yul_path, $._yul_assignment_operator, $._yul_expression),
seq(commaSep1($.yul_path), optional(seq($._yul_assignment_operator, $.yul_function_call))),
)),
yul_function_call: $ => seq(
field("function", choice($.yul_identifier, $.yul_evm_builtin)), '(', commaSep($._yul_expression), ')'
yul_function_call: $ => choice(
seq(
field("function", choice($.yul_identifier, $.yul_evm_builtin)), '(', commaSep($._yul_expression), ')'
),
field("function", $.yul_evm_builtin)
),

@@ -449,4 +501,5 @@ yul_if_statement: $ => seq('if', $._yul_expression, $.yul_block),

// -- [ Statements ] --
block_statement: $ => seq('{', repeat($._statement), "}"),
variable_declaration_statement: $ => prec(3,seq(
_unchecked: $ => "unchecked",
block_statement: $ => seq(optional($._unchecked), '{', repeat($._statement), "}"),
variable_declaration_statement: $ => prec(1,seq(
choice(

@@ -459,22 +512,2 @@ seq($.variable_declaration, optional(seq('=', $._expression))),

// var_variable_decartion: $ => prec.left(seq(
// 'var',
// choice(
// $.identifier,
// seq(
// '(',
// optional($.identifier),
// repeat(
// seq(
// ',',
// optional($.identifier),
// )
// ),
// ')')
// ),
// '=',
// $._expression,
// $._semicolon,
// )),
variable_declaration: $ => seq(

@@ -488,8 +521,8 @@ $.type_name,

seq(
'(',
commaSep($.variable_declaration),
'(',
commaSep(optional($.variable_declaration)),
')'
),
seq('var',
'(',
'(',
optional($.identifier),

@@ -508,8 +541,8 @@ repeat(

if_statement: $ => prec.left(seq(
if_statement: $ => prec.right(seq(
'if', '(',$._expression, ')', $._statement, optional(seq('else', $._statement)),
)),
for_statement: $ => seq(
'for', '(',
'for', '(',
choice($.variable_declaration_statement, $.expression_statement, $._semicolon),

@@ -525,7 +558,16 @@ choice($.expression_statement, $._semicolon),

do_while_statement: $ => seq(
'do', $._statement, 'while', '(',$._expression, ')',
),
'do', $._statement, 'while', '(',$._expression, ')', $._semicolon,
),
continue_statement: $ => seq('continue', $._semicolon),
break_statement: $ => seq('break', $._semicolon),
revert_statement: $ => seq(
'revert',
optional(seq(
field("error", optional($._expression)),
$._call_arguments,
)),
$._semicolon
),
try_statement: $ => seq(

@@ -547,4 +589,4 @@ 'try', $._expression, optional(seq('returns', $._parameter_list)), $.block_statement, repeat1($.catch_clause),

// -- [ Definitions ] --
// -- [ Definitions ] --
// Definitions

@@ -586,3 +628,3 @@ state_variable_declaration: $ => seq(

'(',
commaSep1($._user_defined_type),
commaSep1($.user_defined_type),
')',

@@ -616,12 +658,13 @@ ))

choice(seq(
optional("function"),
choice('fallback', 'receive'),
// optional("function"),
choice('fallback', 'receive', 'function'),
),
"function"
),
'(', ')',
// FIXME: We use repeat to allow for unorderedness. However, this means that the parser
// #todo: only fallback should get arguments
$._parameter_list,
// FIXME: We use repeat to allow for unorderedness. However, this means that the parser
// accepts more than just the solidity language. The same problem exists for other definition rules.
repeat(choice(
$.visibility,
$.visibility,
$.modifier_invocation,

@@ -650,3 +693,3 @@ $.state_mutability,

return_type_definition: $ => seq(
return_type_definition: $ => seq(
'returns',

@@ -657,4 +700,4 @@ $._parameter_list,

virtual: $ => "virtual",
modifier_invocation: $ => seq($.identifier, optional($._call_arguments)),
modifier_invocation: $ => seq($._identifier_path, optional($._call_arguments)),
_call_arguments: $ => prec(4,

@@ -665,3 +708,3 @@ seq(

$._expression,
seq("{", commaSep($.identifier, ":", $._expression), "}"),
seq("{", commaSep(seq($.identifier, ":", $._expression)), "}"),
)),

@@ -673,4 +716,3 @@ ')'

function_body: $ => seq(
"{",
// TODO: make sure this is correct
"{",
repeat($._statement),

@@ -695,3 +737,2 @@ "}",

// TODO: make primary expression anonymous
_primary_expression: $ => choice(

@@ -705,3 +746,3 @@ $.parenthesized_expression,

$.augmented_assignment_expression,
$._user_defined_type,
$.user_defined_type,
$.tuple_expression,

@@ -723,3 +764,3 @@ $.inline_array_expression,

tuple_expression: $ => prec(1, seq(
'(',
'(',
optional($._expression),

@@ -736,3 +777,3 @@ repeat(

inline_array_expression: $ => seq(
'[',
'[',
commaSep($._expression),

@@ -798,3 +839,3 @@ ']'

member_expression: $ => prec(PREC.MEMBER, seq(
member_expression: $ => prec.dynamic(1, seq(
field('object', choice(

@@ -808,17 +849,17 @@ $._expression,

array_access: $ => prec.right(14,seq(
array_access: $ => seq(
field('base', $._expression),
'[',
field('index', $._expression),
optional(field('index', $._expression)),
']'
)),
),
slice_access: $ => prec(PREC.MEMBER, seq(
slice_access: $ => seq(
field('base', $._expression),
'[',
field('from', $._expression),
optional(field('from', $._expression)),
':',
field('to', $._expression),
optional(field('to', $._expression)),
']'
)),
),

@@ -835,20 +876,20 @@ struct_expression: $ => seq(

),
_lhs_expression: $ => choice(
$.member_expression,
$.array_access,
$.identifier,
$.tuple_expression,
// $._destructuring_pattern
),
// _lhs_expression: $ => choice(
// $.member_expression,
// $.array_access,
// $.identifier,
// $.tuple_expression,
// // $._destructuring_pattern
// ),
parenthesized_expression: $ => prec(2, seq('(', $._expression, ')')),
assignment_expression: $ => prec.right(PREC.ASSIGN, seq(
field('left', choice($.parenthesized_expression, $._lhs_expression)),
field('left', $._expression),
'=',
field('right', $._expression)
)),
augmented_assignment_expression: $ => prec.right(PREC.ASSIGN, seq(
field('left', $._lhs_expression),
field('left', $._expression),
choice('+=', '-=', '*=', '/=', '%=', '^=', '&=', '|=', '>>=', '>>>=',

@@ -858,22 +899,26 @@ '<<=',),

)),
call_expression: $ => seq(
seq($._expression, $._call_arguments),
),
call_expression: $ => seq($._expression, $._call_arguments),
payable_conversion_expression: $ => seq('payable', $._call_arguments),
meta_type_expression: $ => seq('type', '(', $.type_name, ')'),
type_name: $ => prec(0, choice(
type_name: $ => choice(
$.primitive_type,
$._user_defined_type,
$.user_defined_type,
$._mapping,
$._array_type,
$._function_type,
)),
),
_array_type: $ => prec(1, seq($.type_name, '[', optional($._expression), ']')),
_function_type: $ => prec.right(seq(
'function', $._parameter_list, optional($._return_parameters),
'function',
$._parameter_list,
repeat(choice(
$.visibility,
$.state_mutability,
)),
optional($._return_parameters),
)),

@@ -886,3 +931,3 @@

_return_parameters: $ => seq(
'(', commaSep1($._nameless_parameter), ')'
'returns', '(', commaSep1($._nameless_parameter), ')'
),

@@ -907,10 +952,5 @@

// TODO: make visible type
_user_defined_type: $ => prec.left(PREC. USER_TYPE, seq(
$.identifier,
repeat(seq(
'.',
$.identifier,
))
)),
user_defined_type: $ => $._identifier_path,
_identifier_path: $ => prec.left(dotSep1( $.identifier)),

@@ -923,3 +963,3 @@ _mapping: $ => seq(

$.primitive_type,
$._user_defined_type
$.user_defined_type
),

@@ -943,3 +983,3 @@

_uint: $ => choice (
'uint', 'uint8', 'uint16', 'uint24', 'uint32', 'uint40', 'uint48', 'uint56', 'uint64', 'uint72', 'uint80', 'uint88', 'uint96', 'uint104', 'uint112', 'uint120', 'uint128', 'uint136', 'uint144', 'uint152', 'uint160', 'uint168', 'uint176', 'uint184', 'uint192', 'uint200', 'uint208', 'uint216', 'uint224', 'uint232', 'uint240', 'uint248', 'uint256'
'uint', 'uint8', 'uint16', 'uint24', 'uint32', 'uint40', 'uint48', 'uint56', 'uint64', 'uint72', 'uint80', 'uint88', 'uint96', 'uint104', 'uint112', 'uint120', 'uint128', 'uint136', 'uint144', 'uint152', 'uint160', 'uint168', 'uint176', 'uint184', 'uint192', 'uint200', 'uint208', 'uint216', 'uint224', 'uint232', 'uint240', 'uint248', 'uint256'
),

@@ -976,7 +1016,8 @@ _bytes: $ => choice (

_decimal_number: $ => choice(
/\d+(\.\d+)?([eE](-)?\d+)?/,
/\.\d+([eE](-)?\d+)?/,
/(\d|_)+(\.(\d|_)+)?([eE](-)?(\d|_)+)?/,
/\.(\d|_)+([eE](-)?(\d|_)+)?/,
),
_hex_number: $ => seq(/0[xX]/, optional(optionalDashSeparation($._hex_digit))),
_hex_digit: $ => /([a-fA-F0-9][a-fA-F0-9])/,
_hex_number: $ => prec(10, /0[xX]([a-fA-F0-9][a-fA-F0-9]?_?)+/),
// _hex_number: $ => seq(/0[xX]/, optional(optionalDashSeparation($._hex_digit))),
_hex_digit: $ => /([a-fA-F0-9][a-fA-F0-9])/,
number_unit: $ => choice(

@@ -994,8 +1035,8 @@ 'wei','szabo', 'finney', 'gwei', 'ether', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'years'

)))),
_escape_sequence: $ => seq('\\', choice(
// TODO: it might be allowed to escape non special characters
/"'\\bfnrtv\n\r/,
/u([a-fA-F0-9]{4})/,
/x([a-fA-F0-9]{2})/,
)),
// _escape_sequence: $ => seq('\\', choice(
// // TODO: it might be allowed to escape non special characters
// /"'\\bfnrtv\n\r/,
// /u([a-fA-F0-9]{4})/,
// /x([a-fA-F0-9]{2})/,
// )),
_escape_sequence: $ => token.immediate(seq(

@@ -1011,4 +1052,6 @@ '\\',

)),
_single_quoted_unicode_char: $ => choice(/[^'\r\n\\]/, $._escape_sequence),
_double_quoted_unicode_char: $ => choice(/[^"\r\n\\]/, $._escape_sequence),
_single_quoted_unicode_char: $ =>
token.immediate(prec(PREC.STRING, /[^'\\\n]+|\\\r?\n/)),
_double_quoted_unicode_char: $ =>
token.immediate(prec(PREC.STRING, /[^"\\\n]+|\\\r?\n/)),
unicode_string_literal: $ => prec.left(repeat1(seq(

@@ -1025,3 +1068,3 @@ 'unicode',

repeat(choice(
token.immediate(prec(PREC.STRING, /[^"\\\n]+|\\\r?\n/)),
$._string_immediate_elt_inside_double_quote,
$._escape_sequence

@@ -1034,3 +1077,3 @@ )),

repeat(choice(
token.immediate(prec(PREC.STRING, /[^'\\\n]+|\\\r?\n/)),
$._string_immediate_elt_inside_quote,
$._escape_sequence

@@ -1041,4 +1084,10 @@ )),

),
// We need to name those elts for ocaml-tree-sitter-semgrep.
_string_immediate_elt_inside_double_quote: $ =>
token.immediate(prec(PREC.STRING, /[^"\\\n]+|\\\r?\n/)),
_string_immediate_elt_inside_quote: $ =>
token.immediate(prec(PREC.STRING, /[^'\\\n]+|\\\r?\n/)),
// Based on: https://github.com/tree-sitter/tree-sitter-c/blob/master/grammar.js#L965

@@ -1048,3 +1097,3 @@ comment: $ => token(

choice(
seq('//', /(\\(.|\r?\n)|[^\\\n])*/),
seq('//', /([^\r\n])*/),
seq(

@@ -1071,3 +1120,3 @@ '/*',

),
);
);
}

@@ -1089,5 +1138,5 @@

optional(','),
);
);
}
function commaSep(rule) {

@@ -1106,4 +1155,4 @@ return optional(commaSep1(rule));

),
);
);
}
{
"name": "tree-sitter-solidity",
"version": "1.0.12",
"version": "1.1.0",
"description": "A tree sitter parser for Solidity",

@@ -12,6 +12,6 @@ "main": "bindings/node",

"dependencies": {
"nan": "^2.14.1"
"nan": "^2.15.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.16.9"
"tree-sitter-cli": "^0.20.6"
},

@@ -18,0 +18,0 @@ "tree-sitter": [

@@ -28,3 +28,6 @@ ## 🌴 tree-sitter-solidity

### References
-> Ethereum solidity grammar: https://github.com/ethereum/solidity/blob/develop/docs/grammar/Solidity.g4
-> Ethereum solidity grammar:
- https://github.com/ethereum/solidity/blob/develop/docs/grammar/SolidityParser.g4
- https://github.com/ethereum/solidity/blob/develop/docs/grammar/SolidityLexer.g4
- https://docs.soliditylang.org/en/latest/grammar.html?#

@@ -31,0 +34,0 @@ -> Tree-sitter javascript grammar: https://github.com/tree-sitter/tree-sitter-javascript/blob/master/grammar.js

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

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