Merge commit '64457ea6b73ef5422ed1687178d4545c3e91334a'

pull/502/head
Wilfred Hughes 2023-03-17 00:05:08 +07:00
commit 8266e0a161
14 changed files with 22107 additions and 19524 deletions

@ -8,7 +8,7 @@ Added support for Ada.
Improved parsing for TOML.
Updated grammars for Bash, C, C++, C#, Clojure, CMake, Elixir and
Updated grammars for Bash, C, C++, C#, Clojure, CMake, Elixir, Go and
Java.
Difftastic now prefers treating files as 'mostly UTF-8' or binary rather than

@ -1,8 +1,11 @@
name: Build/test
on:
pull_request: null
push:
branches:
- "**"
- master
jobs:
test:
runs-on: ${{ matrix.os }}

@ -13,3 +13,4 @@ target
*.o
bindings/c/*.h
bindings/c/tree-sitter-*.pc
.build/

@ -0,0 +1,39 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterGo",
platforms: [.macOS(.v10_13), .iOS(.v11)],
products: [
.library(name: "TreeSitterGo", targets: ["TreeSitterGo"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterGo",
path: ".",
exclude: [
"binding.gyp",
"bindings",
"Cargo.toml",
"corpus",
"examples",
"grammar.js",
"LICENSE",
"Makefile",
"package.json",
"README.md",
"script",
"src/grammar.json",
"src/node-types.json",
],
sources: [
"src/parser.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
]
)

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_GO_H_
#define TREE_SITTER_GO_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_go();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_GO_H_

@ -246,6 +246,7 @@ func f2() (result int, err error) {}
func f(x ... int, y ... int)
func g1[T, U any, V interface{}, W Foo[Bar[T]]](a Foo[T]) {}
func g1[T, U any, V interface{}, W Foo[Bar[T]]](a Foo[T]) {}
func g2(a foo.bar[int]) {}
func f[A int|string, B ~int, C ~int|~string]()
--------------------------------------------------------------------------------
@ -353,6 +354,18 @@ func f[A int|string, B ~int, C ~int|~string]()
(type_arguments
(type_identifier)))))
(block))
(function_declaration
(identifier)
(parameter_list
(parameter_declaration
(identifier)
(generic_type
(qualified_type
(package_identifier)
(type_identifier))
(type_arguments
(type_identifier)))))
(block))
(function_declaration
(identifier)
(type_parameter_list
@ -463,6 +476,7 @@ package main
func (self Person) Equals(other Person) bool {}
func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {}
func (p *T1) M1()
--------------------------------------------------------------------------------
@ -494,7 +508,15 @@ func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {}
(parenthesized_type
(type_identifier))))
(type_identifier)
(block)))
(block))
(method_declaration
(parameter_list
(parameter_declaration
(identifier)
(pointer_type
(type_identifier))))
(field_identifier)
(parameter_list)))
================================================================================
Type declarations

@ -297,6 +297,8 @@ const (
a = "0"
b = "`\"`"
c = "\x0c"
d = "errorstring
"
)
--------------------------------------------------------------------------------
@ -318,7 +320,9 @@ const (
(identifier)
(expression_list
(interpreted_string_literal
(escape_sequence))))))
(escape_sequence))))
(ERROR
(identifier))))
================================================================================
Slice literals

@ -1,10 +1,10 @@
============================================
================================================================================
Qualified type names
============================================
================================================================================
type a b.c
---
--------------------------------------------------------------------------------
(source_file
(type_declaration
@ -14,13 +14,13 @@ type a b.c
package: (package_identifier)
name: (type_identifier)))))
============================================
================================================================================
Array types
============================================
================================================================================
type a [2+2]c
---
--------------------------------------------------------------------------------
(source_file
(type_declaration
@ -32,31 +32,35 @@ type a [2+2]c
right: (int_literal))
element: (type_identifier)))))
============================================
================================================================================
Slice types
============================================
================================================================================
package main
type a []c
type b [][]d
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(slice_type (type_identifier))))
(slice_type
(type_identifier))))
(type_declaration
(type_spec
(type_identifier)
(slice_type (slice_type (type_identifier))))))
(slice_type
(slice_type
(type_identifier))))))
============================================
================================================================================
Struct types
============================================
================================================================================
package main
@ -83,38 +87,47 @@ type g1 struct {
type g2[T, U any, V interface{}, W Foo[Bar[T]]] struct {}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(struct_type (field_declaration_list))))
(struct_type
(field_declaration_list))))
(type_declaration
(type_spec
(type_identifier)
(struct_type (field_declaration_list (field_declaration (type_identifier))))))
(struct_type
(field_declaration_list
(field_declaration
(type_identifier))))))
(type_declaration
(type_spec
(type_identifier)
(struct_type (field_declaration_list
(field_declaration
(field_identifier)
(field_identifier)
(type_identifier))))))
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(field_identifier)
(type_identifier))))))
(type_declaration
(type_spec
(type_identifier)
(struct_type (field_declaration_list
(comment)
(field_declaration
(qualified_type (package_identifier) (type_identifier)))
(comment)
(field_declaration
(field_identifier)
(type_identifier)
(raw_string_literal))))))
(struct_type
(field_declaration_list
(comment)
(field_declaration
(qualified_type
(package_identifier)
(type_identifier)))
(comment)
(field_declaration
(field_identifier)
(type_identifier)
(raw_string_literal))))))
(type_declaration
(type_spec
(type_identifier)
@ -153,12 +166,14 @@ type g2[T, U any, V interface{}, W Foo[Bar[T]]] struct {}
(type_arguments
(generic_type
(type_identifier)
(type_arguments (type_identifier)))))))
(struct_type (field_declaration_list)))))
(type_arguments
(type_identifier)))))))
(struct_type
(field_declaration_list)))))
============================================
================================================================================
Interface types
============================================
================================================================================
package main
@ -177,59 +192,142 @@ type SignedInteger interface {
int | int8 | ~uint | ~uint8
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(type_declaration (type_spec
(type_identifier)
(interface_type)))
(type_declaration (type_spec
(type_identifier)
(interface_type (interface_type_name
(qualified_type (package_identifier) (type_identifier))))))
(type_declaration (type_spec
(type_identifier)
(interface_type
(interface_type_name (type_identifier))
(interface_type_name (qualified_type (package_identifier) (type_identifier)))
(method_spec
(field_identifier)
(parameter_list (parameter_declaration (identifier) (type_identifier)))
(type_identifier))
(method_spec
(field_identifier)
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(interface_type)))
(type_declaration
(type_spec
(type_identifier)
(interface_type
(interface_type_name
(qualified_type
(package_identifier)
(type_identifier))))))
(type_declaration
(type_spec
(type_identifier)
(interface_type
(interface_type_name
(type_identifier))
(interface_type_name
(qualified_type
(package_identifier)
(type_identifier)))
(method_spec
(field_identifier)
(parameter_list
(parameter_declaration (type_identifier))
(variadic_parameter_declaration (type_identifier))) (type_identifier)))))
(type_declaration (type_spec
(type_identifier)
(interface_type (constraint_elem
(constraint_term (type_identifier))
(constraint_term (type_identifier))
(constraint_term (type_identifier))
(constraint_term (type_identifier)))))))
============================================
(parameter_declaration
(identifier)
(type_identifier)))
(type_identifier))
(method_spec
(field_identifier)
(parameter_list
(parameter_declaration
(type_identifier))
(variadic_parameter_declaration
(type_identifier)))
(type_identifier)))))
(type_declaration
(type_spec
(type_identifier)
(interface_type
(constraint_elem
(constraint_term
(type_identifier))
(constraint_term
(type_identifier))
(constraint_term
(type_identifier))
(constraint_term
(type_identifier)))))))
================================================================================
Interface embedded struct types
================================================================================
package main
type NewEmbeddings interface {
struct{ f int }
~struct{ f int }
*struct{ f int }
struct{ f int } | ~struct{ f int }
}
--------------------------------------------------------------------------------
(source_file
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(interface_type
(struct_elem
(struct_term
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier))))))
(struct_elem
(struct_term
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier))))))
(struct_elem
(struct_term
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier))))))
(struct_elem
(struct_term
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier)))))
(struct_term
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier))))))))))
================================================================================
Map types
============================================
================================================================================
package main
type m1 map[string]error
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(map_type (type_identifier) (type_identifier)))))
(map_type
(type_identifier)
(type_identifier)))))
============================================
================================================================================
Pointer types
============================================
================================================================================
package main
@ -238,21 +336,25 @@ type (
p2 **p1
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(pointer_type (type_identifier)))
(pointer_type
(type_identifier)))
(type_spec
(type_identifier)
(pointer_type (pointer_type (type_identifier))))))
(pointer_type
(pointer_type
(type_identifier))))))
============================================
================================================================================
Channel types
============================================
================================================================================
package main
@ -262,24 +364,32 @@ type (
c3 chan<- <-chan int
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(channel_type (channel_type (type_identifier))))
(channel_type
(channel_type
(type_identifier))))
(type_spec
(type_identifier)
(channel_type (channel_type (struct_type (field_declaration_list)))))
(channel_type
(channel_type
(struct_type
(field_declaration_list)))))
(type_spec
(type_identifier)
(channel_type (channel_type (type_identifier))))))
(channel_type
(channel_type
(type_identifier))))))
============================================
================================================================================
Function types
============================================
================================================================================
package main
@ -289,38 +399,47 @@ type (
c func(int, ...*string) bool
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec
(type_identifier)
(function_type
(parameter_list
(parameter_declaration (type_identifier)))
(parameter_declaration
(type_identifier)))
(type_identifier)))
(type_spec
(type_identifier)
(function_type
(parameter_list
(parameter_declaration (type_identifier))
(parameter_declaration (pointer_type (type_identifier))))
(parameter_declaration
(type_identifier))
(parameter_declaration
(pointer_type
(type_identifier))))
(parameter_list
(parameter_declaration (type_identifier))
(parameter_declaration (type_identifier)))))
(parameter_declaration
(type_identifier))
(parameter_declaration
(type_identifier)))))
(type_spec
(type_identifier)
(function_type
(parameter_list
(parameter_declaration (type_identifier))
(parameter_declaration
(type_identifier))
(variadic_parameter_declaration
(pointer_type (type_identifier))))
(pointer_type
(type_identifier))))
(type_identifier)))))
============================================
================================================================================
Type Aliases
============================================
================================================================================
package main
@ -336,20 +455,43 @@ type (
A5 = Value
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_alias
(type_identifier)
(type_identifier)))
(type_declaration
(type_alias (type_identifier) (type_identifier)))
(type_alias
(type_identifier)
(type_identifier)))
(type_declaration
(type_alias (type_identifier) (type_identifier)))
(type_alias
(type_identifier)
(struct_type
(field_declaration_list))))
(type_declaration
(type_alias (type_identifier) (struct_type (field_declaration_list))))
(type_declaration
(type_alias (type_identifier) (type_identifier))
(type_alias (type_identifier) (type_identifier))
(type_alias (type_identifier) (struct_type (field_declaration_list)))
(type_alias (type_identifier) (qualified_type (package_identifier) (type_identifier)))
(type_alias (type_identifier) (type_identifier))
(type_alias (type_identifier) (type_identifier))))
(type_alias
(type_identifier)
(type_identifier))
(type_alias
(type_identifier)
(type_identifier))
(type_alias
(type_identifier)
(struct_type
(field_declaration_list)))
(type_alias
(type_identifier)
(qualified_type
(package_identifier)
(type_identifier)))
(type_alias
(type_identifier)
(type_identifier))
(type_alias
(type_identifier)
(type_identifier))))

@ -214,7 +214,7 @@ module.exports = grammar({
field('name', $._field_identifier),
field('parameters', $.parameter_list),
field('result', optional(choice($.parameter_list, $._simple_type))),
field('body', $.block)
field('body', optional($.block))
)),
type_parameter_list: $ => seq(
@ -295,7 +295,7 @@ module.exports = grammar({
),
generic_type: $ => seq(
field('type', $._type_identifier),
field('type', choice($._type_identifier, $.qualified_type)),
field('type_arguments', $.type_arguments),
),
@ -372,7 +372,7 @@ module.exports = grammar({
),
_interface_body: $ => choice(
$.method_spec, $.interface_type_name, $.constraint_elem
$.method_spec, $.interface_type_name, $.constraint_elem, $.struct_elem
),
interface_type_name: $ => choice($._type_identifier, $.qualified_type),
@ -387,6 +387,16 @@ module.exports = grammar({
$._type_identifier,
)),
struct_elem: $ => seq(
$.struct_term,
repeat(seq('|', $.struct_term))
),
struct_term: $ => prec(-1, seq(
optional(choice('~', '*')),
$.struct_type
)),
method_spec: $ => seq(
field('name', $._field_identifier),
field('parameters', $.parameter_list),
@ -841,7 +851,7 @@ module.exports = grammar({
$._interpreted_string_literal_basic_content,
$.escape_sequence
)),
'"'
token.immediate('"')
),
_interpreted_string_literal_basic_content: $ => token.immediate(prec(1, /[^"\n\\]+/)),

@ -17,7 +17,7 @@
"nan": "^2.14.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.19.1"
"tree-sitter-cli": "^0.20.6"
},
"scripts": {
"build": "tree-sitter generate && node-gyp build",

@ -1,5 +1,9 @@
; Function calls
(call_expression
function: (identifier) @function.builtin
(.match? @function.builtin "^(append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)$"))
(call_expression
function: (identifier) @function)

@ -657,8 +657,16 @@
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "block"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "BLANK"
}
]
}
}
]
@ -1161,8 +1169,17 @@
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_identifier"
},
{
"type": "SYMBOL",
"name": "qualified_type"
}
]
}
},
{
@ -1610,6 +1627,10 @@
{
"type": "SYMBOL",
"name": "constraint_elem"
},
{
"type": "SYMBOL",
"name": "struct_elem"
}
]
},
@ -1676,6 +1697,65 @@
]
}
},
"struct_elem": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "struct_term"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "SYMBOL",
"name": "struct_term"
}
]
}
}
]
},
"struct_term": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "~"
},
{
"type": "STRING",
"value": "*"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "struct_type"
}
]
}
},
"method_spec": {
"type": "SEQ",
"members": [
@ -4364,8 +4444,11 @@
}
},
{
"type": "STRING",
"value": "\""
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\""
}
}
]
},

@ -1184,6 +1184,10 @@
"multiple": false,
"required": true,
"types": [
{
"type": "qualified_type",
"named": true
},
{
"type": "type_identifier",
"named": true
@ -1430,6 +1434,10 @@
{
"type": "method_spec",
"named": true
},
{
"type": "struct_elem",
"named": true
}
]
}
@ -1579,7 +1587,7 @@
"fields": {
"body": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "block",
@ -2061,6 +2069,36 @@
]
}
},
{
"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",
"named": true,

File diff suppressed because it is too large Load Diff