Merge commit 'c8fed1f0847a65a04a4b8cb7655f5f416e0742ca'

pull/261/head
Wilfred Hughes 2022-04-17 16:41:19 +07:00
commit 30cab49688
22 changed files with 24882 additions and 20578 deletions

@ -6,7 +6,7 @@ Added support for Kotlin and TOML.
Fixed an issue with YAML and `|` block strings.
Updated to the latest upstream C++, C# and Elixir parsers.
Updated to the latest upstream C++, C#, Elixir and Go parsers.
### Diffing

@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- run: npm install
- run: npm test
test_windows:
@ -23,6 +23,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
node-version: 16
- run: npm install
- run: npm run-script test-windows

@ -6,3 +6,10 @@ package-lock.json
examples/go
examples/moby
target
*.a
*.dylib
*.so
*.o
bindings/c/*.h
bindings/c/tree-sitter-*.pc

@ -1,7 +1,7 @@
[package]
name = "tree-sitter-go"
description = "Go grammar for the tree-sitter parsing library"
version = "0.19.0"
version = "0.19.1"
authors = [
"Max Brunsfeld <maxbrunsfeld@gmail.com>",
"Douglas Creager <dcreager@dcreager.net>",
@ -25,7 +25,7 @@ include = [
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "0.19"
tree-sitter = ">= 0.19, < 0.21"
[build-dependencies]
cc = "1.0"

@ -0,0 +1,114 @@
VERSION := 0.19.1
# Repository
SRC_DIR := src
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin )
ifeq (, $(PARSER_NAME))
PARSER_NAME := $(shell basename $(PARSER_REPO_URL))
PARSER_NAME := $(subst tree-sitter-,,$(PARSER_NAME))
PARSER_NAME := $(subst .git,,$(PARSER_NAME))
endif
ifeq (, $(PARSER_URL))
PARSER_URL := $(subst :,/,$(PARSER_REPO_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
PARSER_URL := $(subst .git,,$(PARSER_URL))
endif
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )
# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig
# collect C++ sources, and link if necessary
CPPSRC := $(wildcard $(SRC_DIR)/*.cc)
ifeq (, $(CPPSRC))
ADDITIONALLIBS :=
else
ADDITIONALLIBS := -lc++
endif
# collect sources
SRC := $(wildcard $(SRC_DIR)/*.c)
SRC += $(CPPSRC)
OBJ := $(addsuffix .o,$(basename $(SRC)))
# ABI versioning
SONAME_MAJOR := 0
SONAME_MINOR := 0
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
override CFLAGS += -std=gnu99 -fPIC
override CXXFLAGS += -fPIC
# OS-specific bits
ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONALLIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(PARSER_NAME).so.$(SONAME_MAJOR)
endif
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif
all: libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXTVER) bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc
libtree-sitter-$(PARSER_NAME).a: $(OBJ)
$(AR) rcs $@ $^
libtree-sitter-$(PARSER_NAME).$(SOEXTVER): $(OBJ)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXT)
ln -sf $@ libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
bindings/c/$(PARSER_NAME).h:
sed -e 's|@UPPER_PARSERNAME@|$(UPPER_PARSER_NAME)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
bindings/c/tree-sitter.h.in > $@
bindings/c/tree-sitter-$(PARSER_NAME).pc:
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' \
-e 's|@ADDITIONALLIBS@|$(ADDITIONALLIBS)|' \
-e 's|@PARSERNAME@|$(PARSER_NAME)|' \
-e 's|@PARSERURL@|$(PARSER_URL)|' \
bindings/c/tree-sitter.pc.in > $@
install: all
install -d '$(DESTDIR)$(LIBDIR)'
install -m755 libtree-sitter-$(PARSER_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).a
install -m755 libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR)
ln -sf libtree-sitter-$(PARSER_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).$(SOEXT)
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
install -m644 bindings/c/$(PARSER_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/
install -d '$(DESTDIR)$(PCLIBDIR)'
install -m644 bindings/c/tree-sitter-$(PARSER_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/
clean:
rm -f $(OBJ) libtree-sitter-$(PARSER_NAME).a libtree-sitter-$(PARSER_NAME).$(SOEXT) libtree-sitter-$(PARSER_NAME).$(SOEXTVER_MAJOR) libtree-sitter-$(PARSER_NAME).$(SOEXTVER)
rm -f bindings/c/$(PARSER_NAME).h bindings/c/tree-sitter-$(PARSER_NAME).pc
.PHONY: all install clean

@ -3,6 +3,6 @@ tree-sitter-go
[![Build/test](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)
Golang grammar for [tree-sitter][].
A [tree-sitter][] grammar for [Go](https://go.dev/ref/spec).
[tree-sitter]: https://github.com/tree-sitter/tree-sitter

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_@UPPER_PARSERNAME@_H_
#define TREE_SITTER_@UPPER_PARSERNAME@_H_
#include <tree_sitter/parser.h>
#ifdef __cplusplus
extern "C" {
#endif
extern TSLanguage *tree_sitter_@PARSERNAME@();
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_@UPPER_PARSERNAME@_H_

@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
additionallibs=@ADDITIONALLIBS@
Name: tree-sitter-@PARSERNAME@
Description: A tree-sitter grammar for the @PARSERNAME@ programming language.
URL: @PARSERURL@
Version: @VERSION@
Libs: -L${libdir} ${additionallibs} -ltree-sitter-@PARSERNAME@
Cflags: -I${includedir}

@ -8,8 +8,8 @@ way.)
``` toml
[dependencies]
tree-sitter = "0.17"
tree-sitter-go = "0.16"
tree-sitter = "0.20"
tree-sitter-go = "0.19"
```
Typically, you will use the [language][language func] function to add this

@ -1,6 +1,6 @@
============================================
================================================================================
Single const declarations without types
============================================
================================================================================
package main
@ -8,49 +8,65 @@ const zero = 0
const one, two = 1, 2
const three, four, five = 3, 4, 5
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list (int_literal))))
(const_declaration (const_spec
(identifier)
(identifier)
(expression_list (int_literal) (int_literal))))
(const_declaration (const_spec
(identifier)
(identifier)
(identifier)
(expression_list (int_literal) (int_literal) (int_literal)))))
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(int_literal))))
(const_declaration
(const_spec
(identifier)
(identifier)
(expression_list
(int_literal)
(int_literal))))
(const_declaration
(const_spec
(identifier)
(identifier)
(identifier)
(expression_list
(int_literal)
(int_literal)
(int_literal)))))
============================================
================================================================================
Single const declarations with types
============================================
================================================================================
package main
const zero int = 0
const one, two uint64 = 1, 2
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(type_identifier)
(expression_list (int_literal))))
(const_declaration (const_spec
(identifier)
(identifier)
(type_identifier)
(expression_list (int_literal) (int_literal)))))
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(type_identifier)
(expression_list
(int_literal))))
(const_declaration
(const_spec
(identifier)
(identifier)
(type_identifier)
(expression_list
(int_literal)
(int_literal)))))
============================================
================================================================================
Grouped const declarations
============================================
================================================================================
package main
@ -59,21 +75,24 @@ const (
one = 1
)
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list (int_literal)))
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list (int_literal)))))
(expression_list
(int_literal)))))
============================================
================================================================================
Const declarations with implicit values
============================================
================================================================================
package main
@ -83,22 +102,24 @@ const (
two
)
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list (identifier)))
(expression_list
(iota)))
(const_spec
(identifier))
(const_spec
(identifier))))
============================================
================================================================================
Var declarations without types
============================================
================================================================================
package main
@ -106,70 +127,89 @@ var zero = 0
var one, two = 1, 2
var three, four, five = 3, 4, 5
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(var_declaration (var_spec
(identifier)
(expression_list (int_literal))))
(var_declaration (var_spec
(identifier)
(identifier)
(expression_list (int_literal) (int_literal))))
(var_declaration (var_spec
(identifier)
(identifier)
(identifier)
(expression_list (int_literal) (int_literal) (int_literal)))))
(package_clause
(package_identifier))
(var_declaration
(var_spec
(identifier)
(expression_list
(int_literal))))
(var_declaration
(var_spec
(identifier)
(identifier)
(expression_list
(int_literal)
(int_literal))))
(var_declaration
(var_spec
(identifier)
(identifier)
(identifier)
(expression_list
(int_literal)
(int_literal)
(int_literal)))))
============================================
================================================================================
Var declarations with types
============================================
================================================================================
package main
var zero int = 0
var one, two uint64 = 1, 2
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(var_declaration (var_spec
(identifier)
(type_identifier)
(expression_list (int_literal))))
(var_declaration (var_spec
(identifier)
(identifier)
(type_identifier)
(expression_list (int_literal) (int_literal)))))
(package_clause
(package_identifier))
(var_declaration
(var_spec
(identifier)
(type_identifier)
(expression_list
(int_literal))))
(var_declaration
(var_spec
(identifier)
(identifier)
(type_identifier)
(expression_list
(int_literal)
(int_literal)))))
============================================
================================================================================
Var declarations with no expressions
============================================
================================================================================
package main
var zero int
var one, two uint64
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(var_declaration (var_spec
(identifier)
(type_identifier)))
(var_declaration (var_spec
(identifier)
(identifier)
(type_identifier))))
(package_clause
(package_identifier))
(var_declaration
(var_spec
(identifier)
(type_identifier)))
(var_declaration
(var_spec
(identifier)
(identifier)
(type_identifier))))
============================================
================================================================================
Grouped var declarations
============================================
================================================================================
package main
@ -178,21 +218,24 @@ var (
one = 1
)
----
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(var_declaration
(var_spec
(identifier)
(expression_list (int_literal)))
(expression_list
(int_literal)))
(var_spec
(identifier)
(expression_list (int_literal)))))
(expression_list
(int_literal)))))
============================================
================================================================================
Function declarations
============================================
================================================================================
package main
@ -200,11 +243,16 @@ func f1() {}
func f2(a File, b, c, d Thing) int {}
func f2() (File, Thing) {}
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 f[A int|string, B ~int, C ~int|~string]()
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
@ -226,20 +274,107 @@ func f2() (result int, err error) {}
(identifier)
(parameter_list)
(parameter_list
(parameter_declaration (type_identifier))
(parameter_declaration (type_identifier)))
(parameter_declaration
(type_identifier))
(parameter_declaration
(type_identifier)))
(block))
(function_declaration
(identifier)
(parameter_list)
(parameter_list
(parameter_declaration (identifier) (type_identifier))
(parameter_declaration (identifier) (type_identifier)))
(block)))
(parameter_declaration
(identifier)
(type_identifier))
(parameter_declaration
(identifier)
(type_identifier)))
(block))
(function_declaration
(identifier)
(parameter_list
(variadic_parameter_declaration
(identifier)
(type_identifier))
(variadic_parameter_declaration
(identifier)
(type_identifier))))
(function_declaration
(identifier)
(type_parameter_list
(parameter_declaration
(identifier)
(identifier)
(type_identifier))
(parameter_declaration
(identifier)
(interface_type))
(parameter_declaration
(identifier)
(generic_type
(type_identifier)
(type_arguments
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))))
(parameter_list
(parameter_declaration
(identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))
(block))
(function_declaration
(identifier)
(type_parameter_list
(parameter_declaration
(identifier)
(identifier)
(type_identifier))
(parameter_declaration
(identifier)
(interface_type))
(parameter_declaration
(identifier)
(generic_type
(type_identifier)
(type_arguments
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))))
(parameter_list
(parameter_declaration
(identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))
(block))
(function_declaration
(identifier)
(type_parameter_list
(parameter_declaration
(identifier)
(ERROR
(identifier))
(type_identifier))
(parameter_declaration
(identifier)
(ERROR)
(type_identifier))
(parameter_declaration
(identifier)
(ERROR
(identifier))
(type_identifier)))
(parameter_list)))
============================================
================================================================================
Single-line function declarations
============================================
================================================================================
package main
@ -247,31 +382,42 @@ func f1() { a() }
func f2() { a(); b() }
func f3() { a(); b(); }
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(call_expression (identifier) (argument_list))))
(call_expression
(identifier)
(argument_list))))
(function_declaration
(identifier)
(parameter_list)
(block
(call_expression (identifier) (argument_list))
(call_expression (identifier) (argument_list))))
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list))))
(function_declaration
(identifier)
(parameter_list)
(block
(call_expression (identifier) (argument_list))
(call_expression (identifier) (argument_list)))))
(call_expression
(identifier)
(argument_list))
(call_expression
(identifier)
(argument_list)))))
============================================
================================================================================
Variadic function declarations
============================================
================================================================================
package main
@ -279,16 +425,18 @@ func f1(a ...*int) {}
func f2(a int, b ...int) {}
func f3(...bool) {}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list
(variadic_parameter_declaration
(identifier)
(pointer_type (type_identifier))))
(pointer_type
(type_identifier))))
(block))
(function_declaration
(identifier)
@ -303,44 +451,54 @@ func f3(...bool) {}
(function_declaration
(identifier)
(parameter_list
(variadic_parameter_declaration (type_identifier)))
(variadic_parameter_declaration
(type_identifier)))
(block)))
============================================
================================================================================
Method declarations
============================================
================================================================================
package main
func (self Person) Equals(other Person) bool {}
func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(method_declaration
(parameter_list
(parameter_declaration (identifier) (type_identifier)))
(parameter_declaration
(identifier)
(type_identifier)))
(field_identifier)
(parameter_list
(parameter_declaration (identifier) (type_identifier)))
(parameter_declaration
(identifier)
(type_identifier)))
(type_identifier)
(block))
(method_declaration
(parameter_list
(parameter_declaration (identifier) (pointer_type (type_identifier))))
(parameter_declaration
(identifier)
(pointer_type
(type_identifier))))
(field_identifier)
(parameter_list
(variadic_parameter_declaration
(identifier)
(parenthesized_type (type_identifier))))
(parenthesized_type
(type_identifier))))
(type_identifier)
(block)))
============================================
================================================================================
Type declarations
============================================
================================================================================
package main
@ -350,12 +508,19 @@ type (
c d
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(type_declaration
(type_spec (type_identifier) (type_identifier)))
(type_spec
(type_identifier)
(type_identifier)))
(type_declaration
(type_spec (type_identifier) (type_identifier))
(type_spec (type_identifier) (type_identifier))))
(type_spec
(type_identifier)
(type_identifier))
(type_spec
(type_identifier)
(type_identifier))))

@ -55,6 +55,38 @@ func main() {
(call_expression (identifier) (argument_list
(identifier))))))))))
============================================
Generic call expressions
============================================
package main
func main() {
a[b](c)
a[b, c](d)
a[b[c], d](e[f])
}
---
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(call_expression
(identifier)
(type_arguments (type_identifier))
(argument_list (identifier)))
(call_expression
(identifier)
(type_arguments (type_identifier) (type_identifier))
(argument_list (identifier)))
(call_expression
(identifier)
(type_arguments
(generic_type (type_identifier) (type_arguments (type_identifier)))
(type_identifier))
(argument_list (index_expression (identifier) (identifier)))))))
============================================
Calls to 'make' and 'new'
============================================

@ -1,6 +1,6 @@
============================================
================================================================================
Int literals
============================================
================================================================================
package main
@ -18,26 +18,60 @@ const (
i11 = 170_141183_460469_231731_687303_715884_105727
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))
(const_spec (identifier) (expression_list (int_literal)))))
============================================
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))
(const_spec
(identifier)
(expression_list
(int_literal)))))
================================================================================
Float literals
============================================
================================================================================
package main
@ -60,31 +94,80 @@ const (
f16 = 0X_1FFFP-16
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))
(const_spec (identifier) (expression_list (float_literal)))))
============================================
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))
(const_spec
(identifier)
(expression_list
(float_literal)))))
================================================================================
Rune literals
============================================
================================================================================
package main
@ -97,21 +180,40 @@ const (
c = '\U01234567'
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec (identifier) (expression_list (rune_literal)))
(const_spec (identifier) (expression_list (rune_literal)))
(const_spec (identifier) (expression_list (rune_literal)))
(const_spec (identifier) (expression_list (rune_literal)))
(const_spec (identifier) (expression_list (rune_literal)))
(const_spec (identifier) (expression_list (rune_literal)))))
============================================
(const_spec
(identifier)
(expression_list
(rune_literal)))
(const_spec
(identifier)
(expression_list
(rune_literal)))
(const_spec
(identifier)
(expression_list
(rune_literal)))
(const_spec
(identifier)
(expression_list
(rune_literal)))
(const_spec
(identifier)
(expression_list
(rune_literal)))
(const_spec
(identifier)
(expression_list
(rune_literal)))))
================================================================================
Imaginary literals
============================================
================================================================================
package main
@ -130,27 +232,64 @@ const (
l = 0x1p-2i
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))
(const_spec (identifier) (expression_list (imaginary_literal)))))
============================================
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))
(const_spec
(identifier)
(expression_list
(imaginary_literal)))))
================================================================================
String literals
============================================
================================================================================
package main
@ -160,18 +299,30 @@ const (
c = "\x0c"
)
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(const_declaration
(const_spec (identifier) (expression_list (interpreted_string_literal)))
(const_spec (identifier) (expression_list (interpreted_string_literal (escape_sequence))))
(const_spec (identifier) (expression_list (interpreted_string_literal (escape_sequence))))))
============================================
(const_spec
(identifier)
(expression_list
(interpreted_string_literal)))
(const_spec
(identifier)
(expression_list
(interpreted_string_literal
(escape_sequence))))
(const_spec
(identifier)
(expression_list
(interpreted_string_literal
(escape_sequence))))))
================================================================================
Slice literals
============================================
================================================================================
package main
@ -184,53 +335,73 @@ const s3 = []string{
"hello",
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(slice_type (type_identifier))
(literal_value)))))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(slice_type (type_identifier))
(literal_value
(element (interpreted_string_literal)))))))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(slice_type (type_identifier))
(literal_value
(element (interpreted_string_literal))
(element (interpreted_string_literal))))))))
============================================
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(slice_type
(type_identifier))
(literal_value)))))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(slice_type
(type_identifier))
(literal_value
(literal_element
(interpreted_string_literal)))))))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(slice_type
(type_identifier))
(literal_value
(literal_element
(interpreted_string_literal))
(literal_element
(interpreted_string_literal))))))))
================================================================================
Array literals with implicit length
============================================
================================================================================
package main
const a1 = [...]int{1, 2, 3}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(implicit_length_array_type (type_identifier))
(literal_value
(element (int_literal))
(element (int_literal))
(element (int_literal))))))))
============================================
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(implicit_length_array_type
(type_identifier))
(literal_value
(literal_element
(int_literal))
(literal_element
(int_literal))
(literal_element
(int_literal))))))))
================================================================================
Map literals
============================================
================================================================================
package main
@ -239,21 +410,34 @@ const s = map[string]string{
"bye": "goodbye",
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(map_type (type_identifier) (type_identifier))
(literal_value
(keyed_element (interpreted_string_literal) (interpreted_string_literal))
(keyed_element (interpreted_string_literal) (interpreted_string_literal))))))))
============================================
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(map_type
(type_identifier)
(type_identifier))
(literal_value
(keyed_element
(literal_element
(interpreted_string_literal))
(literal_element
(interpreted_string_literal)))
(keyed_element
(literal_element
(interpreted_string_literal))
(literal_element
(interpreted_string_literal)))))))))
================================================================================
Struct literals
============================================
================================================================================
package main
@ -266,33 +450,73 @@ const s2 = struct{i int;}{i: 5}
const s3 = time.Time{}
---
const g1 = Foo[float64, Bar[int]] { }
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(type_identifier)
(literal_value
(keyed_element (field_identifier) (interpreted_string_literal))
(keyed_element (field_identifier) (interpreted_string_literal)))))))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(struct_type (field_declaration_list
(field_declaration (field_identifier) (type_identifier))))
(literal_value
(keyed_element (field_identifier) (int_literal)))))))
(const_declaration (const_spec
(identifier)
(expression_list (composite_literal
(qualified_type (package_identifier) (type_identifier))
(literal_value))))))
============================================
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(type_identifier)
(literal_value
(keyed_element
(literal_element
(identifier))
(literal_element
(interpreted_string_literal)))
(keyed_element
(literal_element
(identifier))
(literal_element
(interpreted_string_literal))))))))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(type_identifier))))
(literal_value
(keyed_element
(literal_element
(identifier))
(literal_element
(int_literal))))))))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(qualified_type
(package_identifier)
(type_identifier))
(literal_value)))))
(const_declaration
(const_spec
(identifier)
(expression_list
(composite_literal
(generic_type
(type_identifier)
(type_arguments
(type_identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))
(literal_value))))))
================================================================================
Function literals
============================================
================================================================================
package main
@ -300,18 +524,27 @@ const s1 = func(s string) (int, int) {
return 1, 2
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(const_declaration (const_spec
(identifier)
(expression_list
(func_literal
(parameter_list
(parameter_declaration (identifier) (type_identifier)))
(parameter_list
(parameter_declaration (type_identifier))
(parameter_declaration (type_identifier)))
(block
(return_statement (expression_list (int_literal) (int_literal)))))))))
(package_clause
(package_identifier))
(const_declaration
(const_spec
(identifier)
(expression_list
(func_literal
(parameter_list
(parameter_declaration
(identifier)
(type_identifier)))
(parameter_list
(parameter_declaration
(type_identifier))
(parameter_declaration
(type_identifier)))
(block
(return_statement
(expression_list
(int_literal)
(int_literal)))))))))

@ -1,6 +1,6 @@
============================================
================================================================================
Declaration statements
============================================
================================================================================
package main
@ -9,19 +9,29 @@ func main() {
const x = 5
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(var_declaration
(var_spec (identifier) (expression_list (identifier))))
(const_declaration
(const_spec (identifier) (expression_list (int_literal)))))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(var_declaration
(var_spec
(identifier)
(expression_list
(identifier))))
(const_declaration
(const_spec
(identifier)
(expression_list
(int_literal)))))))
================================================================================
Expression statements
============================================
================================================================================
package main
@ -29,16 +39,23 @@ func main() {
foo(5)
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(call_expression (identifier) (argument_list (int_literal))))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(call_expression
(identifier)
(argument_list
(int_literal))))))
================================================================================
Send statements
============================================
================================================================================
package main
@ -46,16 +63,22 @@ func main() {
foo <- 5
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(send_statement (identifier) (int_literal)))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(send_statement
(identifier)
(int_literal)))))
================================================================================
Increment/Decrement statements
============================================
================================================================================
package main
@ -64,17 +87,23 @@ func main() {
j--
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(inc_statement (identifier))
(dec_statement (identifier)))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(inc_statement
(identifier))
(dec_statement
(identifier)))))
================================================================================
Assignment statements
============================================
================================================================================
package main
@ -94,54 +123,86 @@ func main() {
n ^= 2
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier) (identifier))
(expression_list (int_literal) (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal)))
(assignment_statement
(expression_list (identifier))
(expression_list (int_literal))))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier)
(identifier))
(expression_list
(int_literal)
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal)))
(assignment_statement
(expression_list
(identifier))
(expression_list
(int_literal))))))
================================================================================
Short var declarations
============================================
================================================================================
package main
@ -149,18 +210,26 @@ func main() {
a, b := 1, 2
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(short_var_declaration
(expression_list (identifier) (identifier))
(expression_list (int_literal) (int_literal))))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(short_var_declaration
(expression_list
(identifier)
(identifier))
(expression_list
(int_literal)
(int_literal))))))
================================================================================
If statements
============================================
================================================================================
package main
@ -188,58 +257,64 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(function_declaration
name: (identifier)
parameters: (parameter_list)
body: (block
(if_statement
condition: (identifier)
consequence: (block (call_expression
function: (identifier)
arguments: (argument_list))))
(if_statement
initializer: (short_var_declaration
left: (expression_list (identifier))
right: (expression_list (call_expression
consequence: (block
(call_expression
function: (identifier)
arguments: (argument_list))))
(if_statement
initializer: (short_var_declaration
left: (expression_list
(identifier))
right: (expression_list
(call_expression
function: (identifier)
arguments: (argument_list))))
condition: (identifier)
consequence: (block
(call_expression
function: (identifier)
arguments: (argument_list))))
(if_statement
condition: (identifier)
consequence: (block (call_expression
function: (identifier)
arguments: (argument_list)))
alternative: (block (call_expression
function: (identifier)
arguments: (argument_list))))
consequence: (block
(call_expression
function: (identifier)
arguments: (argument_list)))
alternative: (block
(call_expression
function: (identifier)
arguments: (argument_list))))
(if_statement
condition: (identifier)
consequence: (block (call_expression
function: (identifier)
arguments: (argument_list)))
alternative: (if_statement
condition: (identifier)
consequence: (block (call_expression
consequence: (block
(call_expression
function: (identifier)
arguments: (argument_list)))
alternative: (block (call_expression
function: (identifier)
arguments: (argument_list))))))))
============================================
alternative: (if_statement
condition: (identifier)
consequence: (block
(call_expression
function: (identifier)
arguments: (argument_list)))
alternative: (block
(call_expression
function: (identifier)
arguments: (argument_list))))))))
================================================================================
For statements
============================================
================================================================================
package main
@ -271,48 +346,79 @@ loop2:
}
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(for_statement
(block
(call_expression (identifier) (argument_list))
(goto_statement (label_name))))
(labeled_statement (label_name)
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(for_statement
(for_clause
(short_var_declaration
(expression_list (identifier))
(expression_list (int_literal)))
(binary_expression (identifier) (int_literal))
(inc_statement (identifier)))
(block
(call_expression (identifier) (argument_list))
(break_statement (label_name)))))
(labeled_statement (label_name)
(call_expression
(identifier)
(argument_list))
(goto_statement
(label_name))))
(labeled_statement
(label_name)
(for_statement
(for_clause
(short_var_declaration
(expression_list
(identifier))
(expression_list
(int_literal)))
(binary_expression
(identifier)
(int_literal))
(inc_statement
(identifier)))
(block
(call_expression
(identifier)
(argument_list))
(break_statement
(label_name)))))
(labeled_statement
(label_name)
(for_statement
(for_clause
(binary_expression
(identifier)
(int_literal))
(inc_statement
(identifier)))
(block
(call_expression
(identifier)
(argument_list))
(continue_statement
(label_name)))))
(for_statement
(for_clause
(binary_expression (identifier) (int_literal))
(inc_statement (identifier)))
(for_clause)
(block
(call_expression (identifier) (argument_list))
(continue_statement (label_name)))))
(for_statement
(for_clause)
(block
(call_expression (identifier) (argument_list))
(continue_statement)))
(for_statement
(range_clause (expression_list (identifier)) (identifier))
(block
(call_expression (identifier) (argument_list (identifier)))
(break_statement))))))
(call_expression
(identifier)
(argument_list))
(continue_statement)))
(for_statement
(range_clause
(expression_list
(identifier))
(identifier))
(block
(call_expression
(identifier)
(argument_list
(identifier)))
(break_statement))))))
============================================
================================================================================
Switch statements
============================================
================================================================================
func main() {
switch e {
@ -335,7 +441,7 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(function_declaration
@ -345,13 +451,16 @@ func main() {
(expression_switch_statement
value: (identifier)
(expression_case
value: (expression_list (int_literal) (int_literal))
value: (expression_list
(int_literal)
(int_literal))
(call_expression
function: (identifier)
arguments: (argument_list))
(fallthrough_statement))
(expression_case
value: (expression_list (int_literal))
value: (expression_list
(int_literal))
(call_expression
function: (identifier)
arguments: (argument_list)))
@ -362,19 +471,22 @@ func main() {
(break_statement)))
(expression_switch_statement
(expression_case
value: (expression_list (true))
value: (expression_list
(true))
(return_statement)))
(expression_switch_statement
initializer: (short_var_declaration
left: (expression_list (identifier))
right: (expression_list (call_expression
function: (identifier)
arguments: (argument_list))))
left: (expression_list
(identifier))
right: (expression_list
(call_expression
function: (identifier)
arguments: (argument_list))))
value: (identifier)))))
============================================
================================================================================
Type switch statements
============================================
================================================================================
func main() {
switch e.(type) {
@ -399,7 +511,7 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(function_declaration
@ -415,48 +527,57 @@ func main() {
function: (identifier)
arguments: (argument_list)))
(type_case
type: (pointer_type (type_identifier))
type: (pointer_type
(type_identifier))
(break_statement)))
(type_switch_statement
alias: (expression_list (identifier))
alias: (expression_list
(identifier))
value: (identifier)
(type_case
type: (type_identifier)
(call_expression
function: (identifier)
arguments: (argument_list (interpreted_string_literal))))
arguments: (argument_list
(interpreted_string_literal))))
(type_case
type: (type_identifier)
(call_expression
function: (identifier)
arguments: (argument_list (identifier))))
arguments: (argument_list
(identifier))))
(type_case
type: (type_identifier)
(call_expression
function: (identifier)
arguments: (argument_list (identifier))))
arguments: (argument_list
(identifier))))
(type_case
type: (function_type
parameters: (parameter_list (parameter_declaration
type: (type_identifier)))
parameters: (parameter_list
(parameter_declaration
type: (type_identifier)))
result: (type_identifier))
(call_expression
function: (identifier)
arguments: (argument_list (identifier))))
arguments: (argument_list
(identifier))))
(type_case
type: (type_identifier)
type: (type_identifier)
(call_expression
function: (identifier)
arguments: (argument_list (interpreted_string_literal))))
arguments: (argument_list
(interpreted_string_literal))))
(default_case
(call_expression
function: (identifier)
arguments: (argument_list (interpreted_string_literal))))))))
arguments: (argument_list
(interpreted_string_literal))))))))
============================================
================================================================================
Select statements
============================================
================================================================================
package main
@ -473,10 +594,11 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(package_clause
(package_identifier))
(function_declaration
name: (identifier)
parameters: (parameter_list)
@ -484,34 +606,41 @@ func main() {
(select_statement
(communication_case
communication: (receive_statement
left: (expression_list (identifier))
right: (unary_expression operand: (identifier)))
left: (expression_list
(identifier))
right: (unary_expression
operand: (identifier)))
(call_expression
function: (identifier)
arguments: (argument_list (identifier))))
arguments: (argument_list
(identifier))))
(communication_case
communication: (send_statement
channel: (identifier)
value: (identifier))
(call_expression
function: (identifier)
arguments: (argument_list (int_literal))))
arguments: (argument_list
(int_literal))))
(communication_case
communication: (receive_statement
right: (unary_expression operand: (call_expression
function: (selector_expression
operand: (identifier)
field: (field_identifier))
arguments: (argument_list (int_literal)))))
right: (unary_expression
operand: (call_expression
function: (selector_expression
operand: (identifier)
field: (field_identifier))
arguments: (argument_list
(int_literal)))))
(call_expression
function: (identifier)
arguments: (argument_list (int_literal))))
arguments: (argument_list
(int_literal))))
(default_case
(return_statement))))))
============================================
================================================================================
Go and defer statements
============================================
================================================================================
package main
@ -520,17 +649,31 @@ func main() {
go x.y()
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(defer_statement (call_expression (selector_expression (identifier) (field_identifier)) (argument_list)))
(go_statement (call_expression (selector_expression (identifier) (field_identifier)) (argument_list))))))
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(defer_statement
(call_expression
(selector_expression
(identifier)
(field_identifier))
(argument_list)))
(go_statement
(call_expression
(selector_expression
(identifier)
(field_identifier))
(argument_list))))))
============================================
================================================================================
Nested statement blocks
============================================
================================================================================
func main() {
{
@ -541,16 +684,27 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(function_declaration (identifier) (parameter_list) (block
(block (call_expression (identifier) (argument_list (interpreted_string_literal))))
(block (call_expression (identifier) (argument_list (interpreted_string_literal)))))))
(function_declaration
(identifier)
(parameter_list)
(block
(block
(call_expression
(identifier)
(argument_list
(interpreted_string_literal))))
(block
(call_expression
(identifier)
(argument_list
(interpreted_string_literal)))))))
============================================
================================================================================
Labels at the ends of statement blocks
============================================
================================================================================
func main() {
{
@ -558,19 +712,20 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(function_declaration
name: (identifier)
parameters: (parameter_list)
body: (block (block
(labeled_statement
label: (label_name))))))
body: (block
(block
(labeled_statement
label: (label_name))))))
============================================
================================================================================
Empty statements
============================================
================================================================================
package main
@ -578,16 +733,20 @@ func main() {
;
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(empty_statement))))
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(empty_statement))))
=============================================
================================================================================
Nested control statements
=============================================
================================================================================
package main
@ -601,42 +760,65 @@ func main() {
}
}
---
--------------------------------------------------------------------------------
(source_file
(package_clause (package_identifier))
(function_declaration (identifier) (parameter_list) (block
(for_statement
(range_clause (expression_list (identifier) (identifier)) (identifier))
(block
(call_expression
(func_literal
(parameter_list)
(block
(if_statement
(binary_expression (identifier) (identifier))
(block
(call_expression
(selector_expression (identifier) (field_identifier))
(argument_list
(interpreted_string_literal)
(index_expression (identifier) (identifier))))))))
(argument_list)))))))
============================================
(package_clause
(package_identifier))
(function_declaration
(identifier)
(parameter_list)
(block
(for_statement
(range_clause
(expression_list
(identifier)
(identifier))
(identifier))
(block
(call_expression
(func_literal
(parameter_list)
(block
(if_statement
(binary_expression
(identifier)
(identifier))
(block
(call_expression
(selector_expression
(identifier)
(field_identifier))
(argument_list
(interpreted_string_literal)
(index_expression
(identifier)
(identifier))))))))
(argument_list)))))))
================================================================================
Top-level statements
============================================
================================================================================
foo(5)
x := T { a: b }
---
--------------------------------------------------------------------------------
(source_file
(call_expression (identifier) (argument_list (int_literal)))
(call_expression
(identifier)
(argument_list
(int_literal)))
(short_var_declaration
(expression_list (identifier))
(expression_list
(identifier))
(expression_list
(composite_literal
(type_identifier)
(literal_value (keyed_element (field_identifier) (identifier)))))))
(literal_value
(keyed_element
(literal_element
(identifier))
(literal_element
(identifier))))))))

@ -76,6 +76,13 @@ type s3 struct {
h int `json:"h"`
}
type g1 struct {
normal Array[T]
nested Array[Array[T]]
}
type g2[T, U any, V interface{}, W Foo[Bar[T]]] struct {}
---
(source_file
@ -107,7 +114,47 @@ type s3 struct {
(field_declaration
(field_identifier)
(type_identifier)
(raw_string_literal)))))))
(raw_string_literal))))))
(type_declaration
(type_spec
(type_identifier)
(struct_type
(field_declaration_list
(field_declaration
(field_identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier))))
(field_declaration
(field_identifier)
(generic_type
(type_identifier)
(type_arguments
(generic_type
(type_identifier)
(type_arguments
(type_identifier))))))))))
(type_declaration
(type_spec
(type_identifier)
(type_parameter_list
(parameter_declaration
(identifier)
(identifier)
(type_identifier))
(parameter_declaration
(identifier)
(interface_type))
(parameter_declaration
(identifier)
(generic_type
(type_identifier)
(type_arguments
(generic_type
(type_identifier)
(type_arguments (type_identifier)))))))
(struct_type (field_declaration_list)))))
============================================
Interface types
@ -126,22 +173,26 @@ type i2 interface {
OtherMethod(int, ...bool) bool
}
type SignedInteger interface {
int | int8 | ~uint | ~uint8
}
---
(source_file
(package_clause (package_identifier))
(type_declaration (type_spec
(type_identifier)
(interface_type (method_spec_list))))
(interface_type)))
(type_declaration (type_spec
(type_identifier)
(interface_type (method_spec_list
(interface_type (interface_type_name
(qualified_type (package_identifier) (type_identifier))))))
(type_declaration (type_spec
(type_identifier)
(interface_type (method_spec_list
(type_identifier)
(qualified_type (package_identifier) (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)))
@ -150,7 +201,14 @@ type i2 interface {
(field_identifier)
(parameter_list
(parameter_declaration (type_identifier))
(variadic_parameter_declaration (type_identifier))) (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)))))))
============================================
Map types

@ -82,6 +82,12 @@ module.exports = grammar({
conflicts: $ => [
[$._simple_type, $._expression],
[$.qualified_type, $._expression],
[$.generic_type, $._expression],
[$.generic_type, $._simple_type],
[$.parameter_declaration, $.type_arguments],
[$.parameter_declaration, $._simple_type, $._expression],
[$.parameter_declaration, $.generic_type, $._expression],
[$.parameter_declaration, $._expression],
[$.func_literal, $.function_type],
[$.function_type],
[$.parameter_declaration, $._simple_type],
@ -97,6 +103,8 @@ module.exports = grammar({
rules: {
source_file: $ => repeat(choice(
// Unlike a Go compiler, we accept statements at top-level to enable
// parsing of partial code snippets in documentation (see #63).
seq($._statement, terminator),
seq($._top_level_declaration, optional(terminator)),
)),
@ -194,6 +202,7 @@ module.exports = grammar({
function_declaration: $ => prec.right(1, seq(
'func',
field('name', $.identifier),
field('type_parameters', optional($.type_parameter_list)),
field('parameters', $.parameter_list),
field('result', optional(choice($.parameter_list, $._simple_type))),
field('body', optional($.block))
@ -205,9 +214,16 @@ module.exports = grammar({
field('name', $._field_identifier),
field('parameters', $.parameter_list),
field('result', optional(choice($.parameter_list, $._simple_type))),
field('body', optional($.block))
field('body', $.block)
)),
type_parameter_list: $ => seq(
'[',
commaSep1($.parameter_declaration),
optional(','),
']'
),
parameter_list: $ => seq(
'(',
optional(seq(
@ -218,7 +234,7 @@ module.exports = grammar({
),
parameter_declaration: $ => seq(
field('name', commaSep($.identifier)),
commaSep(field('name', $.identifier)),
field('type', $._type)
),
@ -249,6 +265,7 @@ module.exports = grammar({
type_spec: $ => seq(
field('name', $._type_identifier),
field('type_parameters', optional($.type_parameter_list)),
field('type', $._type)
),
@ -265,6 +282,7 @@ module.exports = grammar({
_simple_type: $ => choice(
prec.dynamic(-1, $._type_identifier),
$.generic_type,
$.qualified_type,
$.pointer_type,
$.struct_type,
@ -276,6 +294,18 @@ module.exports = grammar({
$.function_type
),
generic_type: $ => seq(
field('type', $._type_identifier),
field('type_arguments', $.type_arguments),
),
type_arguments: $ => prec.dynamic(2, seq(
'[',
commaSep1($._type),
optional(','),
']'
)),
pointer_type: $ => prec(PREC.unary, seq('*', $._type)),
array_type: $ => seq(
@ -316,7 +346,7 @@ module.exports = grammar({
field_declaration: $ => seq(
choice(
seq(
field('name', commaSep1($._field_identifier)),
commaSep1(field('name', $._field_identifier)),
field('type', $._type)
),
seq(
@ -332,19 +362,31 @@ module.exports = grammar({
interface_type: $ => seq(
'interface',
$.method_spec_list
),
method_spec_list: $ => seq(
'{',
optional(seq(
choice($._type_identifier, $.qualified_type, $.method_spec),
repeat(seq(terminator, choice($._type_identifier, $.qualified_type, $.method_spec))),
$._interface_body,
repeat(seq(terminator, $._interface_body)),
optional(terminator)
)),
'}'
),
_interface_body: $ => choice(
$.method_spec, $.interface_type_name, $.constraint_elem
),
interface_type_name: $ => choice($._type_identifier, $.qualified_type),
constraint_elem: $ => seq(
$.constraint_term,
repeat(seq('|', $.constraint_term))
),
constraint_term: $ => prec(-1, seq(
optional('~'),
$._type_identifier,
)),
method_spec: $ => seq(
field('name', $._field_identifier),
field('parameters', $.parameter_list),
@ -611,6 +653,7 @@ module.exports = grammar({
$.nil,
$.true,
$.false,
$.iota,
$.parenthesized_expression
),
@ -627,6 +670,7 @@ module.exports = grammar({
),
seq(
field('function', $._expression),
field('type_arguments', optional($.type_arguments)),
field('arguments', $.argument_list)
)
)),
@ -711,6 +755,7 @@ module.exports = grammar({
$.implicit_length_array_type,
$.struct_type,
$._type_identifier,
$.generic_type,
$.qualified_type
)),
field('body', $.literal_value)
@ -718,30 +763,21 @@ module.exports = grammar({
literal_value: $ => seq(
'{',
optional(seq(
choice($.element, $.keyed_element),
repeat(seq(',', choice($.element, $.keyed_element))),
optional(',')
)),
optional(
seq(
commaSep(choice($.literal_element, $.keyed_element)),
optional(','))),
'}'
),
keyed_element: $ => seq(
choice(
seq($._expression, ':'),
seq($.literal_value, ':'),
prec(1, seq($._field_identifier, ':'))
),
choice(
$._expression,
$.literal_value
)
),
literal_element: $ => choice($._expression, $.literal_value),
element: $ => choice(
$._expression,
$.literal_value
),
// In T{k: v}, the key k may be:
// - any expression (when T is a map, slice or array),
// - a field identifier (when T is a struct), or
// - a literal_element (when T is an array).
// The first two cases cannot be distinguished without type information.
keyed_element: $ => seq($.literal_element, ':', $.literal_element),
func_literal: $ => seq(
'func',
@ -802,11 +838,12 @@ module.exports = grammar({
interpreted_string_literal: $ => seq(
'"',
repeat(choice(
token.immediate(prec(1, /[^"\n\\]+/)),
$._interpreted_string_literal_basic_content,
$.escape_sequence
)),
'"'
),
_interpreted_string_literal_basic_content: $ => token.immediate(prec(1, /[^"\n\\]+/)),
escape_sequence: $ => token.immediate(seq(
'\\',
@ -846,6 +883,7 @@ module.exports = grammar({
nil: $ => 'nil',
true: $ => 'true',
false: $ => 'false',
iota: $ => 'iota',
// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ => token(choice(

@ -7,6 +7,10 @@
"parser",
"go"
],
"repository": {
"type": "git",
"url": "https://github.com/tree-sitter/tree-sitter-go.git"
},
"author": "Max Brunsfeld",
"license": "MIT",
"dependencies": {

@ -60,6 +60,7 @@
"|"
"|="
"||"
"~"
] @operator
; Keywords
@ -112,6 +113,7 @@
(true)
(false)
(nil)
(iota)
] @constant.builtin
(comment) @comment

@ -0,0 +1,175 @@
(import_declaration
"import" @structure.anchor
(import_spec_list
"(" @structure.open
")" @structure.close
)
)
(function_declaration
"func" @structure.anchor
body: (block
"{" @structure.open
"}" @structure.close
)
)
(function_declaration
(identifier) @structure.anchor
(parameter_list
"(" @structure.open
("," @structure.separator (_))*
")" @structure.close
)
)
(method_declaration
"func" @structure.anchor
body: (block
"{" @structure.open
"}" @structure.close
)
)
(call_expression
function: (_) @structure.anchor
(argument_list
"(" @structure.open
("," @structure.separator (_))*
","? @structure.separator
")" @structure.close
)
)
(composite_literal
type: (_) @structure.anchor
body: (literal_value
"{" @structure.open
("," @structure.separator (_)?)*
"}" @structure.close
)
)
(literal_value
"{" @structure.anchor
("," @structure.separator (_)?)*
"}" @structure.close
)
(if_statement
["if" "else"] @structure.anchor
(block
"{" @structure.open
"}" @structure.close
)
)
(if_statement
"else" @structure.anchor
(if_statement
"if"
(block
"{" @structure.open
"}" @structure.close
)
)
)
(expression_switch_statement
"switch" @structure.anchor
"{" @structure.open
"}" @structure.close
)
(expression_switch_statement
(expression_case
"case" @structure.anchor
":" @structure.open
)
.
[
(expression_case "case" @structure.limit)
(default_case "default" @structure.limit)
]
)
(expression_switch_statement
(default_case "default" @structure.anchor)
"}" @structure.limit
)
(type_switch_statement
"switch" @structure.anchor
"{" @structure.open
"}" @structure.close
)
(type_switch_statement
(type_case
"case" @structure.anchor
":" @structure.open
)
.
[
(type_case "case" @structure.limit)
(default_case "default" @structure.limit)
]
)
(select_statement
"select" @structure.anchor
"{" @structure.open
"}" @structure.close
)
(func_literal
"func" @structure.anchor
(block
"{" @structure.open
"}" @structure.close
)
)
(for_statement
"for" @structure.anchor
(block
"{" @structure.open
"}" @structure.close
)
)
(type_declaration
"type" @structure.anchor
(type_spec
(struct_type
(field_declaration_list
"{" @structure.open
"}" @structure.close
)
)
)
)
(struct_type
"struct" @structure.anchor
(field_declaration_list
"{" @structure.open
"}" @structure.close
)
)
(type_declaration
"type" @structure.anchor
(type_spec
(interface_type
"{" @structure.open
"}" @structure.close
)
)
)
(interface_type
"interface" @structure.anchor
"{" @structure.open
"}" @structure.close
)

@ -526,6 +526,22 @@
"name": "identifier"
}
},
{
"type": "FIELD",
"name": "type_parameters",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_parameter_list"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "parameters",
@ -641,21 +657,63 @@
"type": "FIELD",
"name": "body",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "block"
},
{
"type": "BLANK"
}
]
"type": "SYMBOL",
"name": "block"
}
}
]
}
},
"type_parameter_list": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "parameter_declaration"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "parameter_declaration"
}
]
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
"parameter_list": {
"type": "SEQ",
"members": [
@ -749,41 +807,45 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
]
}
}
]
}
]
},
{
"type": "BLANK"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
@ -933,6 +995,22 @@
"name": "_type_identifier"
}
},
{
"type": "FIELD",
"name": "type_parameters",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_parameter_list"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "type",
@ -1034,6 +1112,10 @@
"name": "_type_identifier"
}
},
{
"type": "SYMBOL",
"name": "generic_type"
},
{
"type": "SYMBOL",
"name": "qualified_type"
@ -1072,6 +1154,81 @@
}
]
},
"generic_type": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "_type_identifier"
}
},
{
"type": "FIELD",
"name": "type_arguments",
"content": {
"type": "SYMBOL",
"name": "type_arguments"
}
}
]
},
"type_arguments": {
"type": "PREC_DYNAMIC",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_type"
}
]
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
}
},
"pointer_type": {
"type": "PREC",
"value": 6,
@ -1263,33 +1420,37 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_field_identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "_field_identifier"
}
]
}
}
]
}
]
}
}
]
},
{
"type": "FIELD",
@ -1362,15 +1523,6 @@
"type": "STRING",
"value": "interface"
},
{
"type": "SYMBOL",
"name": "method_spec_list"
}
]
},
"method_spec_list": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
@ -1382,21 +1534,8 @@
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_identifier"
},
{
"type": "SYMBOL",
"name": "qualified_type"
},
{
"type": "SYMBOL",
"name": "method_spec"
}
]
"type": "SYMBOL",
"name": "_interface_body"
},
{
"type": "REPEAT",
@ -1415,23 +1554,10 @@
"value": ";"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_identifier"
},
{
"type": "SYMBOL",
"name": "qualified_type"
},
{
"type": "SYMBOL",
"name": "method_spec"
}
]
},
{
"type": "SYMBOL",
"name": "_interface_body"
}
]
}
@ -1470,6 +1596,86 @@
}
]
},
"_interface_body": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "method_spec"
},
{
"type": "SYMBOL",
"name": "interface_type_name"
},
{
"type": "SYMBOL",
"name": "constraint_elem"
}
]
},
"interface_type_name": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_type_identifier"
},
{
"type": "SYMBOL",
"name": "qualified_type"
}
]
},
"constraint_elem": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "constraint_term"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "SYMBOL",
"name": "constraint_term"
}
]
}
}
]
},
"constraint_term": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "~"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_type_identifier"
}
]
}
},
"method_spec": {
"type": "SEQ",
"members": [
@ -2967,6 +3173,10 @@
"type": "SYMBOL",
"name": "false"
},
{
"type": "SYMBOL",
"name": "iota"
},
{
"type": "SYMBOL",
"name": "parenthesized_expression"
@ -3047,6 +3257,22 @@
"name": "_expression"
}
},
{
"type": "FIELD",
"name": "type_arguments",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "type_arguments"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "arguments",
@ -3494,6 +3720,10 @@
"type": "SYMBOL",
"name": "_type_identifier"
},
{
"type": "SYMBOL",
"name": "generic_type"
},
{
"type": "SYMBOL",
"name": "qualified_type"
@ -3529,40 +3759,53 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "element"
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "literal_element"
},
{
"type": "SYMBOL",
"name": "keyed_element"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "literal_element"
},
{
"type": "SYMBOL",
"name": "keyed_element"
}
]
}
]
}
}
]
},
{
"type": "SYMBOL",
"name": "keyed_element"
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "element"
},
{
"type": "SYMBOL",
"name": "keyed_element"
}
]
}
]
}
},
{
"type": "CHOICE",
"members": [
@ -3588,82 +3831,33 @@
}
]
},
"keyed_element": {
"type": "SEQ",
"literal_element": {
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "literal_value"
},
{
"type": "STRING",
"value": ":"
}
]
},
{
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_field_identifier"
},
{
"type": "STRING",
"value": ":"
}
]
}
}
]
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "literal_value"
}
]
"type": "SYMBOL",
"name": "literal_value"
}
]
},
"element": {
"type": "CHOICE",
"keyed_element": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
"name": "literal_element"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "literal_value"
"name": "literal_element"
}
]
},
@ -4159,15 +4353,8 @@
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\"\\n\\\\]+"
}
}
"type": "SYMBOL",
"name": "_interpreted_string_literal_basic_content"
},
{
"type": "SYMBOL",
@ -4182,6 +4369,17 @@
}
]
},
"_interpreted_string_literal_basic_content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[^\"\\n\\\\]+"
}
}
},
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": {
@ -6438,6 +6636,10 @@
"type": "STRING",
"value": "false"
},
"iota": {
"type": "STRING",
"value": "iota"
},
"comment": {
"type": "TOKEN",
"content": {
@ -6496,6 +6698,32 @@
"qualified_type",
"_expression"
],
[
"generic_type",
"_expression"
],
[
"generic_type",
"_simple_type"
],
[
"parameter_declaration",
"type_arguments"
],
[
"parameter_declaration",
"_simple_type",
"_expression"
],
[
"parameter_declaration",
"generic_type",
"_expression"
],
[
"parameter_declaration",
"_expression"
],
[
"func_literal",
"function_type"

@ -47,6 +47,10 @@
"type": "interpreted_string_literal",
"named": true
},
{
"type": "iota",
"named": true
},
{
"type": "nil",
"named": true
@ -135,6 +139,10 @@
"type": "function_type",
"named": true
},
{
"type": "generic_type",
"named": true
},
{
"type": "interface_type",
"named": true
@ -551,6 +559,16 @@
"named": true
}
]
},
"type_arguments": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_arguments",
"named": true
}
]
}
}
},
@ -622,6 +640,10 @@
"type": "array_type",
"named": true
},
{
"type": "generic_type",
"named": true
},
{
"type": "implicit_length_array_type",
"named": true
@ -706,22 +728,22 @@
}
},
{
"type": "continue_statement",
"type": "constraint_elem",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"multiple": true,
"required": true,
"types": [
{
"type": "label_name",
"type": "constraint_term",
"named": true
}
]
}
},
{
"type": "dec_statement",
"type": "constraint_term",
"named": true,
"fields": {},
"children": {
@ -729,29 +751,29 @@
"required": true,
"types": [
{
"type": "_expression",
"type": "type_identifier",
"named": true
}
]
}
},
{
"type": "default_case",
"type": "continue_statement",
"named": true,
"fields": {},
"children": {
"multiple": true,
"multiple": false,
"required": false,
"types": [
{
"type": "_statement",
"type": "label_name",
"named": true
}
]
}
},
{
"type": "defer_statement",
"type": "dec_statement",
"named": true,
"fields": {},
"children": {
@ -766,12 +788,22 @@
}
},
{
"type": "dot",
"type": "default_case",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "_statement",
"named": true
}
]
}
},
{
"type": "element",
"type": "defer_statement",
"named": true,
"fields": {},
"children": {
@ -781,14 +813,15 @@
{
"type": "_expression",
"named": true
},
{
"type": "literal_value",
"named": true
}
]
}
},
{
"type": "dot",
"named": true,
"fields": {}
},
{
"type": "empty_statement",
"named": true,
@ -888,10 +921,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "field_identifier",
"named": true
@ -1104,6 +1133,16 @@
"named": true
}
]
},
"type_parameters": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_parameter_list",
"named": true
}
]
}
}
},
@ -1137,6 +1176,32 @@
}
}
},
{
"type": "generic_type",
"named": true,
"fields": {
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "type_identifier",
"named": true
}
]
},
"type_arguments": {
"multiple": false,
"required": true,
"types": [
{
"type": "type_arguments",
"named": true
}
]
}
}
},
{
"type": "go_statement",
"named": true,
@ -1350,12 +1415,39 @@
"type": "interface_type",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "constraint_elem",
"named": true
},
{
"type": "interface_type_name",
"named": true
},
{
"type": "method_spec",
"named": true
}
]
}
},
{
"type": "interface_type_name",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "method_spec_list",
"type": "qualified_type",
"named": true
},
{
"type": "type_identifier",
"named": true
}
]
@ -1385,15 +1477,7 @@
"required": true,
"types": [
{
"type": "_expression",
"named": true
},
{
"type": "field_identifier",
"named": true
},
{
"type": "literal_value",
"type": "literal_element",
"named": true
}
]
@ -1425,6 +1509,25 @@
]
}
},
{
"type": "literal_element",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "_expression",
"named": true
},
{
"type": "literal_value",
"named": true
}
]
}
},
{
"type": "literal_value",
"named": true,
@ -1434,11 +1537,11 @@
"required": false,
"types": [
{
"type": "element",
"type": "keyed_element",
"named": true
},
{
"type": "keyed_element",
"type": "literal_element",
"named": true
}
]
@ -1476,7 +1579,7 @@
"fields": {
"body": {
"multiple": false,
"required": false,
"required": true,
"types": [
{
"type": "block",
@ -1570,29 +1673,6 @@
}
}
},
{
"type": "method_spec_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "method_spec",
"named": true
},
{
"type": "qualified_type",
"named": true
},
{
"type": "type_identifier",
"named": true
}
]
}
},
{
"type": "package_clause",
"named": true,
@ -1616,10 +1696,6 @@
"multiple": true,
"required": false,
"types": [
{
"type": ",",
"named": false
},
{
"type": "identifier",
"named": true
@ -2026,6 +2102,21 @@
}
}
},
{
"type": "type_arguments",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "_type",
"named": true
}
]
}
},
{
"type": "type_assertion_expression",
"named": true,
@ -2127,6 +2218,21 @@
]
}
},
{
"type": "type_parameter_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "parameter_declaration",
"named": true
}
]
}
},
{
"type": "type_spec",
"named": true,
@ -2150,6 +2256,16 @@
"named": true
}
]
},
"type_parameters": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_parameter_list",
"named": true
}
]
}
}
},
@ -2625,6 +2741,10 @@
"type": "interface",
"named": false
},
{
"type": "iota",
"named": true
},
{
"type": "label_name",
"named": true
@ -2708,5 +2828,9 @@
{
"type": "}",
"named": false
},
{
"type": "~",
"named": false
}
]

File diff suppressed because it is too large Load Diff

@ -102,8 +102,8 @@ struct TSLanguage {
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char **symbol_names;
const char **field_names;
const char * const *symbol_names;
const char * const *field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
@ -123,6 +123,7 @@ struct TSLanguage {
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
const TSStateId *primary_state_ids;
};
/*