tree-sitter-go
Advanced tools
Comparing version 0.20.0 to 0.21.0
@@ -1,19 +0,7 @@ | ||
try { | ||
module.exports = require('../../build/Release/tree_sitter_go_binding'); | ||
} catch (error1) { | ||
if (error1.code !== 'MODULE_NOT_FOUND') { | ||
throw error1; | ||
} | ||
try { | ||
module.exports = require('../../build/Debug/tree_sitter_go_binding'); | ||
} catch (error2) { | ||
if (error2.code !== 'MODULE_NOT_FOUND') { | ||
throw error2; | ||
} | ||
throw error1; | ||
} | ||
} | ||
const root = require("path").join(__dirname, "..", ".."); | ||
module.exports = require("node-gyp-build")(root); | ||
try { | ||
module.exports.nodeTypeInfo = require('../../src/node-types.json'); | ||
module.exports.nodeTypeInfo = require("../../src/node-types.json"); | ||
} catch (_) {} |
182
grammar.js
/** | ||
* @file Go grammar for tree-sitter | ||
* @author Max Brunsfeld | ||
* @author Max Brunsfeld <maxbrunsfeld@gmail.com> | ||
* @author Amaan Qureshi <amaanq12@gmail.com> | ||
* @license MIT | ||
*/ | ||
/* eslint-disable arrow-parens */ | ||
/* eslint-disable camelcase */ | ||
/* eslint-disable-next-line spaced-comment */ | ||
/// <reference types="tree-sitter-cli/dsl" /> | ||
// @ts-check | ||
const | ||
PREC = { | ||
primary: 7, | ||
unary: 6, | ||
multiplicative: 5, | ||
additive: 4, | ||
comparative: 3, | ||
and: 2, | ||
or: 1, | ||
composite_literal: -1, | ||
}, | ||
const PREC = { | ||
primary: 7, | ||
unary: 6, | ||
multiplicative: 5, | ||
additive: 4, | ||
comparative: 3, | ||
and: 2, | ||
or: 1, | ||
composite_literal: -1, | ||
}; | ||
multiplicative_operators = ['*', '/', '%', '<<', '>>', '&', '&^'], | ||
additive_operators = ['+', '-', '|', '^'], | ||
comparative_operators = ['==', '!=', '<', '<=', '>', '>='], | ||
assignment_operators = multiplicative_operators.concat(additive_operators).map(operator => operator + '=').concat('='), | ||
const multiplicativeOperators = ['*', '/', '%', '<<', '>>', '&', '&^']; | ||
const additiveOperators = ['+', '-', '|', '^']; | ||
const comparativeOperators = ['==', '!=', '<', '<=', '>', '>=']; | ||
const assignmentOperators = multiplicativeOperators.concat(additiveOperators).map(operator => operator + '=').concat('='); | ||
newline = '\n', | ||
terminator = choice(newline, ';', '\0'), | ||
const newline = '\n'; | ||
const terminator = choice(newline, ';', '\0'); | ||
hexDigit = /[0-9a-fA-F]/, | ||
octalDigit = /[0-7]/, | ||
decimalDigit = /[0-9]/, | ||
binaryDigit = /[01]/, | ||
const hexDigit = /[0-9a-fA-F]/; | ||
const octalDigit = /[0-7]/; | ||
const decimalDigit = /[0-9]/; | ||
const binaryDigit = /[01]/; | ||
hexDigits = seq(hexDigit, repeat(seq(optional('_'), hexDigit))), | ||
octalDigits = seq(octalDigit, repeat(seq(optional('_'), octalDigit))), | ||
decimalDigits = seq(decimalDigit, repeat(seq(optional('_'), decimalDigit))), | ||
binaryDigits = seq(binaryDigit, repeat(seq(optional('_'), binaryDigit))), | ||
const hexDigits = seq(hexDigit, repeat(seq(optional('_'), hexDigit))); | ||
const octalDigits = seq(octalDigit, repeat(seq(optional('_'), octalDigit))); | ||
const decimalDigits = seq(decimalDigit, repeat(seq(optional('_'), decimalDigit))); | ||
const binaryDigits = seq(binaryDigit, repeat(seq(optional('_'), binaryDigit))); | ||
hexLiteral = seq('0', choice('x', 'X'), optional('_'), hexDigits), | ||
octalLiteral = seq('0', optional(choice('o', 'O')), optional('_'), octalDigits), | ||
decimalLiteral = choice('0', seq(/[1-9]/, optional(seq(optional('_'), decimalDigits)))), | ||
binaryLiteral = seq('0', choice('b', 'B'), optional('_'), binaryDigits), | ||
const hexLiteral = seq('0', choice('x', 'X'), optional('_'), hexDigits); | ||
const octalLiteral = seq('0', optional(choice('o', 'O')), optional('_'), octalDigits); | ||
const decimalLiteral = choice('0', seq(/[1-9]/, optional(seq(optional('_'), decimalDigits)))); | ||
const binaryLiteral = seq('0', choice('b', 'B'), optional('_'), binaryDigits); | ||
intLiteral = choice(binaryLiteral, decimalLiteral, octalLiteral, hexLiteral), | ||
const intLiteral = choice(binaryLiteral, decimalLiteral, octalLiteral, hexLiteral); | ||
decimalExponent = seq(choice('e', 'E'), optional(choice('+', '-')), decimalDigits), | ||
decimalFloatLiteral = choice( | ||
seq(decimalDigits, '.', optional(decimalDigits), optional(decimalExponent)), | ||
seq(decimalDigits, decimalExponent), | ||
seq('.', decimalDigits, optional(decimalExponent)), | ||
), | ||
const decimalExponent = seq(choice('e', 'E'), optional(choice('+', '-')), decimalDigits); | ||
const decimalFloatLiteral = choice( | ||
seq(decimalDigits, '.', optional(decimalDigits), optional(decimalExponent)), | ||
seq(decimalDigits, decimalExponent), | ||
seq('.', decimalDigits, optional(decimalExponent)), | ||
); | ||
hexExponent = seq(choice('p', 'P'), optional(choice('+', '-')), decimalDigits), | ||
hexMantissa = choice( | ||
seq(optional('_'), hexDigits, '.', optional(hexDigits)), | ||
seq(optional('_'), hexDigits), | ||
seq('.', hexDigits), | ||
), | ||
hexFloatLiteral = seq('0', choice('x', 'X'), hexMantissa, hexExponent), | ||
const hexExponent = seq(choice('p', 'P'), optional(choice('+', '-')), decimalDigits); | ||
const hexMantissa = choice( | ||
seq(optional('_'), hexDigits, '.', optional(hexDigits)), | ||
seq(optional('_'), hexDigits), | ||
seq('.', hexDigits), | ||
); | ||
const hexFloatLiteral = seq('0', choice('x', 'X'), hexMantissa, hexExponent); | ||
floatLiteral = choice(decimalFloatLiteral, hexFloatLiteral), | ||
const floatLiteral = choice(decimalFloatLiteral, hexFloatLiteral); | ||
imaginaryLiteral = seq(choice(decimalDigits, intLiteral, floatLiteral), 'i'); | ||
const imaginaryLiteral = seq(choice(decimalDigits, intLiteral, floatLiteral), 'i'); | ||
@@ -85,2 +82,3 @@ module.exports = grammar({ | ||
$._string_literal, | ||
$._interface_elem, | ||
], | ||
@@ -92,9 +90,9 @@ | ||
[$._simple_type, $._expression], | ||
[$._simple_type, $.generic_type, $._expression], | ||
[$.qualified_type, $._expression], | ||
[$.generic_type, $._expression], | ||
[$.generic_type, $._simple_type], | ||
[$.parameter_declaration, $._simple_type, $._expression], | ||
[$.parameter_declaration, $.generic_type, $._expression], | ||
[$.parameter_declaration, $._expression], | ||
[$.parameter_declaration, $._simple_type], | ||
[$.type_parameter_declaration, $._simple_type, $._expression], | ||
[$.type_parameter_declaration, $._expression], | ||
[$.type_parameter_declaration, $._simple_type, $.generic_type, $._expression], | ||
], | ||
@@ -232,3 +230,3 @@ | ||
'[', | ||
commaSep1($.parameter_declaration), | ||
commaSep1($.type_parameter_declaration), | ||
optional(','), | ||
@@ -238,2 +236,7 @@ ']', | ||
type_parameter_declaration: $ => seq( | ||
commaSep1(field('name', $.identifier)), | ||
field('type', alias($.type_elem, $.type_constraint)), | ||
), | ||
parameter_list: $ => seq( | ||
@@ -307,14 +310,13 @@ '(', | ||
$.function_type, | ||
$.union_type, | ||
$.negated_type, | ||
), | ||
generic_type: $ => seq( | ||
field('type', choice($._type_identifier, $.qualified_type, $.union_type, $.negated_type)), | ||
generic_type: $ => prec.dynamic(1, seq( | ||
field('type', choice($._type_identifier, $.qualified_type, $.negated_type)), | ||
field('type_arguments', $.type_arguments), | ||
), | ||
)), | ||
type_arguments: $ => prec.dynamic(2, seq( | ||
'[', | ||
commaSep1($._type), | ||
commaSep1($.type_elem), | ||
optional(','), | ||
@@ -351,8 +353,2 @@ ']', | ||
union_type: $ => prec.left(seq( | ||
$._type, | ||
'|', | ||
$._type, | ||
)), | ||
negated_type: $ => prec.left(seq( | ||
@@ -395,4 +391,4 @@ '~', | ||
optional(seq( | ||
$._interface_body, | ||
repeat(seq(terminator, $._interface_body)), | ||
$._interface_elem, | ||
repeat(seq(terminator, $._interface_elem)), | ||
optional(terminator), | ||
@@ -403,19 +399,8 @@ )), | ||
_interface_body: $ => choice( | ||
$.method_spec, | ||
$.struct_elem, | ||
alias($._simple_type, $.constraint_elem), | ||
_interface_elem: $ => choice( | ||
$.method_elem, | ||
$.type_elem, | ||
), | ||
struct_elem: $ => seq( | ||
$.struct_term, | ||
repeat(seq('|', $.struct_term)), | ||
), | ||
struct_term: $ => prec(1, seq( | ||
optional(choice('~', '*')), | ||
$.struct_type, | ||
)), | ||
method_spec: $ => seq( | ||
method_elem: $ => seq( | ||
field('name', $._field_identifier), | ||
@@ -426,2 +411,4 @@ field('parameters', $.parameter_list), | ||
type_elem: $ => sep1($._type, '|'), | ||
map_type: $ => prec.right(seq( | ||
@@ -524,3 +511,3 @@ 'map', | ||
field('left', $.expression_list), | ||
field('operator', choice(...assignment_operators)), | ||
field('operator', choice(...assignmentOperators)), | ||
field('right', $.expression_list), | ||
@@ -678,2 +665,3 @@ ), | ||
$.type_conversion_expression, | ||
$.type_instantiation_expression, | ||
$.identifier, | ||
@@ -785,2 +773,10 @@ alias(choice('new', 'make'), $.identifier), | ||
type_instantiation_expression: $ => prec.dynamic(-1, seq( | ||
field('type', $._type), | ||
'[', | ||
commaSep1($._type), | ||
optional(','), | ||
']', | ||
)), | ||
composite_literal: $ => prec(PREC.composite_literal, seq( | ||
@@ -832,5 +828,5 @@ field('type', choice( | ||
const table = [ | ||
[PREC.multiplicative, choice(...multiplicative_operators)], | ||
[PREC.additive, choice(...additive_operators)], | ||
[PREC.comparative, choice(...comparative_operators)], | ||
[PREC.multiplicative, choice(...multiplicativeOperators)], | ||
[PREC.additive, choice(...additiveOperators)], | ||
[PREC.comparative, choice(...comparativeOperators)], | ||
[PREC.and, '&&'], | ||
@@ -937,2 +933,16 @@ [PREC.or, '||'], | ||
/** | ||
* Creates a rule to match one or more occurrences of `rule` separated by `sep` | ||
* | ||
* @param {RuleOrLiteral} rule | ||
* | ||
* @param {RuleOrLiteral} separator | ||
* | ||
* @return {SeqRule} | ||
* | ||
*/ | ||
function sep1(rule, separator) { | ||
return seq(rule, repeat(seq(separator, rule))); | ||
} | ||
/** | ||
* Creates a rule to match one or more of the rules separated by a comma | ||
@@ -939,0 +949,0 @@ * |
{ | ||
"name": "tree-sitter-go", | ||
"version": "0.20.0", | ||
"version": "0.21.0", | ||
"description": "Go grammar for tree-sitter", | ||
"repository": "github:tree-sitter/tree-sitter-go", | ||
"license": "MIT", | ||
"author": "Max Brunsfeld <maxbrunsfeld@gmail.com>", | ||
"contributors": [ | ||
"Amaan Qureshi <amaanq12@gmail.com>" | ||
], | ||
"main": "bindings/node", | ||
"types": "bindings/node", | ||
"keywords": [ | ||
"parser", | ||
"incremental", | ||
"parsing", | ||
"tree-sitter", | ||
"go" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/tree-sitter/tree-sitter-go.git" | ||
}, | ||
"author": "Max Brunsfeld", | ||
"license": "MIT", | ||
"files": [ | ||
"grammar.js", | ||
"binding.gyp", | ||
"prebuilds/**", | ||
"bindings/node/*", | ||
"queries/*", | ||
"src/**" | ||
], | ||
"dependencies": { | ||
"nan": "^2.14.0" | ||
"node-addon-api": "^8.0.0", | ||
"node-gyp-build": "^4.8.0" | ||
}, | ||
"peerDependencies": { | ||
"tree-sitter": "^0.21.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"tree_sitter": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.45.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-google": "^0.14.0", | ||
"tree-sitter-cli": "^0.20.8" | ||
"tree-sitter-cli": "^0.22.2", | ||
"prebuildify": "^6.0.0" | ||
}, | ||
"scripts": { | ||
"build": "tree-sitter generate && node-gyp build", | ||
"install": "node-gyp-build", | ||
"prebuildify": "prebuildify --napi --strip", | ||
"build": "tree-sitter generate --no-bindings", | ||
"build-wasm": "tree-sitter build --wasm", | ||
"lint": "eslint grammar.js", | ||
"test": "tree-sitter test && script/parse-examples", | ||
"test-windows": "tree-sitter test" | ||
"parse": "tree-sitter parse", | ||
"test": "tree-sitter test" | ||
}, | ||
@@ -35,5 +59,49 @@ "tree-sitter": [ | ||
"go" | ||
], | ||
"highlights": "queries/highlights.scm", | ||
"tags": "queries/tags.scm" | ||
} | ||
], | ||
"eslintConfig": { | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"extends": "google", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"arrow-parens": "off", | ||
"camel-case": "off", | ||
"indent": [ | ||
"error", | ||
2, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"max-len": [ | ||
"error", | ||
{ | ||
"code": 160, | ||
"ignoreComments": true, | ||
"ignoreUrls": true, | ||
"ignoreStrings": true | ||
} | ||
], | ||
"spaced-comment": [ | ||
"warn", | ||
"always", | ||
{ | ||
"line": { | ||
"markers": [ | ||
"/" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
# tree-sitter-go | ||
[![CI](https://github.com/tree-sitter/tree-sitter-go/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-go/actions/workflows/ci.yml) | ||
[![CI][ci]](https://github.com/tree-sitter/tree-sitter-go/actions/workflows/ci.yml) | ||
[![discord][discord]](https://discord.gg/w7nTvsVJhm) | ||
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org) | ||
[![crates][crates]](https://crates.io/crates/tree-sitter-go) | ||
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-go) | ||
[![pypi][pypi]](https://pypi.org/project/tree-sitter-go) | ||
A [tree-sitter][] grammar for [Go](https://go.dev/ref/spec). | ||
[Go](https://go.dev/ref/spec) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). | ||
[tree-sitter]: https://github.com/tree-sitter/tree-sitter | ||
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-go/ci.yml?logo=github&label=CI | ||
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord | ||
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix | ||
[npm]: https://img.shields.io/npm/v/tree-sitter-go?logo=npm | ||
[crates]: https://img.shields.io/crates/v/tree-sitter-go?logo=rust | ||
[pypi]: https://img.shields.io/pypi/v/tree-sitter-go?logo=pypi&logoColor=ffd242 |
@@ -91,2 +91,6 @@ [ | ||
{ | ||
"type": "type_instantiation_expression", | ||
"named": true | ||
}, | ||
{ | ||
"type": "unary_expression", | ||
@@ -178,6 +182,2 @@ "named": true | ||
"named": true | ||
}, | ||
{ | ||
"type": "union_type", | ||
"named": true | ||
} | ||
@@ -1197,6 +1197,2 @@ ] | ||
"named": true | ||
}, | ||
{ | ||
"type": "union_type", | ||
"named": true | ||
} | ||
@@ -1435,12 +1431,8 @@ ] | ||
{ | ||
"type": "constraint_elem", | ||
"type": "method_elem", | ||
"named": true | ||
}, | ||
{ | ||
"type": "method_spec", | ||
"type": "type_elem", | ||
"named": true | ||
}, | ||
{ | ||
"type": "struct_elem", | ||
"named": true | ||
} | ||
@@ -1631,3 +1623,3 @@ ] | ||
{ | ||
"type": "method_spec", | ||
"type": "method_elem", | ||
"named": true, | ||
@@ -2075,32 +2067,2 @@ "fields": { | ||
{ | ||
"type": "struct_elem", | ||
"named": true, | ||
"fields": {}, | ||
"children": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "struct_term", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "struct_term", | ||
"named": true, | ||
"fields": {}, | ||
"children": { | ||
"multiple": false, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "struct_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "struct_type", | ||
@@ -2155,3 +2117,3 @@ "named": true, | ||
{ | ||
"type": "_type", | ||
"type": "type_elem", | ||
"named": true | ||
@@ -2219,2 +2181,17 @@ } | ||
{ | ||
"type": "type_constraint", | ||
"named": true, | ||
"fields": {}, | ||
"children": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "type_conversion_expression", | ||
@@ -2265,2 +2242,69 @@ "named": true, | ||
{ | ||
"type": "type_elem", | ||
"named": true, | ||
"fields": {}, | ||
"children": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "type_instantiation_expression", | ||
"named": true, | ||
"fields": { | ||
"type": { | ||
"multiple": false, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
"children": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "type_parameter_declaration", | ||
"named": true, | ||
"fields": { | ||
"name": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "identifier", | ||
"named": true | ||
} | ||
] | ||
}, | ||
"type": { | ||
"multiple": false, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "type_constraint", | ||
"named": true | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "type_parameter_list", | ||
@@ -2274,3 +2318,3 @@ "named": true, | ||
{ | ||
"type": "parameter_declaration", | ||
"type": "type_parameter_declaration", | ||
"named": true | ||
@@ -2418,17 +2462,2 @@ } | ||
{ | ||
"type": "union_type", | ||
"named": true, | ||
"fields": {}, | ||
"children": { | ||
"multiple": true, | ||
"required": true, | ||
"types": [ | ||
{ | ||
"type": "_type", | ||
"named": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "var_declaration", | ||
@@ -2435,0 +2464,0 @@ "named": true, |
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 not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 4 instances 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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3191366
10732
18
1
3
4
21
1
5
+ Addednode-addon-api@^8.0.0
+ Addednode-gyp-build@^4.8.0
+ Addednode-addon-api@8.3.0(transitive)
+ Addednode-gyp-build@4.8.4(transitive)
+ Addedtree-sitter@0.21.1(transitive)
- Removednan@^2.14.0
- Removednan@2.22.0(transitive)