mirror of https://github.com/Wilfred/difftastic/
Use tree-sitter-go from crates.io
parent
15b9590db5
commit
7e8974e295
@ -1 +0,0 @@
|
||||
../tree-sitter-go/queries/highlights.scm
|
||||
@ -1 +0,0 @@
|
||||
tree-sitter-go/src
|
||||
@ -1,39 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.{json,toml,yml,gyp}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.rs]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{c,cc,h}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.{py,pyi}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.swift]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.go]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
|
||||
[Makefile]
|
||||
indent_style = tab
|
||||
indent_size = 8
|
||||
@ -1,11 +0,0 @@
|
||||
* text eol=lf
|
||||
|
||||
src/*.json linguist-generated
|
||||
src/parser.c linguist-generated
|
||||
src/tree_sitter/* linguist-generated
|
||||
|
||||
bindings/** linguist-generated
|
||||
binding.gyp linguist-generated
|
||||
setup.py linguist-generated
|
||||
Makefile linguist-generated
|
||||
Package.swift linguist-generated
|
||||
@ -1,8 +0,0 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
commit-message:
|
||||
prefix: "ci"
|
||||
@ -1,82 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths:
|
||||
- grammar.js
|
||||
- src/**
|
||||
- test/**
|
||||
- bindings/**
|
||||
- binding.gyp
|
||||
pull_request:
|
||||
paths:
|
||||
- grammar.js
|
||||
- src/**
|
||||
- test/**
|
||||
- bindings/**
|
||||
- binding.gyp
|
||||
|
||||
concurrency:
|
||||
group: ${{github.workflow}}-${{github.ref}}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test parser
|
||||
runs-on: ${{matrix.os}}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-14]
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up tree-sitter
|
||||
uses: tree-sitter/setup-action/cli@v1
|
||||
- name: Set up examples
|
||||
run: |-
|
||||
git clone https://github.com/golang/go examples/go --single-branch --depth=1 --filter=blob:none
|
||||
git clone https://github.com/moby/moby examples/moby --single-branch --depth=1 --filter=blob:none
|
||||
- name: Run tests
|
||||
uses: tree-sitter/parser-test-action@v2
|
||||
with:
|
||||
test-rust: ${{runner.os == 'Linux'}}
|
||||
- name: Parse examples
|
||||
id: examples
|
||||
continue-on-error: true
|
||||
uses: tree-sitter/parse-action@v4
|
||||
with:
|
||||
files: examples/**/*.go
|
||||
invalid-files: |
|
||||
examples/go/src/cmd/compile/internal/syntax/testdata/*.go
|
||||
examples/go/src/cmd/compile/internal/types2/testdata/local/issue47996.go
|
||||
examples/go/src/go/parser/testdata/issue42951/not_a_file.go/invalid.go
|
||||
examples/go/src/internal/types/testdata/**/*.go
|
||||
examples/go/test/bombad.go
|
||||
examples/go/test/const2.go
|
||||
examples/go/test/ddd1.go
|
||||
examples/go/test/fixedbugs/**/*.go
|
||||
examples/go/test/import5.go
|
||||
examples/go/test/makenew.go
|
||||
examples/go/test/method4.dir/prog.go
|
||||
examples/go/test/method7.go
|
||||
examples/go/test/slice3err.go
|
||||
examples/go/test/switch2.go
|
||||
examples/go/test/syntax/chan.go
|
||||
examples/go/test/syntax/chan1.go
|
||||
examples/go/test/syntax/ddd.go
|
||||
examples/go/test/syntax/else.go
|
||||
examples/go/test/syntax/if.go
|
||||
examples/go/test/syntax/import.go
|
||||
examples/go/test/syntax/initvar.go
|
||||
examples/go/test/syntax/semi*.go
|
||||
examples/go/test/syntax/vareq.go
|
||||
examples/go/test/syntax/vareq1.go
|
||||
examples/go/test/typeparam/issue*.go
|
||||
examples/moby/daemon/logger/journald/read_test.go
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: steps.examples.outputs.failures != ''
|
||||
with:
|
||||
name: failures-${{matrix.os}}
|
||||
path: ${{steps.examples.outputs.failures}}
|
||||
@ -1,26 +0,0 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
paths:
|
||||
- grammar.js
|
||||
pull_request:
|
||||
paths:
|
||||
- grammar.js
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
cache: npm
|
||||
node-version: ${{vars.NODE_VERSION}}
|
||||
- name: Install modules
|
||||
run: npm ci --legacy-peer-deps
|
||||
- name: Run ESLint
|
||||
run: npm run lint
|
||||
@ -1,23 +0,0 @@
|
||||
name: Publish packages
|
||||
|
||||
on:
|
||||
push:
|
||||
tags: ["*"]
|
||||
|
||||
concurrency:
|
||||
group: ${{github.workflow}}-${{github.ref}}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
npm:
|
||||
uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main
|
||||
secrets:
|
||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||
crates:
|
||||
uses: tree-sitter/workflows/.github/workflows/package-crates.yml@main
|
||||
secrets:
|
||||
CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}}
|
||||
pypi:
|
||||
uses: tree-sitter/workflows/.github/workflows/package-pypi.yml@main
|
||||
secrets:
|
||||
PYPI_API_TOKEN: ${{secrets.PYPI_API_TOKEN}}
|
||||
@ -1,38 +0,0 @@
|
||||
# Rust artifacts
|
||||
Cargo.lock
|
||||
target/
|
||||
|
||||
# Node artifacts
|
||||
build/
|
||||
prebuilds/
|
||||
node_modules/
|
||||
*.tgz
|
||||
|
||||
# Swift artifacts
|
||||
.build/
|
||||
|
||||
# Go artifacts
|
||||
go.sum
|
||||
_obj/
|
||||
|
||||
# Python artifacts
|
||||
.venv/
|
||||
dist/
|
||||
*.egg-info
|
||||
*.whl
|
||||
|
||||
# C artifacts
|
||||
*.a
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
*.dll
|
||||
*.pc
|
||||
|
||||
# Example dirs
|
||||
/examples/*/
|
||||
|
||||
# Grammar volatiles
|
||||
*.wasm
|
||||
*.obj
|
||||
*.o
|
||||
@ -1,26 +0,0 @@
|
||||
[package]
|
||||
name = "tree-sitter-go"
|
||||
description = "Go grammar for tree-sitter"
|
||||
version = "0.21.0"
|
||||
authors = [
|
||||
"Max Brunsfeld <maxbrunsfeld@gmail.com>",
|
||||
"Amaan Qureshi <amaanq12@gmail.com>",
|
||||
]
|
||||
license = "MIT"
|
||||
keywords = ["incremental", "parsing", "tree-sitter", "go"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-go"
|
||||
edition = "2021"
|
||||
autoexamples = false
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = ">=0.21.0"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0.90"
|
||||
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Max Brunsfeld
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -1,111 +0,0 @@
|
||||
VERSION := 0.21.0
|
||||
|
||||
LANGUAGE_NAME := tree-sitter-go
|
||||
|
||||
# repository
|
||||
SRC_DIR := src
|
||||
|
||||
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
|
||||
|
||||
ifeq ($(PARSER_URL),)
|
||||
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
|
||||
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
|
||||
PARSER_URL := $(subst :,/,$(PARSER_URL))
|
||||
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
|
||||
endif
|
||||
endif
|
||||
|
||||
TS ?= tree-sitter
|
||||
|
||||
# ABI versioning
|
||||
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
|
||||
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
|
||||
|
||||
# install directory layout
|
||||
PREFIX ?= /usr/local
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
PCLIBDIR ?= $(LIBDIR)/pkgconfig
|
||||
|
||||
# object files
|
||||
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c))
|
||||
|
||||
# flags
|
||||
ARFLAGS := rcs
|
||||
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
|
||||
|
||||
# OS-specific bits
|
||||
ifeq ($(OS),Windows_NT)
|
||||
$(error "Windows is not supported")
|
||||
else ifeq ($(shell uname),Darwin)
|
||||
SOEXT = dylib
|
||||
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
|
||||
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
|
||||
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
|
||||
ifneq ($(ADDITIONAL_LIBS),)
|
||||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
|
||||
endif
|
||||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_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 ($(ADDITIONAL_LIBS),)
|
||||
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
|
||||
endif
|
||||
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
|
||||
endif
|
||||
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
|
||||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
|
||||
endif
|
||||
|
||||
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
|
||||
|
||||
lib$(LANGUAGE_NAME).a: $(OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
|
||||
ifneq ($(STRIP),)
|
||||
$(STRIP) $@
|
||||
endif
|
||||
|
||||
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
|
||||
sed -e 's|@URL@|$(PARSER_URL)|' \
|
||||
-e 's|@VERSION@|$(VERSION)|' \
|
||||
-e 's|@LIBDIR@|$(LIBDIR)|' \
|
||||
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
|
||||
-e 's|@REQUIRES@|$(REQUIRES)|' \
|
||||
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
|
||||
-e 's|=$(PREFIX)|=$${prefix}|' \
|
||||
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
|
||||
|
||||
$(SRC_DIR)/parser.c: grammar.js
|
||||
$(TS) generate --no-bindings
|
||||
|
||||
install: all
|
||||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
|
||||
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
|
||||
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
|
||||
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
|
||||
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
|
||||
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
|
||||
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
|
||||
|
||||
uninstall:
|
||||
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
|
||||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
|
||||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
|
||||
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
|
||||
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
|
||||
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
|
||||
|
||||
test:
|
||||
$(TS) test
|
||||
$(TS) parse examples/* --quiet --time
|
||||
|
||||
.PHONY: all install uninstall clean test
|
||||
@ -1,46 +0,0 @@
|
||||
// swift-tools-version:5.3
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "TreeSitterGo",
|
||||
products: [
|
||||
.library(name: "TreeSitterGo", targets: ["TreeSitterGo"]),
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(name: "TreeSitterGo",
|
||||
path: ".",
|
||||
exclude: [
|
||||
"Cargo.toml",
|
||||
"Makefile",
|
||||
"binding.gyp",
|
||||
"bindings/c",
|
||||
"bindings/go",
|
||||
"bindings/node",
|
||||
"bindings/python",
|
||||
"bindings/rust",
|
||||
"prebuilds",
|
||||
"grammar.js",
|
||||
"package.json",
|
||||
"package-lock.json",
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"test",
|
||||
"examples",
|
||||
".editorconfig",
|
||||
".github",
|
||||
".gitignore",
|
||||
".gitattributes",
|
||||
".gitmodules",
|
||||
],
|
||||
sources: [
|
||||
"src/parser.c",
|
||||
],
|
||||
resources: [
|
||||
.copy("queries")
|
||||
],
|
||||
publicHeadersPath: "bindings/swift",
|
||||
cSettings: [.headerSearchPath("src")])
|
||||
],
|
||||
cLanguageStandard: .c11
|
||||
)
|
||||
@ -1,17 +0,0 @@
|
||||
# tree-sitter-go
|
||||
|
||||
[![CI][ci]](https://github.com/tree-sitter/tree-sitter-go/actions/workflows/ci.yml)
|
||||
[![discord][discord]](https://discord.gg/w7nTvsVJhm)
|
||||
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org)
|
||||
[![crates][crates]](https://crates.io/crates/tree-sitter-go)
|
||||
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-go)
|
||||
[![pypi][pypi]](https://pypi.org/project/tree-sitter-go)
|
||||
|
||||
[Go](https://go.dev/ref/spec) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter).
|
||||
|
||||
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter/tree-sitter-go/ci.yml?logo=github&label=CI
|
||||
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord
|
||||
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix
|
||||
[npm]: https://img.shields.io/npm/v/tree-sitter-go?logo=npm
|
||||
[crates]: https://img.shields.io/crates/v/tree-sitter-go?logo=rust
|
||||
[pypi]: https://img.shields.io/pypi/v/tree-sitter-go?logo=pypi&logoColor=ffd242
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_go_binding",
|
||||
"dependencies": [
|
||||
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
||||
],
|
||||
"include_dirs": [
|
||||
"src",
|
||||
],
|
||||
"sources": [
|
||||
"bindings/node/binding.cc",
|
||||
"src/parser.c",
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c11",
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#ifndef TREE_SITTER_GO_H_
|
||||
#define TREE_SITTER_GO_H_
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const TSLanguage *tree_sitter_go(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_GO_H_
|
||||
@ -1,11 +0,0 @@
|
||||
prefix=@PREFIX@
|
||||
libdir=@LIBDIR@
|
||||
includedir=@INCLUDEDIR@
|
||||
|
||||
Name: tree-sitter-go
|
||||
Description: Go grammar for tree-sitter
|
||||
URL: @URL@
|
||||
Version: @VERSION@
|
||||
Requires: @REQUIRES@
|
||||
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-go
|
||||
Cflags: -I${includedir}
|
||||
@ -1,12 +0,0 @@
|
||||
package tree_sitter_go
|
||||
|
||||
// #cgo CFLAGS: -std=c11 -fPIC
|
||||
// #include "../../src/parser.c"
|
||||
import "C"
|
||||
|
||||
import "unsafe"
|
||||
|
||||
// Get the tree-sitter Language for this grammar.
|
||||
func Language() unsafe.Pointer {
|
||||
return unsafe.Pointer(C.tree_sitter_go())
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
package tree_sitter_go_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
tree_sitter "github.com/smacker/go-tree-sitter"
|
||||
"github.com/tree-sitter/tree-sitter-go"
|
||||
)
|
||||
|
||||
func TestCanLoadGrammar(t *testing.T) {
|
||||
language := tree_sitter.NewLanguage(tree_sitter_go.Language())
|
||||
if language == nil {
|
||||
t.Errorf("Error loading Go grammar")
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
module github.com/tree-sitter/tree-sitter-go
|
||||
|
||||
go 1.22
|
||||
|
||||
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
|
||||
@ -1,20 +0,0 @@
|
||||
#include <napi.h>
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
extern "C" TSLanguage *tree_sitter_go();
|
||||
|
||||
// "tree-sitter", "language" hashed with BLAKE2
|
||||
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
||||
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
||||
};
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
exports["name"] = Napi::String::New(env, "go");
|
||||
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_go());
|
||||
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
||||
exports["language"] = language;
|
||||
return exports;
|
||||
}
|
||||
|
||||
NODE_API_MODULE(tree_sitter_go_binding, Init)
|
||||
@ -1,28 +0,0 @@
|
||||
type BaseNode = {
|
||||
type: string;
|
||||
named: boolean;
|
||||
};
|
||||
|
||||
type ChildNode = {
|
||||
multiple: boolean;
|
||||
required: boolean;
|
||||
types: BaseNode[];
|
||||
};
|
||||
|
||||
type NodeInfo =
|
||||
| (BaseNode & {
|
||||
subtypes: BaseNode[];
|
||||
})
|
||||
| (BaseNode & {
|
||||
fields: { [name: string]: ChildNode };
|
||||
children: ChildNode[];
|
||||
});
|
||||
|
||||
type Language = {
|
||||
name: string;
|
||||
language: unknown;
|
||||
nodeTypeInfo: NodeInfo[];
|
||||
};
|
||||
|
||||
declare const language: Language;
|
||||
export = language;
|
||||
@ -1,7 +0,0 @@
|
||||
const root = require("path").join(__dirname, "..", "..");
|
||||
|
||||
module.exports = require("node-gyp-build")(root);
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -1,5 +0,0 @@
|
||||
"Go grammar for tree-sitter"
|
||||
|
||||
from ._binding import language
|
||||
|
||||
__all__ = ["language"]
|
||||
@ -1 +0,0 @@
|
||||
def language() -> int: ...
|
||||
@ -1,27 +0,0 @@
|
||||
#include <Python.h>
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
TSLanguage *tree_sitter_go(void);
|
||||
|
||||
static PyObject* _binding_language(PyObject *self, PyObject *args) {
|
||||
return PyLong_FromVoidPtr(tree_sitter_go());
|
||||
}
|
||||
|
||||
static PyMethodDef methods[] = {
|
||||
{"language", _binding_language, METH_NOARGS,
|
||||
"Get the tree-sitter language for this grammar."},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef module = {
|
||||
.m_base = PyModuleDef_HEAD_INIT,
|
||||
.m_name = "_binding",
|
||||
.m_doc = NULL,
|
||||
.m_size = -1,
|
||||
.m_methods = methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit__binding(void) {
|
||||
return PyModule_Create(&module);
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
fn main() {
|
||||
let src_dir = std::path::Path::new("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config.std("c11").include(src_dir);
|
||||
|
||||
let parser_path = src_dir.join("parser.c");
|
||||
c_config.file(&parser_path);
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
|
||||
c_config.compile("tree-sitter-go");
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
//! This crate provides Go language support for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! Typically, you will use the [language][language func] function to add this language to a
|
||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
//!
|
||||
//! ```
|
||||
//! use tree_sitter::Parser;
|
||||
//!
|
||||
//! let code = r#"
|
||||
//! func add(a, b int) int {
|
||||
//! return a + b
|
||||
//! }
|
||||
//! "#;
|
||||
//! let mut parser = Parser::new();
|
||||
//! parser.set_language(&tree_sitter_go::language()).expect("Error loading Go grammar");
|
||||
//! let tree = parser.parse(code, None).unwrap();
|
||||
//! assert!(!tree.root_node().has_error());
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_go() -> Language;
|
||||
}
|
||||
|
||||
/// Get the tree-sitter [Language][] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_go() }
|
||||
}
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
///
|
||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
||||
|
||||
/// The syntax highlighting query for this language.
|
||||
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
|
||||
|
||||
/// The symbol tagging query for this language.
|
||||
pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn test_can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(&super::language())
|
||||
.expect("Error loading Go grammar");
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#ifndef TREE_SITTER_GO_H_
|
||||
#define TREE_SITTER_GO_H_
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
const TSLanguage *tree_sitter_go(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_GO_H_
|
||||
@ -1,19 +0,0 @@
|
||||
// run
|
||||
|
||||
// Copyright 2015 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
x := 0
|
||||
func() {
|
||||
x = 1
|
||||
}()
|
||||
func() {
|
||||
if x != 1 {
|
||||
panic("x != 1")
|
||||
}
|
||||
}()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,955 +0,0 @@
|
||||
/**
|
||||
* @file Go grammar for tree-sitter
|
||||
* @author Max Brunsfeld <maxbrunsfeld@gmail.com>
|
||||
* @author Amaan Qureshi <amaanq12@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/// <reference types="tree-sitter-cli/dsl" />
|
||||
// @ts-check
|
||||
|
||||
const PREC = {
|
||||
primary: 7,
|
||||
unary: 6,
|
||||
multiplicative: 5,
|
||||
additive: 4,
|
||||
comparative: 3,
|
||||
and: 2,
|
||||
or: 1,
|
||||
composite_literal: -1,
|
||||
};
|
||||
|
||||
const multiplicativeOperators = ['*', '/', '%', '<<', '>>', '&', '&^'];
|
||||
const additiveOperators = ['+', '-', '|', '^'];
|
||||
const comparativeOperators = ['==', '!=', '<', '<=', '>', '>='];
|
||||
const assignmentOperators = multiplicativeOperators.concat(additiveOperators).map(operator => operator + '=').concat('=');
|
||||
|
||||
|
||||
const newline = '\n';
|
||||
const terminator = choice(newline, ';', '\0');
|
||||
|
||||
const hexDigit = /[0-9a-fA-F]/;
|
||||
const octalDigit = /[0-7]/;
|
||||
const decimalDigit = /[0-9]/;
|
||||
const binaryDigit = /[01]/;
|
||||
|
||||
const hexDigits = seq(hexDigit, repeat(seq(optional('_'), hexDigit)));
|
||||
const octalDigits = seq(octalDigit, repeat(seq(optional('_'), octalDigit)));
|
||||
const decimalDigits = seq(decimalDigit, repeat(seq(optional('_'), decimalDigit)));
|
||||
const binaryDigits = seq(binaryDigit, repeat(seq(optional('_'), binaryDigit)));
|
||||
|
||||
const hexLiteral = seq('0', choice('x', 'X'), optional('_'), hexDigits);
|
||||
const octalLiteral = seq('0', optional(choice('o', 'O')), optional('_'), octalDigits);
|
||||
const decimalLiteral = choice('0', seq(/[1-9]/, optional(seq(optional('_'), decimalDigits))));
|
||||
const binaryLiteral = seq('0', choice('b', 'B'), optional('_'), binaryDigits);
|
||||
|
||||
const intLiteral = choice(binaryLiteral, decimalLiteral, octalLiteral, hexLiteral);
|
||||
|
||||
const decimalExponent = seq(choice('e', 'E'), optional(choice('+', '-')), decimalDigits);
|
||||
const decimalFloatLiteral = choice(
|
||||
seq(decimalDigits, '.', optional(decimalDigits), optional(decimalExponent)),
|
||||
seq(decimalDigits, decimalExponent),
|
||||
seq('.', decimalDigits, optional(decimalExponent)),
|
||||
);
|
||||
|
||||
const hexExponent = seq(choice('p', 'P'), optional(choice('+', '-')), decimalDigits);
|
||||
const hexMantissa = choice(
|
||||
seq(optional('_'), hexDigits, '.', optional(hexDigits)),
|
||||
seq(optional('_'), hexDigits),
|
||||
seq('.', hexDigits),
|
||||
);
|
||||
const hexFloatLiteral = seq('0', choice('x', 'X'), hexMantissa, hexExponent);
|
||||
|
||||
const floatLiteral = choice(decimalFloatLiteral, hexFloatLiteral);
|
||||
|
||||
const imaginaryLiteral = seq(choice(decimalDigits, intLiteral, floatLiteral), 'i');
|
||||
|
||||
module.exports = grammar({
|
||||
name: 'go',
|
||||
|
||||
extras: $ => [
|
||||
$.comment,
|
||||
/\s/,
|
||||
],
|
||||
|
||||
inline: $ => [
|
||||
$._type,
|
||||
$._type_identifier,
|
||||
$._field_identifier,
|
||||
$._package_identifier,
|
||||
$._top_level_declaration,
|
||||
$._string_literal,
|
||||
$._interface_elem,
|
||||
],
|
||||
|
||||
word: $ => $.identifier,
|
||||
|
||||
conflicts: $ => [
|
||||
[$._simple_type, $._expression],
|
||||
[$._simple_type, $.generic_type, $._expression],
|
||||
[$.qualified_type, $._expression],
|
||||
[$.generic_type, $._simple_type],
|
||||
[$.parameter_declaration, $._simple_type],
|
||||
[$.type_parameter_declaration, $._simple_type, $._expression],
|
||||
[$.type_parameter_declaration, $._expression],
|
||||
[$.type_parameter_declaration, $._simple_type, $.generic_type, $._expression],
|
||||
],
|
||||
|
||||
supertypes: $ => [
|
||||
$._expression,
|
||||
$._type,
|
||||
$._simple_type,
|
||||
$._statement,
|
||||
$._simple_statement,
|
||||
],
|
||||
|
||||
rules: {
|
||||
source_file: $ => seq(
|
||||
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, terminator),
|
||||
)),
|
||||
optional($._top_level_declaration),
|
||||
),
|
||||
|
||||
_top_level_declaration: $ => choice(
|
||||
$.package_clause,
|
||||
$.function_declaration,
|
||||
$.method_declaration,
|
||||
$.import_declaration,
|
||||
),
|
||||
|
||||
package_clause: $ => seq(
|
||||
'package',
|
||||
$._package_identifier,
|
||||
),
|
||||
|
||||
import_declaration: $ => seq(
|
||||
'import',
|
||||
choice(
|
||||
$.import_spec,
|
||||
$.import_spec_list,
|
||||
),
|
||||
),
|
||||
|
||||
import_spec: $ => seq(
|
||||
optional(field('name', choice(
|
||||
$.dot,
|
||||
$.blank_identifier,
|
||||
$._package_identifier,
|
||||
))),
|
||||
field('path', $._string_literal),
|
||||
),
|
||||
dot: _ => '.',
|
||||
blank_identifier: _ => '_',
|
||||
|
||||
import_spec_list: $ => seq(
|
||||
'(',
|
||||
optional(seq(
|
||||
$.import_spec,
|
||||
repeat(seq(terminator, $.import_spec)),
|
||||
optional(terminator),
|
||||
)),
|
||||
')',
|
||||
),
|
||||
|
||||
_declaration: $ => choice(
|
||||
$.const_declaration,
|
||||
$.type_declaration,
|
||||
$.var_declaration,
|
||||
),
|
||||
|
||||
const_declaration: $ => seq(
|
||||
'const',
|
||||
choice(
|
||||
$.const_spec,
|
||||
seq(
|
||||
'(',
|
||||
repeat(seq($.const_spec, terminator)),
|
||||
')',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const_spec: $ => prec.left(seq(
|
||||
field('name', commaSep1($.identifier)),
|
||||
optional(seq(
|
||||
optional(field('type', $._type)),
|
||||
'=',
|
||||
field('value', $.expression_list),
|
||||
)),
|
||||
)),
|
||||
|
||||
var_declaration: $ => seq(
|
||||
'var',
|
||||
choice(
|
||||
$.var_spec,
|
||||
seq(
|
||||
'(',
|
||||
repeat(seq($.var_spec, terminator)),
|
||||
')',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
var_spec: $ => seq(
|
||||
field('name', commaSep1($.identifier)),
|
||||
choice(
|
||||
seq(
|
||||
field('type', $._type),
|
||||
optional(seq('=', field('value', $.expression_list))),
|
||||
),
|
||||
seq('=', field('value', $.expression_list)),
|
||||
),
|
||||
),
|
||||
|
||||
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)),
|
||||
)),
|
||||
|
||||
method_declaration: $ => prec.right(1, seq(
|
||||
'func',
|
||||
field('receiver', $.parameter_list),
|
||||
field('name', $._field_identifier),
|
||||
field('parameters', $.parameter_list),
|
||||
field('result', optional(choice($.parameter_list, $._simple_type))),
|
||||
field('body', optional($.block)),
|
||||
)),
|
||||
|
||||
type_parameter_list: $ => seq(
|
||||
'[',
|
||||
commaSep1($.type_parameter_declaration),
|
||||
optional(','),
|
||||
']',
|
||||
),
|
||||
|
||||
type_parameter_declaration: $ => seq(
|
||||
commaSep1(field('name', $.identifier)),
|
||||
field('type', alias($.type_elem, $.type_constraint)),
|
||||
),
|
||||
|
||||
parameter_list: $ => seq(
|
||||
'(',
|
||||
optional(seq(
|
||||
commaSep(choice($.parameter_declaration, $.variadic_parameter_declaration)),
|
||||
optional(','),
|
||||
)),
|
||||
')',
|
||||
),
|
||||
|
||||
parameter_declaration: $ => prec.left(seq(
|
||||
commaSep(field('name', $.identifier)),
|
||||
field('type', $._type),
|
||||
)),
|
||||
|
||||
variadic_parameter_declaration: $ => seq(
|
||||
field('name', optional($.identifier)),
|
||||
'...',
|
||||
field('type', $._type),
|
||||
),
|
||||
|
||||
type_alias: $ => seq(
|
||||
field('name', $._type_identifier),
|
||||
'=',
|
||||
field('type', $._type),
|
||||
),
|
||||
|
||||
type_declaration: $ => seq(
|
||||
'type',
|
||||
choice(
|
||||
$.type_spec,
|
||||
$.type_alias,
|
||||
seq(
|
||||
'(',
|
||||
repeat(seq(choice($.type_spec, $.type_alias), terminator)),
|
||||
')',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
type_spec: $ => seq(
|
||||
field('name', $._type_identifier),
|
||||
field('type_parameters', optional($.type_parameter_list)),
|
||||
field('type', $._type),
|
||||
),
|
||||
|
||||
field_name_list: $ => commaSep1($._field_identifier),
|
||||
|
||||
expression_list: $ => commaSep1($._expression),
|
||||
|
||||
_type: $ => choice(
|
||||
$._simple_type,
|
||||
$.parenthesized_type,
|
||||
),
|
||||
|
||||
parenthesized_type: $ => seq('(', $._type, ')'),
|
||||
|
||||
_simple_type: $ => choice(
|
||||
prec.dynamic(-1, $._type_identifier),
|
||||
$.generic_type,
|
||||
$.qualified_type,
|
||||
$.pointer_type,
|
||||
$.struct_type,
|
||||
$.interface_type,
|
||||
$.array_type,
|
||||
$.slice_type,
|
||||
$.map_type,
|
||||
$.channel_type,
|
||||
$.function_type,
|
||||
$.negated_type,
|
||||
),
|
||||
|
||||
generic_type: $ => prec.dynamic(1, seq(
|
||||
field('type', choice($._type_identifier, $.qualified_type, $.negated_type)),
|
||||
field('type_arguments', $.type_arguments),
|
||||
)),
|
||||
|
||||
type_arguments: $ => prec.dynamic(2, seq(
|
||||
'[',
|
||||
commaSep1($.type_elem),
|
||||
optional(','),
|
||||
']',
|
||||
)),
|
||||
|
||||
pointer_type: $ => prec(PREC.unary, seq('*', $._type)),
|
||||
|
||||
array_type: $ => prec.right(seq(
|
||||
'[',
|
||||
field('length', $._expression),
|
||||
']',
|
||||
field('element', $._type),
|
||||
)),
|
||||
|
||||
implicit_length_array_type: $ => seq(
|
||||
'[',
|
||||
'...',
|
||||
']',
|
||||
field('element', $._type),
|
||||
),
|
||||
|
||||
slice_type: $ => prec.right(seq(
|
||||
'[',
|
||||
']',
|
||||
field('element', $._type),
|
||||
)),
|
||||
|
||||
struct_type: $ => seq(
|
||||
'struct',
|
||||
$.field_declaration_list,
|
||||
),
|
||||
|
||||
negated_type: $ => prec.left(seq(
|
||||
'~',
|
||||
$._type,
|
||||
)),
|
||||
|
||||
field_declaration_list: $ => seq(
|
||||
'{',
|
||||
optional(seq(
|
||||
$.field_declaration,
|
||||
repeat(seq(terminator, $.field_declaration)),
|
||||
optional(terminator),
|
||||
)),
|
||||
'}',
|
||||
),
|
||||
|
||||
field_declaration: $ => seq(
|
||||
choice(
|
||||
seq(
|
||||
commaSep1(field('name', $._field_identifier)),
|
||||
field('type', $._type),
|
||||
),
|
||||
seq(
|
||||
optional('*'),
|
||||
field('type', choice(
|
||||
$._type_identifier,
|
||||
$.qualified_type,
|
||||
$.generic_type,
|
||||
)),
|
||||
),
|
||||
),
|
||||
field('tag', optional($._string_literal)),
|
||||
),
|
||||
|
||||
interface_type: $ => seq(
|
||||
'interface',
|
||||
'{',
|
||||
optional(seq(
|
||||
$._interface_elem,
|
||||
repeat(seq(terminator, $._interface_elem)),
|
||||
optional(terminator),
|
||||
)),
|
||||
'}',
|
||||
),
|
||||
|
||||
_interface_elem: $ => choice(
|
||||
$.method_elem,
|
||||
$.type_elem,
|
||||
),
|
||||
|
||||
method_elem: $ => seq(
|
||||
field('name', $._field_identifier),
|
||||
field('parameters', $.parameter_list),
|
||||
field('result', optional(choice($.parameter_list, $._simple_type))),
|
||||
),
|
||||
|
||||
type_elem: $ => sep1($._type, '|'),
|
||||
|
||||
map_type: $ => prec.right(seq(
|
||||
'map',
|
||||
'[',
|
||||
field('key', $._type),
|
||||
']',
|
||||
field('value', $._type),
|
||||
)),
|
||||
|
||||
channel_type: $ => prec.left(choice(
|
||||
seq('chan', field('value', $._type)),
|
||||
seq('chan', '<-', field('value', $._type)),
|
||||
prec(PREC.unary, seq('<-', 'chan', field('value', $._type))),
|
||||
)),
|
||||
|
||||
function_type: $ => prec.right(seq(
|
||||
'func',
|
||||
field('parameters', $.parameter_list),
|
||||
field('result', optional(choice($.parameter_list, $._simple_type))),
|
||||
)),
|
||||
|
||||
block: $ => seq(
|
||||
'{',
|
||||
optional($._statement_list),
|
||||
'}',
|
||||
),
|
||||
|
||||
_statement_list: $ => choice(
|
||||
seq(
|
||||
$._statement,
|
||||
repeat(seq(terminator, $._statement)),
|
||||
optional(seq(
|
||||
terminator,
|
||||
optional(alias($.empty_labeled_statement, $.labeled_statement)),
|
||||
)),
|
||||
),
|
||||
alias($.empty_labeled_statement, $.labeled_statement),
|
||||
),
|
||||
|
||||
_statement: $ => choice(
|
||||
$._declaration,
|
||||
$._simple_statement,
|
||||
$.return_statement,
|
||||
$.go_statement,
|
||||
$.defer_statement,
|
||||
$.if_statement,
|
||||
$.for_statement,
|
||||
$.expression_switch_statement,
|
||||
$.type_switch_statement,
|
||||
$.select_statement,
|
||||
$.labeled_statement,
|
||||
$.fallthrough_statement,
|
||||
$.break_statement,
|
||||
$.continue_statement,
|
||||
$.goto_statement,
|
||||
$.block,
|
||||
$.empty_statement,
|
||||
),
|
||||
|
||||
empty_statement: _ => ';',
|
||||
|
||||
_simple_statement: $ => choice(
|
||||
$.expression_statement,
|
||||
$.send_statement,
|
||||
$.inc_statement,
|
||||
$.dec_statement,
|
||||
$.assignment_statement,
|
||||
$.short_var_declaration,
|
||||
),
|
||||
|
||||
expression_statement: $ => $._expression,
|
||||
|
||||
send_statement: $ => seq(
|
||||
field('channel', $._expression),
|
||||
'<-',
|
||||
field('value', $._expression),
|
||||
),
|
||||
|
||||
receive_statement: $ => seq(
|
||||
optional(seq(
|
||||
field('left', $.expression_list),
|
||||
choice('=', ':='),
|
||||
)),
|
||||
field('right', $._expression),
|
||||
),
|
||||
|
||||
inc_statement: $ => seq(
|
||||
$._expression,
|
||||
'++',
|
||||
),
|
||||
|
||||
dec_statement: $ => seq(
|
||||
$._expression,
|
||||
'--',
|
||||
),
|
||||
|
||||
assignment_statement: $ => seq(
|
||||
field('left', $.expression_list),
|
||||
field('operator', choice(...assignmentOperators)),
|
||||
field('right', $.expression_list),
|
||||
),
|
||||
|
||||
short_var_declaration: $ => seq(
|
||||
// TODO: this should really only allow identifier lists, but that causes
|
||||
// conflicts between identifiers as expressions vs identifiers here.
|
||||
field('left', $.expression_list),
|
||||
':=',
|
||||
field('right', $.expression_list),
|
||||
),
|
||||
|
||||
labeled_statement: $ => seq(
|
||||
field('label', alias($.identifier, $.label_name)),
|
||||
':',
|
||||
$._statement,
|
||||
),
|
||||
|
||||
empty_labeled_statement: $ => seq(
|
||||
field('label', alias($.identifier, $.label_name)),
|
||||
':',
|
||||
),
|
||||
|
||||
// This is a hack to prevent `fallthrough_statement` from being parsed as
|
||||
// a single token. For consistency with `break_statement` etc it should
|
||||
// be parsed as a parent node that *contains* a `fallthrough` token.
|
||||
fallthrough_statement: _ => prec.left('fallthrough'),
|
||||
|
||||
break_statement: $ => seq('break', optional(alias($.identifier, $.label_name))),
|
||||
|
||||
continue_statement: $ => seq('continue', optional(alias($.identifier, $.label_name))),
|
||||
|
||||
goto_statement: $ => seq('goto', alias($.identifier, $.label_name)),
|
||||
|
||||
return_statement: $ => seq('return', optional($.expression_list)),
|
||||
|
||||
go_statement: $ => seq('go', $._expression),
|
||||
|
||||
defer_statement: $ => seq('defer', $._expression),
|
||||
|
||||
if_statement: $ => seq(
|
||||
'if',
|
||||
optional(seq(
|
||||
field('initializer', $._simple_statement),
|
||||
';',
|
||||
)),
|
||||
field('condition', $._expression),
|
||||
field('consequence', $.block),
|
||||
optional(seq(
|
||||
'else',
|
||||
field('alternative', choice($.block, $.if_statement)),
|
||||
)),
|
||||
),
|
||||
|
||||
for_statement: $ => seq(
|
||||
'for',
|
||||
optional(choice($._expression, $.for_clause, $.range_clause)),
|
||||
field('body', $.block),
|
||||
),
|
||||
|
||||
for_clause: $ => seq(
|
||||
field('initializer', optional($._simple_statement)),
|
||||
';',
|
||||
field('condition', optional($._expression)),
|
||||
';',
|
||||
field('update', optional($._simple_statement)),
|
||||
),
|
||||
|
||||
range_clause: $ => seq(
|
||||
optional(seq(
|
||||
field('left', $.expression_list),
|
||||
choice('=', ':='),
|
||||
)),
|
||||
'range',
|
||||
field('right', $._expression),
|
||||
),
|
||||
|
||||
expression_switch_statement: $ => seq(
|
||||
'switch',
|
||||
optional(seq(
|
||||
field('initializer', $._simple_statement),
|
||||
';',
|
||||
)),
|
||||
field('value', optional($._expression)),
|
||||
'{',
|
||||
repeat(choice($.expression_case, $.default_case)),
|
||||
'}',
|
||||
),
|
||||
|
||||
expression_case: $ => seq(
|
||||
'case',
|
||||
field('value', $.expression_list),
|
||||
':',
|
||||
optional($._statement_list),
|
||||
),
|
||||
|
||||
default_case: $ => seq(
|
||||
'default',
|
||||
':',
|
||||
optional($._statement_list),
|
||||
),
|
||||
|
||||
type_switch_statement: $ => seq(
|
||||
'switch',
|
||||
$._type_switch_header,
|
||||
'{',
|
||||
repeat(choice($.type_case, $.default_case)),
|
||||
'}',
|
||||
),
|
||||
|
||||
_type_switch_header: $ => seq(
|
||||
optional(seq(
|
||||
field('initializer', $._simple_statement),
|
||||
';',
|
||||
)),
|
||||
optional(seq(field('alias', $.expression_list), ':=')),
|
||||
field('value', $._expression),
|
||||
'.',
|
||||
'(',
|
||||
'type',
|
||||
')',
|
||||
),
|
||||
|
||||
type_case: $ => seq(
|
||||
'case',
|
||||
field('type', commaSep1($._type)),
|
||||
':',
|
||||
optional($._statement_list),
|
||||
),
|
||||
|
||||
select_statement: $ => seq(
|
||||
'select',
|
||||
'{',
|
||||
repeat(choice($.communication_case, $.default_case)),
|
||||
'}',
|
||||
),
|
||||
|
||||
communication_case: $ => seq(
|
||||
'case',
|
||||
field('communication', choice($.send_statement, $.receive_statement)),
|
||||
':',
|
||||
optional($._statement_list),
|
||||
),
|
||||
|
||||
_expression: $ => choice(
|
||||
$.unary_expression,
|
||||
$.binary_expression,
|
||||
$.selector_expression,
|
||||
$.index_expression,
|
||||
$.slice_expression,
|
||||
$.call_expression,
|
||||
$.type_assertion_expression,
|
||||
$.type_conversion_expression,
|
||||
$.type_instantiation_expression,
|
||||
$.identifier,
|
||||
alias(choice('new', 'make'), $.identifier),
|
||||
$.composite_literal,
|
||||
$.func_literal,
|
||||
$._string_literal,
|
||||
$.int_literal,
|
||||
$.float_literal,
|
||||
$.imaginary_literal,
|
||||
$.rune_literal,
|
||||
$.nil,
|
||||
$.true,
|
||||
$.false,
|
||||
$.iota,
|
||||
$.parenthesized_expression,
|
||||
),
|
||||
|
||||
parenthesized_expression: $ => seq(
|
||||
'(',
|
||||
$._expression,
|
||||
')',
|
||||
),
|
||||
|
||||
call_expression: $ => prec(PREC.primary, choice(
|
||||
seq(
|
||||
field('function', alias(choice('new', 'make'), $.identifier)),
|
||||
field('arguments', alias($.special_argument_list, $.argument_list)),
|
||||
),
|
||||
seq(
|
||||
field('function', $._expression),
|
||||
field('type_arguments', optional($.type_arguments)),
|
||||
field('arguments', $.argument_list),
|
||||
),
|
||||
)),
|
||||
|
||||
variadic_argument: $ => prec.right(seq(
|
||||
$._expression,
|
||||
'...',
|
||||
)),
|
||||
|
||||
special_argument_list: $ => seq(
|
||||
'(',
|
||||
$._type,
|
||||
repeat(seq(',', $._expression)),
|
||||
optional(','),
|
||||
')',
|
||||
),
|
||||
|
||||
argument_list: $ => seq(
|
||||
'(',
|
||||
optional(seq(
|
||||
choice($._expression, $.variadic_argument),
|
||||
repeat(seq(',', choice($._expression, $.variadic_argument))),
|
||||
optional(','),
|
||||
)),
|
||||
')',
|
||||
),
|
||||
|
||||
selector_expression: $ => prec(PREC.primary, seq(
|
||||
field('operand', $._expression),
|
||||
'.',
|
||||
field('field', $._field_identifier),
|
||||
)),
|
||||
|
||||
index_expression: $ => prec(PREC.primary, seq(
|
||||
field('operand', $._expression),
|
||||
'[',
|
||||
field('index', $._expression),
|
||||
']',
|
||||
)),
|
||||
|
||||
slice_expression: $ => prec(PREC.primary, seq(
|
||||
field('operand', $._expression),
|
||||
'[',
|
||||
choice(
|
||||
seq(
|
||||
field('start', optional($._expression)),
|
||||
':',
|
||||
field('end', optional($._expression)),
|
||||
),
|
||||
seq(
|
||||
field('start', optional($._expression)),
|
||||
':',
|
||||
field('end', $._expression),
|
||||
':',
|
||||
field('capacity', $._expression),
|
||||
),
|
||||
),
|
||||
']',
|
||||
)),
|
||||
|
||||
type_assertion_expression: $ => prec(PREC.primary, seq(
|
||||
field('operand', $._expression),
|
||||
'.',
|
||||
'(',
|
||||
field('type', $._type),
|
||||
')',
|
||||
)),
|
||||
|
||||
type_conversion_expression: $ => prec.dynamic(-1, seq(
|
||||
field('type', $._type),
|
||||
'(',
|
||||
field('operand', $._expression),
|
||||
optional(','),
|
||||
')',
|
||||
)),
|
||||
|
||||
type_instantiation_expression: $ => prec.dynamic(-1, seq(
|
||||
field('type', $._type),
|
||||
'[',
|
||||
commaSep1($._type),
|
||||
optional(','),
|
||||
']',
|
||||
)),
|
||||
|
||||
composite_literal: $ => prec(PREC.composite_literal, seq(
|
||||
field('type', choice(
|
||||
$.map_type,
|
||||
$.slice_type,
|
||||
$.array_type,
|
||||
$.implicit_length_array_type,
|
||||
$.struct_type,
|
||||
$._type_identifier,
|
||||
$.generic_type,
|
||||
$.qualified_type,
|
||||
)),
|
||||
field('body', $.literal_value),
|
||||
)),
|
||||
|
||||
literal_value: $ => seq(
|
||||
'{',
|
||||
optional(
|
||||
seq(
|
||||
commaSep(choice($.literal_element, $.keyed_element)),
|
||||
optional(','))),
|
||||
'}',
|
||||
),
|
||||
|
||||
literal_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',
|
||||
field('parameters', $.parameter_list),
|
||||
field('result', optional(choice($.parameter_list, $._simple_type))),
|
||||
field('body', $.block),
|
||||
),
|
||||
|
||||
unary_expression: $ => prec(PREC.unary, seq(
|
||||
field('operator', choice('+', '-', '!', '^', '*', '&', '<-')),
|
||||
field('operand', $._expression),
|
||||
)),
|
||||
|
||||
binary_expression: $ => {
|
||||
const table = [
|
||||
[PREC.multiplicative, choice(...multiplicativeOperators)],
|
||||
[PREC.additive, choice(...additiveOperators)],
|
||||
[PREC.comparative, choice(...comparativeOperators)],
|
||||
[PREC.and, '&&'],
|
||||
[PREC.or, '||'],
|
||||
];
|
||||
|
||||
return choice(...table.map(([precedence, operator]) =>
|
||||
// @ts-ignore
|
||||
prec.left(precedence, seq(
|
||||
field('left', $._expression),
|
||||
// @ts-ignore
|
||||
field('operator', operator),
|
||||
field('right', $._expression),
|
||||
)),
|
||||
));
|
||||
},
|
||||
|
||||
qualified_type: $ => seq(
|
||||
field('package', $._package_identifier),
|
||||
'.',
|
||||
field('name', $._type_identifier),
|
||||
),
|
||||
|
||||
identifier: _ => /[_\p{XID_Start}][_\p{XID_Continue}]*/,
|
||||
|
||||
_type_identifier: $ => alias($.identifier, $.type_identifier),
|
||||
_field_identifier: $ => alias($.identifier, $.field_identifier),
|
||||
_package_identifier: $ => alias($.identifier, $.package_identifier),
|
||||
|
||||
_string_literal: $ => choice(
|
||||
$.raw_string_literal,
|
||||
$.interpreted_string_literal,
|
||||
),
|
||||
|
||||
raw_string_literal: _ => token(seq(
|
||||
'`',
|
||||
repeat(/[^`]/),
|
||||
'`',
|
||||
)),
|
||||
|
||||
interpreted_string_literal: $ => seq(
|
||||
'"',
|
||||
repeat(choice(
|
||||
$._interpreted_string_literal_basic_content,
|
||||
$.escape_sequence,
|
||||
)),
|
||||
token.immediate('"'),
|
||||
),
|
||||
_interpreted_string_literal_basic_content: _ => token.immediate(prec(1, /[^"\n\\]+/)),
|
||||
|
||||
escape_sequence: _ => token.immediate(seq(
|
||||
'\\',
|
||||
choice(
|
||||
/[^xuU]/,
|
||||
/\d{2,3}/,
|
||||
/x[0-9a-fA-F]{2,}/,
|
||||
/u[0-9a-fA-F]{4}/,
|
||||
/U[0-9a-fA-F]{8}/,
|
||||
),
|
||||
)),
|
||||
|
||||
int_literal: _ => token(intLiteral),
|
||||
|
||||
float_literal: _ => token(floatLiteral),
|
||||
|
||||
imaginary_literal: _ => token(imaginaryLiteral),
|
||||
|
||||
rune_literal: _ => token(seq(
|
||||
'\'',
|
||||
choice(
|
||||
/[^'\\]/,
|
||||
seq(
|
||||
'\\',
|
||||
choice(
|
||||
seq('x', hexDigit, hexDigit),
|
||||
seq(octalDigit, octalDigit, octalDigit),
|
||||
seq('u', hexDigit, hexDigit, hexDigit, hexDigit),
|
||||
seq('U', hexDigit, hexDigit, hexDigit, hexDigit, hexDigit, hexDigit, hexDigit, hexDigit),
|
||||
seq(choice('a', 'b', 'f', 'n', 'r', 't', 'v', '\\', '\'', '"')),
|
||||
),
|
||||
),
|
||||
),
|
||||
'\'',
|
||||
)),
|
||||
|
||||
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(
|
||||
seq('//', /.*/),
|
||||
seq(
|
||||
'/*',
|
||||
/[^*]*\*+([^/*][^*]*\*+)*/,
|
||||
'/',
|
||||
),
|
||||
)),
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Creates a rule to match one or more occurrences of `rule` separated by `sep`
|
||||
*
|
||||
* @param {RuleOrLiteral} rule
|
||||
*
|
||||
* @param {RuleOrLiteral} separator
|
||||
*
|
||||
* @return {SeqRule}
|
||||
*
|
||||
*/
|
||||
function sep1(rule, separator) {
|
||||
return seq(rule, repeat(seq(separator, rule)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a rule to match one or more of the rules separated by a comma
|
||||
*
|
||||
* @param {Rule} rule
|
||||
*
|
||||
* @return {SeqRule}
|
||||
*
|
||||
*/
|
||||
function commaSep1(rule) {
|
||||
return seq(rule, repeat(seq(',', rule)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a rule to optionally match one or more of the rules separated by a comma
|
||||
*
|
||||
* @param {Rule} rule
|
||||
*
|
||||
* @return {ChoiceRule}
|
||||
*
|
||||
*/
|
||||
function commaSep(rule) {
|
||||
return optional(commaSep1(rule));
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,106 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-go",
|
||||
"version": "0.21.0",
|
||||
"description": "Go grammar for tree-sitter",
|
||||
"repository": "github:tree-sitter/tree-sitter-go",
|
||||
"license": "MIT",
|
||||
"author": "Max Brunsfeld <maxbrunsfeld@gmail.com>",
|
||||
"contributors": [
|
||||
"Amaan Qureshi <amaanq12@gmail.com>"
|
||||
],
|
||||
"main": "bindings/node",
|
||||
"types": "bindings/node",
|
||||
"keywords": [
|
||||
"incremental",
|
||||
"parsing",
|
||||
"tree-sitter",
|
||||
"go"
|
||||
],
|
||||
"files": [
|
||||
"grammar.js",
|
||||
"binding.gyp",
|
||||
"prebuilds/**",
|
||||
"bindings/node/*",
|
||||
"queries/*",
|
||||
"src/**"
|
||||
],
|
||||
"dependencies": {
|
||||
"node-addon-api": "^8.0.0",
|
||||
"node-gyp-build": "^4.8.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"tree-sitter": "^0.21.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"tree_sitter": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"tree-sitter-cli": "^0.22.2",
|
||||
"prebuildify": "^6.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"install": "node-gyp-build",
|
||||
"prebuildify": "prebuildify --napi --strip",
|
||||
"build": "tree-sitter generate --no-bindings",
|
||||
"build-wasm": "tree-sitter build --wasm",
|
||||
"lint": "eslint grammar.js",
|
||||
"parse": "tree-sitter parse",
|
||||
"test": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.go",
|
||||
"file-types": [
|
||||
"go"
|
||||
],
|
||||
"highlights": "queries/highlights.scm",
|
||||
"tags": "queries/tags.scm"
|
||||
}
|
||||
],
|
||||
"eslintConfig": {
|
||||
"env": {
|
||||
"commonjs": true,
|
||||
"es2021": true
|
||||
},
|
||||
"extends": "google",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"arrow-parens": "off",
|
||||
"camel-case": "off",
|
||||
"indent": [
|
||||
"error",
|
||||
2,
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"max-len": [
|
||||
"error",
|
||||
{
|
||||
"code": 160,
|
||||
"ignoreComments": true,
|
||||
"ignoreUrls": true,
|
||||
"ignoreStrings": true
|
||||
}
|
||||
],
|
||||
"spaced-comment": [
|
||||
"warn",
|
||||
"always",
|
||||
{
|
||||
"line": {
|
||||
"markers": [
|
||||
"/"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=42", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "tree-sitter-go"
|
||||
description = "Go grammar for tree-sitter"
|
||||
version = "0.21.0"
|
||||
keywords = ["incremental", "parsing", "tree-sitter", "go"]
|
||||
classifiers = [
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Topic :: Software Development :: Compilers",
|
||||
"Topic :: Text Processing :: Linguistic",
|
||||
"Typing :: Typed",
|
||||
]
|
||||
authors = [
|
||||
{ name = "Max Brunsfeld", email = "maxbrunsfeld@gmail.com" },
|
||||
{ name = "Amaan Qureshi", email = "amaanq12@gmail.com" },
|
||||
]
|
||||
requires-python = ">=3.8"
|
||||
license.text = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/tree-sitter/tree-sitter-go"
|
||||
|
||||
[project.optional-dependencies]
|
||||
core = ["tree-sitter~=0.21"]
|
||||
|
||||
[tool.cibuildwheel]
|
||||
build = "cp38-*"
|
||||
build-frontend = "build"
|
||||
@ -1,123 +0,0 @@
|
||||
; Function calls
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
|
||||
(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: (selector_expression
|
||||
field: (field_identifier) @function.method))
|
||||
|
||||
; Function definitions
|
||||
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
|
||||
(method_declaration
|
||||
name: (field_identifier) @function.method)
|
||||
|
||||
; Identifiers
|
||||
|
||||
(type_identifier) @type
|
||||
(field_identifier) @property
|
||||
(identifier) @variable
|
||||
|
||||
; Operators
|
||||
|
||||
[
|
||||
"--"
|
||||
"-"
|
||||
"-="
|
||||
":="
|
||||
"!"
|
||||
"!="
|
||||
"..."
|
||||
"*"
|
||||
"*"
|
||||
"*="
|
||||
"/"
|
||||
"/="
|
||||
"&"
|
||||
"&&"
|
||||
"&="
|
||||
"%"
|
||||
"%="
|
||||
"^"
|
||||
"^="
|
||||
"+"
|
||||
"++"
|
||||
"+="
|
||||
"<-"
|
||||
"<"
|
||||
"<<"
|
||||
"<<="
|
||||
"<="
|
||||
"="
|
||||
"=="
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
"|"
|
||||
"|="
|
||||
"||"
|
||||
"~"
|
||||
] @operator
|
||||
|
||||
; Keywords
|
||||
|
||||
[
|
||||
"break"
|
||||
"case"
|
||||
"chan"
|
||||
"const"
|
||||
"continue"
|
||||
"default"
|
||||
"defer"
|
||||
"else"
|
||||
"fallthrough"
|
||||
"for"
|
||||
"func"
|
||||
"go"
|
||||
"goto"
|
||||
"if"
|
||||
"import"
|
||||
"interface"
|
||||
"map"
|
||||
"package"
|
||||
"range"
|
||||
"return"
|
||||
"select"
|
||||
"struct"
|
||||
"switch"
|
||||
"type"
|
||||
"var"
|
||||
] @keyword
|
||||
|
||||
; Literals
|
||||
|
||||
[
|
||||
(interpreted_string_literal)
|
||||
(raw_string_literal)
|
||||
(rune_literal)
|
||||
] @string
|
||||
|
||||
(escape_sequence) @escape
|
||||
|
||||
[
|
||||
(int_literal)
|
||||
(float_literal)
|
||||
(imaginary_literal)
|
||||
] @number
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
(nil)
|
||||
(iota)
|
||||
] @constant.builtin
|
||||
|
||||
(comment) @comment
|
||||
@ -1,175 +0,0 @@
|
||||
(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
|
||||
)
|
||||
@ -1,30 +0,0 @@
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(function_declaration
|
||||
name: (identifier) @name) @definition.function
|
||||
(#strip! @doc "^//\\s*")
|
||||
(#set-adjacent! @doc @definition.function)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(method_declaration
|
||||
name: (field_identifier) @name) @definition.method
|
||||
(#strip! @doc "^//\\s*")
|
||||
(#set-adjacent! @doc @definition.method)
|
||||
)
|
||||
|
||||
(call_expression
|
||||
function: [
|
||||
(identifier) @name
|
||||
(parenthesized_expression (identifier) @name)
|
||||
(selector_expression field: (field_identifier) @name)
|
||||
(parenthesized_expression (selector_expression field: (field_identifier) @name))
|
||||
]) @reference.call
|
||||
|
||||
(type_spec
|
||||
name: (type_identifier) @name) @definition.type
|
||||
|
||||
(type_identifier) @name @reference.type
|
||||
@ -1,56 +0,0 @@
|
||||
from os.path import isdir, join
|
||||
from platform import system
|
||||
|
||||
from setuptools import Extension, find_packages, setup
|
||||
from setuptools.command.build import build
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
|
||||
|
||||
class Build(build):
|
||||
def run(self):
|
||||
if isdir("queries"):
|
||||
dest = join(self.build_lib, "tree_sitter_go", "queries")
|
||||
self.copy_tree("queries", dest)
|
||||
super().run()
|
||||
|
||||
|
||||
class BdistWheel(bdist_wheel):
|
||||
def get_tag(self):
|
||||
python, abi, platform = super().get_tag()
|
||||
if python.startswith("cp"):
|
||||
python, abi = "cp38", "abi3"
|
||||
return python, abi, platform
|
||||
|
||||
|
||||
setup(
|
||||
packages=find_packages("bindings/python"),
|
||||
package_dir={"": "bindings/python"},
|
||||
package_data={
|
||||
"tree_sitter_go": ["*.pyi", "py.typed"],
|
||||
"tree_sitter_go.queries": ["*.scm"],
|
||||
},
|
||||
ext_package="tree_sitter_go",
|
||||
ext_modules=[
|
||||
Extension(
|
||||
name="_binding",
|
||||
sources=[
|
||||
"bindings/python/tree_sitter_go/binding.c",
|
||||
"src/parser.c",
|
||||
],
|
||||
extra_compile_args=(
|
||||
["-std=c11"] if system() != 'Windows' else []
|
||||
),
|
||||
define_macros=[
|
||||
("Py_LIMITED_API", "0x03080000"),
|
||||
("PY_SSIZE_T_CLEAN", None)
|
||||
],
|
||||
include_dirs=["src"],
|
||||
py_limited_api=True,
|
||||
)
|
||||
],
|
||||
cmdclass={
|
||||
"build": Build,
|
||||
"bdist_wheel": BdistWheel
|
||||
},
|
||||
zip_safe=False
|
||||
)
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,54 +0,0 @@
|
||||
#ifndef TREE_SITTER_ALLOC_H_
|
||||
#define TREE_SITTER_ALLOC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Allow clients to override allocation functions
|
||||
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
||||
|
||||
extern void *(*ts_current_malloc)(size_t);
|
||||
extern void *(*ts_current_calloc)(size_t, size_t);
|
||||
extern void *(*ts_current_realloc)(void *, size_t);
|
||||
extern void (*ts_current_free)(void *);
|
||||
|
||||
#ifndef ts_malloc
|
||||
#define ts_malloc ts_current_malloc
|
||||
#endif
|
||||
#ifndef ts_calloc
|
||||
#define ts_calloc ts_current_calloc
|
||||
#endif
|
||||
#ifndef ts_realloc
|
||||
#define ts_realloc ts_current_realloc
|
||||
#endif
|
||||
#ifndef ts_free
|
||||
#define ts_free ts_current_free
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#ifndef ts_malloc
|
||||
#define ts_malloc malloc
|
||||
#endif
|
||||
#ifndef ts_calloc
|
||||
#define ts_calloc calloc
|
||||
#endif
|
||||
#ifndef ts_realloc
|
||||
#define ts_realloc realloc
|
||||
#endif
|
||||
#ifndef ts_free
|
||||
#define ts_free free
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_ALLOC_H_
|
||||
@ -1,290 +0,0 @@
|
||||
#ifndef TREE_SITTER_ARRAY_H_
|
||||
#define TREE_SITTER_ARRAY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "./alloc.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable : 4101)
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#endif
|
||||
|
||||
#define Array(T) \
|
||||
struct { \
|
||||
T *contents; \
|
||||
uint32_t size; \
|
||||
uint32_t capacity; \
|
||||
}
|
||||
|
||||
/// Initialize an array.
|
||||
#define array_init(self) \
|
||||
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
|
||||
|
||||
/// Create an empty array.
|
||||
#define array_new() \
|
||||
{ NULL, 0, 0 }
|
||||
|
||||
/// Get a pointer to the element at a given `index` in the array.
|
||||
#define array_get(self, _index) \
|
||||
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
|
||||
|
||||
/// Get a pointer to the first element in the array.
|
||||
#define array_front(self) array_get(self, 0)
|
||||
|
||||
/// Get a pointer to the last element in the array.
|
||||
#define array_back(self) array_get(self, (self)->size - 1)
|
||||
|
||||
/// Clear the array, setting its size to zero. Note that this does not free any
|
||||
/// memory allocated for the array's contents.
|
||||
#define array_clear(self) ((self)->size = 0)
|
||||
|
||||
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
|
||||
/// less than the array's current capacity, this function has no effect.
|
||||
#define array_reserve(self, new_capacity) \
|
||||
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
|
||||
|
||||
/// Free any memory allocated for this array. Note that this does not free any
|
||||
/// memory allocated for the array's contents.
|
||||
#define array_delete(self) _array__delete((Array *)(self))
|
||||
|
||||
/// Push a new `element` onto the end of the array.
|
||||
#define array_push(self, element) \
|
||||
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
|
||||
(self)->contents[(self)->size++] = (element))
|
||||
|
||||
/// Increase the array's size by `count` elements.
|
||||
/// New elements are zero-initialized.
|
||||
#define array_grow_by(self, count) \
|
||||
do { \
|
||||
if ((count) == 0) break; \
|
||||
_array__grow((Array *)(self), count, array_elem_size(self)); \
|
||||
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
|
||||
(self)->size += (count); \
|
||||
} while (0)
|
||||
|
||||
/// Append all elements from one array to the end of another.
|
||||
#define array_push_all(self, other) \
|
||||
array_extend((self), (other)->size, (other)->contents)
|
||||
|
||||
/// Append `count` elements to the end of the array, reading their values from the
|
||||
/// `contents` pointer.
|
||||
#define array_extend(self, count, contents) \
|
||||
_array__splice( \
|
||||
(Array *)(self), array_elem_size(self), (self)->size, \
|
||||
0, count, contents \
|
||||
)
|
||||
|
||||
/// Remove `old_count` elements from the array starting at the given `index`. At
|
||||
/// the same index, insert `new_count` new elements, reading their values from the
|
||||
/// `new_contents` pointer.
|
||||
#define array_splice(self, _index, old_count, new_count, new_contents) \
|
||||
_array__splice( \
|
||||
(Array *)(self), array_elem_size(self), _index, \
|
||||
old_count, new_count, new_contents \
|
||||
)
|
||||
|
||||
/// Insert one `element` into the array at the given `index`.
|
||||
#define array_insert(self, _index, element) \
|
||||
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
|
||||
|
||||
/// Remove one element from the array at the given `index`.
|
||||
#define array_erase(self, _index) \
|
||||
_array__erase((Array *)(self), array_elem_size(self), _index)
|
||||
|
||||
/// Pop the last element off the array, returning the element by value.
|
||||
#define array_pop(self) ((self)->contents[--(self)->size])
|
||||
|
||||
/// Assign the contents of one array to another, reallocating if necessary.
|
||||
#define array_assign(self, other) \
|
||||
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
|
||||
|
||||
/// Swap one array with another
|
||||
#define array_swap(self, other) \
|
||||
_array__swap((Array *)(self), (Array *)(other))
|
||||
|
||||
/// Get the size of the array contents
|
||||
#define array_elem_size(self) (sizeof *(self)->contents)
|
||||
|
||||
/// Search a sorted array for a given `needle` value, using the given `compare`
|
||||
/// callback to determine the order.
|
||||
///
|
||||
/// If an existing element is found to be equal to `needle`, then the `index`
|
||||
/// out-parameter is set to the existing value's index, and the `exists`
|
||||
/// out-parameter is set to true. Otherwise, `index` is set to an index where
|
||||
/// `needle` should be inserted in order to preserve the sorting, and `exists`
|
||||
/// is set to false.
|
||||
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
|
||||
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
|
||||
|
||||
/// Search a sorted array for a given `needle` value, using integer comparisons
|
||||
/// of a given struct field (specified with a leading dot) to determine the order.
|
||||
///
|
||||
/// See also `array_search_sorted_with`.
|
||||
#define array_search_sorted_by(self, field, needle, _index, _exists) \
|
||||
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
|
||||
|
||||
/// Insert a given `value` into a sorted array, using the given `compare`
|
||||
/// callback to determine the order.
|
||||
#define array_insert_sorted_with(self, compare, value) \
|
||||
do { \
|
||||
unsigned _index, _exists; \
|
||||
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
|
||||
if (!_exists) array_insert(self, _index, value); \
|
||||
} while (0)
|
||||
|
||||
/// Insert a given `value` into a sorted array, using integer comparisons of
|
||||
/// a given struct field (specified with a leading dot) to determine the order.
|
||||
///
|
||||
/// See also `array_search_sorted_by`.
|
||||
#define array_insert_sorted_by(self, field, value) \
|
||||
do { \
|
||||
unsigned _index, _exists; \
|
||||
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
|
||||
if (!_exists) array_insert(self, _index, value); \
|
||||
} while (0)
|
||||
|
||||
// Private
|
||||
|
||||
typedef Array(void) Array;
|
||||
|
||||
/// This is not what you're looking for, see `array_delete`.
|
||||
static inline void _array__delete(Array *self) {
|
||||
if (self->contents) {
|
||||
ts_free(self->contents);
|
||||
self->contents = NULL;
|
||||
self->size = 0;
|
||||
self->capacity = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_erase`.
|
||||
static inline void _array__erase(Array *self, size_t element_size,
|
||||
uint32_t index) {
|
||||
assert(index < self->size);
|
||||
char *contents = (char *)self->contents;
|
||||
memmove(contents + index * element_size, contents + (index + 1) * element_size,
|
||||
(self->size - index - 1) * element_size);
|
||||
self->size--;
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_reserve`.
|
||||
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
|
||||
if (new_capacity > self->capacity) {
|
||||
if (self->contents) {
|
||||
self->contents = ts_realloc(self->contents, new_capacity * element_size);
|
||||
} else {
|
||||
self->contents = ts_malloc(new_capacity * element_size);
|
||||
}
|
||||
self->capacity = new_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_assign`.
|
||||
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
|
||||
_array__reserve(self, element_size, other->size);
|
||||
self->size = other->size;
|
||||
memcpy(self->contents, other->contents, self->size * element_size);
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_swap`.
|
||||
static inline void _array__swap(Array *self, Array *other) {
|
||||
Array swap = *other;
|
||||
*other = *self;
|
||||
*self = swap;
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
|
||||
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
|
||||
uint32_t new_size = self->size + count;
|
||||
if (new_size > self->capacity) {
|
||||
uint32_t new_capacity = self->capacity * 2;
|
||||
if (new_capacity < 8) new_capacity = 8;
|
||||
if (new_capacity < new_size) new_capacity = new_size;
|
||||
_array__reserve(self, element_size, new_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
/// This is not what you're looking for, see `array_splice`.
|
||||
static inline void _array__splice(Array *self, size_t element_size,
|
||||
uint32_t index, uint32_t old_count,
|
||||
uint32_t new_count, const void *elements) {
|
||||
uint32_t new_size = self->size + new_count - old_count;
|
||||
uint32_t old_end = index + old_count;
|
||||
uint32_t new_end = index + new_count;
|
||||
assert(old_end <= self->size);
|
||||
|
||||
_array__reserve(self, element_size, new_size);
|
||||
|
||||
char *contents = (char *)self->contents;
|
||||
if (self->size > old_end) {
|
||||
memmove(
|
||||
contents + new_end * element_size,
|
||||
contents + old_end * element_size,
|
||||
(self->size - old_end) * element_size
|
||||
);
|
||||
}
|
||||
if (new_count > 0) {
|
||||
if (elements) {
|
||||
memcpy(
|
||||
(contents + index * element_size),
|
||||
elements,
|
||||
new_count * element_size
|
||||
);
|
||||
} else {
|
||||
memset(
|
||||
(contents + index * element_size),
|
||||
0,
|
||||
new_count * element_size
|
||||
);
|
||||
}
|
||||
}
|
||||
self->size += new_count - old_count;
|
||||
}
|
||||
|
||||
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
|
||||
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
|
||||
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
|
||||
do { \
|
||||
*(_index) = start; \
|
||||
*(_exists) = false; \
|
||||
uint32_t size = (self)->size - *(_index); \
|
||||
if (size == 0) break; \
|
||||
int comparison; \
|
||||
while (size > 1) { \
|
||||
uint32_t half_size = size / 2; \
|
||||
uint32_t mid_index = *(_index) + half_size; \
|
||||
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
|
||||
if (comparison <= 0) *(_index) = mid_index; \
|
||||
size -= half_size; \
|
||||
} \
|
||||
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
|
||||
if (comparison == 0) *(_exists) = true; \
|
||||
else if (comparison < 0) *(_index) += 1; \
|
||||
} while (0)
|
||||
|
||||
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
|
||||
/// parameter by reference in order to work with the generic sorting function above.
|
||||
#define _compare_int(a, b) ((int)*(a) - (int)(b))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(default : 4101)
|
||||
#elif defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_ARRAY_H_
|
||||
@ -1,230 +0,0 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSStateId;
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const char * const *symbol_names;
|
||||
const char * const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
const TSStateId *primary_state_ids;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define UNUSED __pragma(warning(suppress : 4101))
|
||||
#else
|
||||
#define UNUSED __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
UNUSED \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = (state_value) \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = (state_value), \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
@ -1,583 +0,0 @@
|
||||
================================================================================
|
||||
Single const declarations without types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
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)))))
|
||||
|
||||
================================================================================
|
||||
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)))))
|
||||
|
||||
================================================================================
|
||||
Grouped const declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
zero = 0
|
||||
one = 1
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(const_declaration
|
||||
(const_spec
|
||||
(identifier)
|
||||
(expression_list
|
||||
(int_literal)))
|
||||
(const_spec
|
||||
(identifier)
|
||||
(expression_list
|
||||
(int_literal)))))
|
||||
|
||||
================================================================================
|
||||
Const declarations with implicit values
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
zero = iota
|
||||
one
|
||||
two
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(const_declaration
|
||||
(const_spec
|
||||
(identifier)
|
||||
(expression_list
|
||||
(iota)))
|
||||
(const_spec
|
||||
(identifier))
|
||||
(const_spec
|
||||
(identifier))))
|
||||
|
||||
================================================================================
|
||||
Var declarations without types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
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)))))
|
||||
|
||||
================================================================================
|
||||
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)))))
|
||||
|
||||
================================================================================
|
||||
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))))
|
||||
|
||||
================================================================================
|
||||
Grouped var declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
var (
|
||||
zero = 0
|
||||
one = 1
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(var_declaration
|
||||
(var_spec
|
||||
(identifier)
|
||||
(expression_list
|
||||
(int_literal)))
|
||||
(var_spec
|
||||
(identifier)
|
||||
(expression_list
|
||||
(int_literal)))))
|
||||
|
||||
================================================================================
|
||||
Function declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
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 g2(a foo.bar[int]) {}
|
||||
func f[A int|string, B ~int, C ~int|~string]()
|
||||
func f2(a File, b, c, d Thing) int {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier))
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(type_identifier)
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(parameter_list
|
||||
(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))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(variadic_parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier))
|
||||
(variadic_parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier))))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(type_parameter_list
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(type_identifier)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(interface_type)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))))))
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(type_parameter_list
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(type_identifier)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(interface_type)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))))))
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(generic_type
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier))
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(type_parameter_list
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(type_identifier)
|
||||
(type_identifier)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(negated_type
|
||||
(type_identifier))))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(negated_type
|
||||
(type_identifier))
|
||||
(negated_type
|
||||
(type_identifier)))))
|
||||
(parameter_list))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier))
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(type_identifier)
|
||||
(block)))
|
||||
|
||||
================================================================================
|
||||
Single-line function declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func f1() { a() }
|
||||
func f2() { a(); b() }
|
||||
func f3() { a(); b(); }
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list))))))
|
||||
|
||||
================================================================================
|
||||
Variadic function declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func f1(a ...*int) {}
|
||||
func f2(a int, b ...int) {}
|
||||
func f3(...bool) {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(variadic_parameter_declaration
|
||||
(identifier)
|
||||
(pointer_type
|
||||
(type_identifier))))
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier))
|
||||
(variadic_parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(block))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list
|
||||
(variadic_parameter_declaration
|
||||
(type_identifier)))
|
||||
(block)))
|
||||
|
||||
================================================================================
|
||||
Method declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func (self Person) Equals(other Person) bool {}
|
||||
func (v *Value) ObjxMap(optionalDefault ...(Map)) Map {}
|
||||
func (p *T1) M1()
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(method_declaration
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(field_identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(type_identifier)
|
||||
(block))
|
||||
(method_declaration
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(pointer_type
|
||||
(type_identifier))))
|
||||
(field_identifier)
|
||||
(parameter_list
|
||||
(variadic_parameter_declaration
|
||||
(identifier)
|
||||
(parenthesized_type
|
||||
(type_identifier))))
|
||||
(type_identifier)
|
||||
(block))
|
||||
(method_declaration
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(pointer_type
|
||||
(type_identifier))))
|
||||
(field_identifier)
|
||||
(parameter_list)))
|
||||
|
||||
================================================================================
|
||||
Type declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type a b
|
||||
type (
|
||||
a b
|
||||
c d
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(type_identifier)))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(type_identifier))
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(type_identifier))))
|
||||
@ -1,458 +0,0 @@
|
||||
================================================================================
|
||||
Call expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a(b, c...)
|
||||
|
||||
a(
|
||||
b,
|
||||
c,
|
||||
)
|
||||
|
||||
a(
|
||||
b,
|
||||
c...,
|
||||
)
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(identifier)
|
||||
(variadic_argument
|
||||
(identifier)))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(identifier)
|
||||
(variadic_argument
|
||||
(identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Nested call expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a(b(c(d)))
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(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
|
||||
(expression_statement
|
||||
(type_conversion_expression
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(type_conversion_expression
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))
|
||||
(type_elem
|
||||
(type_identifier))))
|
||||
(identifier)))
|
||||
(expression_statement
|
||||
(type_conversion_expression
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier)))))
|
||||
(type_elem
|
||||
(type_identifier))))
|
||||
(index_expression
|
||||
(identifier)
|
||||
(identifier)))))))
|
||||
|
||||
================================================================================
|
||||
Calls to 'make' and 'new'
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
make(chan<- int)
|
||||
|
||||
// `new` and `make` can also be used as variable names
|
||||
make(chan<- int, (new - old), make.stuff)
|
||||
|
||||
make(chan<- int, 5, 10)
|
||||
new(map[string]string)
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(channel_type
|
||||
(type_identifier)))))
|
||||
(comment)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(channel_type
|
||||
(type_identifier))
|
||||
(parenthesized_expression
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier)))
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier)))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(channel_type
|
||||
(type_identifier))
|
||||
(int_literal)
|
||||
(int_literal))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(map_type
|
||||
(type_identifier)
|
||||
(type_identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Selector expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a.b.c()
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(selector_expression
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier))
|
||||
(field_identifier))
|
||||
(argument_list))))))
|
||||
|
||||
================================================================================
|
||||
Indexing expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
_ = a[1]
|
||||
_ = b[:]
|
||||
_ = c[1:]
|
||||
_ = d[1:2]
|
||||
_ = e[:2:3]
|
||||
_ = f[1:2:3]
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(index_expression
|
||||
(identifier)
|
||||
(int_literal))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(slice_expression
|
||||
(identifier))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(slice_expression
|
||||
(identifier)
|
||||
(int_literal))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(slice_expression
|
||||
(identifier)
|
||||
(int_literal)
|
||||
(int_literal))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(slice_expression
|
||||
(identifier)
|
||||
(int_literal)
|
||||
(int_literal))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(slice_expression
|
||||
(identifier)
|
||||
(int_literal)
|
||||
(int_literal)
|
||||
(int_literal)))))))
|
||||
|
||||
================================================================================
|
||||
Type assertion expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
_ = a.(p.Person)
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(type_assertion_expression
|
||||
(identifier)
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier))))))))
|
||||
|
||||
================================================================================
|
||||
Type conversion expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
_ = []a.b(c.d)
|
||||
_ = ([]a.b)(c.d)
|
||||
_ = <-chan int(c) // conversion to channel type
|
||||
<-(chan int(c)) // receive statement
|
||||
// These type conversions cannot be distinguished from call expressions
|
||||
T(x)
|
||||
(*Point)(p)
|
||||
e.f(g)
|
||||
(e.f)(g)
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(type_conversion_expression
|
||||
(slice_type
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier)))
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier)))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(type_conversion_expression
|
||||
(parenthesized_type
|
||||
(slice_type
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier))))
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier)))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(type_conversion_expression
|
||||
(channel_type
|
||||
(type_identifier))
|
||||
(identifier))))
|
||||
(comment)
|
||||
(expression_statement
|
||||
(unary_expression
|
||||
(parenthesized_expression
|
||||
(type_conversion_expression
|
||||
(channel_type
|
||||
(type_identifier))
|
||||
(identifier)))))
|
||||
(comment)
|
||||
(comment)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(parenthesized_expression
|
||||
(unary_expression
|
||||
(identifier)))
|
||||
(argument_list
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier))
|
||||
(argument_list
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(parenthesized_expression
|
||||
(selector_expression
|
||||
(identifier)
|
||||
(field_identifier)))
|
||||
(argument_list
|
||||
(identifier)))))))
|
||||
|
||||
================================================================================
|
||||
Unary expressions
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
_ = !<-a
|
||||
_ = *foo()
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(unary_expression
|
||||
(unary_expression
|
||||
(identifier)))))
|
||||
(assignment_statement
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(unary_expression
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list))))))))
|
||||
@ -1,557 +0,0 @@
|
||||
================================================================================
|
||||
Int literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
i1 = 42
|
||||
i2 = 4_2
|
||||
i3 = 0600
|
||||
i4 = 0_600
|
||||
i5 = 0o600
|
||||
i6 = 0O600
|
||||
i7 = 0xBadFace
|
||||
i8 = 0xBad_Face
|
||||
i9 = 0x_67_7a_2f_cc_40_c6
|
||||
i10 = 170141183460469231731687303715884105727
|
||||
i11 = 170_141183_460469_231731_687303_715884_105727
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(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)))))
|
||||
|
||||
================================================================================
|
||||
Float literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
f1 = 0.
|
||||
f2 = 72.40
|
||||
f3 = 072.40
|
||||
f4 = 2.71828
|
||||
f5 = 1.e+0
|
||||
f6 = 6.67428e-11
|
||||
f7 = 1E6
|
||||
f8 = .25
|
||||
f9 = .12345E+5
|
||||
f10 = 1_5.
|
||||
f11 = 0.15e+0_2
|
||||
f12 = 0x1p-2
|
||||
f13 = 0x2.p10
|
||||
f14 = 0x1.Fp+0
|
||||
f15 = 0X.8p-0
|
||||
f16 = 0X_1FFFP-16
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(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)))))
|
||||
|
||||
================================================================================
|
||||
Rune literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
a = '0'
|
||||
b = '\''
|
||||
c = '\\'
|
||||
c = '\n'
|
||||
c = '\u0000'
|
||||
c = '\U01234567'
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(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)))))
|
||||
|
||||
================================================================================
|
||||
Imaginary literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
a = 0i
|
||||
b = 0123i
|
||||
c = 0o123i
|
||||
d = 0xabci
|
||||
e = 0.i
|
||||
f = 2.71828i
|
||||
g = 1.e+0i
|
||||
h = 6.67428e-11i
|
||||
i = 1E6i
|
||||
j = .25i
|
||||
k = .12345E+5i
|
||||
l = 0x1p-2i
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(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)))))
|
||||
|
||||
================================================================================
|
||||
String literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const (
|
||||
a = "0"
|
||||
b = "`\"`"
|
||||
c = "\x0c"
|
||||
d = "errorstring
|
||||
"
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(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))))
|
||||
(ERROR
|
||||
(identifier))))
|
||||
|
||||
================================================================================
|
||||
Slice literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const s1 = []string{}
|
||||
|
||||
const s2 = []string{"hi"}
|
||||
|
||||
const s3 = []string{
|
||||
"hi",
|
||||
"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
|
||||
(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
|
||||
(literal_element
|
||||
(int_literal))
|
||||
(literal_element
|
||||
(int_literal))
|
||||
(literal_element
|
||||
(int_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Map literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
const s = map[string]string{
|
||||
"hi": "hello",
|
||||
"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
|
||||
(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
|
||||
|
||||
const s1 = Person{
|
||||
name: "Frank",
|
||||
Age: "5 months",
|
||||
}
|
||||
|
||||
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
|
||||
(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_elem
|
||||
(type_identifier))
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier)))))))
|
||||
(literal_value))))))
|
||||
|
||||
================================================================================
|
||||
Function literals
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
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)))))))))
|
||||
@ -1,855 +0,0 @@
|
||||
================================================================================
|
||||
Declaration statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
var x = y
|
||||
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)))))))
|
||||
|
||||
================================================================================
|
||||
Expression statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
foo(5)
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(int_literal)))))))
|
||||
|
||||
================================================================================
|
||||
Send statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
foo <- 5
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(send_statement
|
||||
(identifier)
|
||||
(int_literal)))))
|
||||
|
||||
================================================================================
|
||||
Increment/Decrement statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
i++
|
||||
j--
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(inc_statement
|
||||
(identifier))
|
||||
(dec_statement
|
||||
(identifier)))))
|
||||
|
||||
================================================================================
|
||||
Assignment statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
a = 1
|
||||
b, c += 2, 3
|
||||
d *= 3
|
||||
e += 1
|
||||
f /= 2
|
||||
g <<= 1
|
||||
h >>= 1
|
||||
i %= 1
|
||||
j &= 2
|
||||
k &^= 3
|
||||
l -= 1
|
||||
m |= 2
|
||||
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))))))
|
||||
|
||||
================================================================================
|
||||
Short var declarations
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
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))))))
|
||||
|
||||
================================================================================
|
||||
If statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
if a {
|
||||
b()
|
||||
}
|
||||
|
||||
if a := b(); c {
|
||||
d()
|
||||
}
|
||||
|
||||
if a {
|
||||
b()
|
||||
} else {
|
||||
c()
|
||||
}
|
||||
|
||||
if b {
|
||||
c()
|
||||
} else if d {
|
||||
e()
|
||||
} else {
|
||||
f()
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
name: (identifier)
|
||||
parameters: (parameter_list)
|
||||
body: (block
|
||||
(if_statement
|
||||
condition: (identifier)
|
||||
consequence: (block
|
||||
(expression_statement
|
||||
(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
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list)))))
|
||||
(if_statement
|
||||
condition: (identifier)
|
||||
consequence: (block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list))))
|
||||
alternative: (block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list)))))
|
||||
(if_statement
|
||||
condition: (identifier)
|
||||
consequence: (block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list))))
|
||||
alternative: (if_statement
|
||||
condition: (identifier)
|
||||
consequence: (block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list))))
|
||||
alternative: (block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list)))))))))
|
||||
|
||||
================================================================================
|
||||
For statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
for {
|
||||
a()
|
||||
goto loop
|
||||
}
|
||||
|
||||
loop: for i := 0; i < 5; i++ {
|
||||
a()
|
||||
break loop
|
||||
}
|
||||
|
||||
loop2:
|
||||
for ; i < 10; i++ {
|
||||
a()
|
||||
continue loop2
|
||||
}
|
||||
|
||||
for ;; {
|
||||
a()
|
||||
continue
|
||||
}
|
||||
|
||||
for x := range y {
|
||||
a(x)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(for_statement
|
||||
(block
|
||||
(expression_statement
|
||||
(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
|
||||
(expression_statement
|
||||
(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
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))
|
||||
(continue_statement
|
||||
(label_name)))))
|
||||
(for_statement
|
||||
(for_clause)
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list)))
|
||||
(continue_statement)))
|
||||
(for_statement
|
||||
(range_clause
|
||||
(expression_list
|
||||
(identifier))
|
||||
(identifier))
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(identifier))))
|
||||
(break_statement))))))
|
||||
|
||||
================================================================================
|
||||
Switch statements
|
||||
================================================================================
|
||||
|
||||
func main() {
|
||||
switch e {
|
||||
case 1, 2:
|
||||
a()
|
||||
fallthrough
|
||||
case 3:
|
||||
d()
|
||||
default:
|
||||
c()
|
||||
break
|
||||
}
|
||||
|
||||
switch {
|
||||
case true:
|
||||
return
|
||||
}
|
||||
|
||||
switch f := y(); f {
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_declaration
|
||||
name: (identifier)
|
||||
parameters: (parameter_list)
|
||||
body: (block
|
||||
(expression_switch_statement
|
||||
value: (identifier)
|
||||
(expression_case
|
||||
value: (expression_list
|
||||
(int_literal)
|
||||
(int_literal))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list)))
|
||||
(fallthrough_statement))
|
||||
(expression_case
|
||||
value: (expression_list
|
||||
(int_literal))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list))))
|
||||
(default_case
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list)))
|
||||
(break_statement)))
|
||||
(expression_switch_statement
|
||||
(expression_case
|
||||
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))))
|
||||
value: (identifier)))))
|
||||
|
||||
================================================================================
|
||||
Type switch statements
|
||||
================================================================================
|
||||
|
||||
func main() {
|
||||
switch e.(type) {
|
||||
case []Person:
|
||||
a()
|
||||
case *Dog:
|
||||
break
|
||||
}
|
||||
switch i := x.(type) {
|
||||
case nil:
|
||||
printString("x is nil")
|
||||
case int:
|
||||
printInt(i)
|
||||
case float64:
|
||||
printFloat64(i)
|
||||
case func(int) float64:
|
||||
printFunction(i)
|
||||
case bool, string:
|
||||
printString("type is bool or string")
|
||||
default:
|
||||
printString("don't know the type")
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_declaration
|
||||
name: (identifier)
|
||||
parameters: (parameter_list)
|
||||
body: (block
|
||||
(type_switch_statement
|
||||
value: (identifier)
|
||||
(type_case
|
||||
type: (slice_type
|
||||
element: (type_identifier))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list))))
|
||||
(type_case
|
||||
type: (pointer_type
|
||||
(type_identifier))
|
||||
(break_statement)))
|
||||
(type_switch_statement
|
||||
alias: (expression_list
|
||||
(identifier))
|
||||
value: (identifier)
|
||||
(type_case
|
||||
type: (type_identifier)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(interpreted_string_literal)))))
|
||||
(type_case
|
||||
type: (type_identifier)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(identifier)))))
|
||||
(type_case
|
||||
type: (type_identifier)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(identifier)))))
|
||||
(type_case
|
||||
type: (function_type
|
||||
parameters: (parameter_list
|
||||
(parameter_declaration
|
||||
type: (type_identifier)))
|
||||
result: (type_identifier))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(identifier)))))
|
||||
(type_case
|
||||
type: (type_identifier)
|
||||
type: (type_identifier)
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(interpreted_string_literal)))))
|
||||
(default_case
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(interpreted_string_literal)))))))))
|
||||
|
||||
================================================================================
|
||||
Select statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
select {
|
||||
case x := <-c:
|
||||
println(x)
|
||||
case y <- c:
|
||||
println(5)
|
||||
case <-time.After(1):
|
||||
println(6)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
name: (identifier)
|
||||
parameters: (parameter_list)
|
||||
body: (block
|
||||
(select_statement
|
||||
(communication_case
|
||||
communication: (receive_statement
|
||||
left: (expression_list
|
||||
(identifier))
|
||||
right: (unary_expression
|
||||
operand: (identifier)))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(identifier)))))
|
||||
(communication_case
|
||||
communication: (send_statement
|
||||
channel: (identifier)
|
||||
value: (identifier))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
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)))))
|
||||
(expression_statement
|
||||
(call_expression
|
||||
function: (identifier)
|
||||
arguments: (argument_list
|
||||
(int_literal)))))
|
||||
(default_case
|
||||
(return_statement))))))
|
||||
|
||||
================================================================================
|
||||
Go and defer statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
defer x.y()
|
||||
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))))))
|
||||
|
||||
================================================================================
|
||||
Nested statement blocks
|
||||
================================================================================
|
||||
|
||||
func main() {
|
||||
{
|
||||
println("hi")
|
||||
}
|
||||
{
|
||||
println("bye")
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(interpreted_string_literal)))))
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(interpreted_string_literal))))))))
|
||||
|
||||
================================================================================
|
||||
Labels at the ends of statement blocks
|
||||
================================================================================
|
||||
|
||||
func main() {
|
||||
{
|
||||
end_of_block:
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(function_declaration
|
||||
name: (identifier)
|
||||
parameters: (parameter_list)
|
||||
body: (block
|
||||
(block
|
||||
(labeled_statement
|
||||
label: (label_name))))))
|
||||
|
||||
================================================================================
|
||||
Empty statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
;
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(empty_statement))))
|
||||
|
||||
================================================================================
|
||||
Nested control statements
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
for i, v := range vectors {
|
||||
func() {
|
||||
if v == v {
|
||||
fmt.Println("something: %v", vectors[i])
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(block
|
||||
(for_statement
|
||||
(range_clause
|
||||
(expression_list
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))
|
||||
(block
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(func_literal
|
||||
(parameter_list)
|
||||
(block
|
||||
(if_statement
|
||||
(binary_expression
|
||||
(identifier)
|
||||
(identifier))
|
||||
(block
|
||||
(expression_statement
|
||||
(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
|
||||
(expression_statement
|
||||
(call_expression
|
||||
(identifier)
|
||||
(argument_list
|
||||
(int_literal))))
|
||||
(short_var_declaration
|
||||
(expression_list
|
||||
(identifier))
|
||||
(expression_list
|
||||
(composite_literal
|
||||
(type_identifier)
|
||||
(literal_value
|
||||
(keyed_element
|
||||
(literal_element
|
||||
(identifier))
|
||||
(literal_element
|
||||
(identifier))))))))
|
||||
@ -1,509 +0,0 @@
|
||||
================================================================================
|
||||
Qualified type names
|
||||
================================================================================
|
||||
|
||||
type a b.c
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(type_declaration
|
||||
(type_spec
|
||||
name: (type_identifier)
|
||||
type: (qualified_type
|
||||
package: (package_identifier)
|
||||
name: (type_identifier)))))
|
||||
|
||||
================================================================================
|
||||
Array types
|
||||
================================================================================
|
||||
|
||||
type a [2+2]c
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(type_declaration
|
||||
(type_spec
|
||||
name: (type_identifier)
|
||||
type: (array_type
|
||||
length: (binary_expression
|
||||
left: (int_literal)
|
||||
right: (int_literal))
|
||||
element: (type_identifier)))))
|
||||
|
||||
================================================================================
|
||||
Slice types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type a []c
|
||||
type b [][]d
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(slice_type
|
||||
(type_identifier))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(slice_type
|
||||
(slice_type
|
||||
(type_identifier))))))
|
||||
|
||||
================================================================================
|
||||
Struct types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type s1 struct {}
|
||||
|
||||
type s2 struct { Person }
|
||||
|
||||
type s2 struct {
|
||||
f, g int
|
||||
}
|
||||
|
||||
type s3 struct {
|
||||
// an embedded struct
|
||||
p.s1
|
||||
|
||||
// a tag
|
||||
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
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(struct_type
|
||||
(field_declaration_list))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(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))))))
|
||||
(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))))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier)))))
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))))))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(type_parameter_list
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(type_identifier)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(interface_type)))
|
||||
(type_parameter_declaration
|
||||
(identifier)
|
||||
(type_constraint
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(generic_type
|
||||
(type_identifier)
|
||||
(type_arguments
|
||||
(type_elem
|
||||
(type_identifier))))))))))
|
||||
(struct_type
|
||||
(field_declaration_list)))))
|
||||
|
||||
================================================================================
|
||||
Interface types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type i1 interface {}
|
||||
|
||||
type i1 interface { io.Reader }
|
||||
|
||||
type i2 interface {
|
||||
i1
|
||||
io.Reader
|
||||
SomeMethod(s string) error
|
||||
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)))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(interface_type
|
||||
(type_elem
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier))))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(interface_type
|
||||
(type_elem
|
||||
(type_identifier))
|
||||
(type_elem
|
||||
(qualified_type
|
||||
(package_identifier)
|
||||
(type_identifier)))
|
||||
(method_elem
|
||||
(field_identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(identifier)
|
||||
(type_identifier)))
|
||||
(type_identifier))
|
||||
(method_elem
|
||||
(field_identifier)
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(type_identifier))
|
||||
(variadic_parameter_declaration
|
||||
(type_identifier)))
|
||||
(type_identifier)))))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(interface_type
|
||||
(type_elem
|
||||
(type_identifier)
|
||||
(type_identifier)
|
||||
(negated_type
|
||||
(type_identifier))
|
||||
(negated_type
|
||||
(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 }
|
||||
struct{ f int } | string
|
||||
}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(interface_type
|
||||
(type_elem
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier)))))
|
||||
(type_elem
|
||||
(negated_type
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier))))))
|
||||
(type_elem
|
||||
(pointer_type
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier))))))
|
||||
(type_elem
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier))))
|
||||
(negated_type
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier))))))
|
||||
(type_elem
|
||||
(struct_type
|
||||
(field_declaration_list
|
||||
(field_declaration
|
||||
(field_identifier)
|
||||
(type_identifier))))
|
||||
(type_identifier))))))
|
||||
|
||||
================================================================================
|
||||
Map types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type m1 map[string]error
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(map_type
|
||||
(type_identifier)
|
||||
(type_identifier)))))
|
||||
|
||||
================================================================================
|
||||
Pointer types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type (
|
||||
p1 *string
|
||||
p2 **p1
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(pointer_type
|
||||
(type_identifier)))
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(pointer_type
|
||||
(pointer_type
|
||||
(type_identifier))))))
|
||||
|
||||
================================================================================
|
||||
Channel types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type (
|
||||
c1 chan<- chan int
|
||||
c2 chan<- chan<- struct{}
|
||||
c3 chan<- <-chan int
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(channel_type
|
||||
(channel_type
|
||||
(type_identifier))))
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(channel_type
|
||||
(channel_type
|
||||
(struct_type
|
||||
(field_declaration_list)))))
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(channel_type
|
||||
(channel_type
|
||||
(type_identifier))))))
|
||||
|
||||
================================================================================
|
||||
Function types
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type (
|
||||
a func(int) int
|
||||
b func(int, *string) (bool, error)
|
||||
c func(int, ...*string) bool
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(function_type
|
||||
(parameter_list
|
||||
(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_list
|
||||
(parameter_declaration
|
||||
(type_identifier))
|
||||
(parameter_declaration
|
||||
(type_identifier)))))
|
||||
(type_spec
|
||||
(type_identifier)
|
||||
(function_type
|
||||
(parameter_list
|
||||
(parameter_declaration
|
||||
(type_identifier))
|
||||
(variadic_parameter_declaration
|
||||
(pointer_type
|
||||
(type_identifier))))
|
||||
(type_identifier)))))
|
||||
|
||||
================================================================================
|
||||
Type Aliases
|
||||
================================================================================
|
||||
|
||||
package main
|
||||
|
||||
type H1 = G1
|
||||
type _ = G2
|
||||
type _ = struct{}
|
||||
type (
|
||||
A0 = T0
|
||||
A1 = int
|
||||
A2 = struct{}
|
||||
A3 = reflect.Value
|
||||
A4 = Value
|
||||
A5 = Value
|
||||
)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(package_clause
|
||||
(package_identifier))
|
||||
(type_declaration
|
||||
(type_alias
|
||||
(type_identifier)
|
||||
(type_identifier)))
|
||||
(type_declaration
|
||||
(type_alias
|
||||
(type_identifier)
|
||||
(type_identifier)))
|
||||
(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))))
|
||||
Loading…
Reference in New Issue