mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-06-13 09:21:56 +08:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d528dddd6 | ||
|
|
543d590710 | ||
|
|
f1d70eb6b2 | ||
|
|
d828c3f37e | ||
|
|
038491b7bc | ||
|
|
cf683411ee | ||
|
|
de5ed6a677 | ||
|
|
3dda557410 | ||
|
|
c800f6f723 | ||
|
|
0395ba1816 | ||
|
|
86f9f63b46 | ||
|
|
a7a6753118 | ||
|
|
2e80d12d6a | ||
|
|
417a96cbf2 | ||
|
|
2d4c29ea7c |
@@ -16,7 +16,6 @@ We hope that the items listed below will inspire further engagement from the com
|
|||||||
- [x] Support `username/password` authentication in ETCD
|
- [x] Support `username/password` authentication in ETCD
|
||||||
- [x] Support `SSL/TLS` in `zRPC`
|
- [x] Support `SSL/TLS` in `zRPC`
|
||||||
- [x] Support `TLS` in redis connections
|
- [x] Support `TLS` in redis connections
|
||||||
- [ ] Support `retry strategies` in `zRPC`
|
|
||||||
|
|
||||||
## 2022
|
## 2022
|
||||||
- [ ] Support `goctl mock` command to start a mocking server with given `.api` file
|
- [ ] Support `goctl mock` command to start a mocking server with given `.api` file
|
||||||
|
|||||||
@@ -37,25 +37,35 @@ func GetRegistry() *Registry {
|
|||||||
|
|
||||||
// GetConn returns an etcd client connection associated with given endpoints.
|
// GetConn returns an etcd client connection associated with given endpoints.
|
||||||
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
func (r *Registry) GetConn(endpoints []string) (EtcdClient, error) {
|
||||||
return r.getCluster(endpoints).getClient()
|
c, _ := r.getCluster(endpoints)
|
||||||
|
return c.getClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
// Monitor monitors the key on given etcd endpoints, notify with the given UpdateListener.
|
||||||
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
func (r *Registry) Monitor(endpoints []string, key string, l UpdateListener) error {
|
||||||
return r.getCluster(endpoints).monitor(key, l)
|
c, exists := r.getCluster(endpoints)
|
||||||
|
// if exists, the existing values should be updated to the listener.
|
||||||
|
if exists {
|
||||||
|
kvs := c.getCurrent(key)
|
||||||
|
for _, kv := range kvs {
|
||||||
|
l.OnAdd(kv)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) getCluster(endpoints []string) *cluster {
|
return c.monitor(key, l)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) getCluster(endpoints []string) (c *cluster, exists bool) {
|
||||||
clusterKey := getClusterKey(endpoints)
|
clusterKey := getClusterKey(endpoints)
|
||||||
r.lock.Lock()
|
r.lock.Lock()
|
||||||
defer r.lock.Unlock()
|
defer r.lock.Unlock()
|
||||||
c, ok := r.clusters[clusterKey]
|
c, exists = r.clusters[clusterKey]
|
||||||
if !ok {
|
if !exists {
|
||||||
c = newCluster(endpoints)
|
c = newCluster(endpoints)
|
||||||
r.clusters[clusterKey] = c
|
r.clusters[clusterKey] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type cluster struct {
|
type cluster struct {
|
||||||
@@ -94,6 +104,21 @@ func (c *cluster) getClient() (EtcdClient, error) {
|
|||||||
return val.(EtcdClient), nil
|
return val.(EtcdClient), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *cluster) getCurrent(key string) []KV {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
var kvs []KV
|
||||||
|
for k, v := range c.values[key] {
|
||||||
|
kvs = append(kvs, KV{
|
||||||
|
Key: k,
|
||||||
|
Val: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return kvs
|
||||||
|
}
|
||||||
|
|
||||||
func (c *cluster) handleChanges(key string, kvs []KV) {
|
func (c *cluster) handleChanges(key string, kvs []KV) {
|
||||||
var add []KV
|
var add []KV
|
||||||
var remove []KV
|
var remove []KV
|
||||||
@@ -197,14 +222,12 @@ func (c *cluster) load(cli EtcdClient, key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var kvs []KV
|
var kvs []KV
|
||||||
c.lock.Lock()
|
|
||||||
for _, ev := range resp.Kvs {
|
for _, ev := range resp.Kvs {
|
||||||
kvs = append(kvs, KV{
|
kvs = append(kvs, KV{
|
||||||
Key: string(ev.Key),
|
Key: string(ev.Key),
|
||||||
Val: string(ev.Value),
|
Val: string(ev.Value),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
c.lock.Unlock()
|
|
||||||
|
|
||||||
c.handleChanges(key, kvs)
|
c.handleChanges(key, kvs)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ func setMockClient(cli EtcdClient) func() {
|
|||||||
|
|
||||||
func TestGetCluster(t *testing.T) {
|
func TestGetCluster(t *testing.T) {
|
||||||
AddAccount([]string{"first"}, "foo", "bar")
|
AddAccount([]string{"first"}, "foo", "bar")
|
||||||
c1 := GetRegistry().getCluster([]string{"first"})
|
c1, _ := GetRegistry().getCluster([]string{"first"})
|
||||||
c2 := GetRegistry().getCluster([]string{"second"})
|
c2, _ := GetRegistry().getCluster([]string{"second"})
|
||||||
c3 := GetRegistry().getCluster([]string{"first"})
|
c3, _ := GetRegistry().getCluster([]string{"first"})
|
||||||
assert.Equal(t, c1, c3)
|
assert.Equal(t, c1, c3)
|
||||||
assert.NotEqual(t, c1, c2)
|
assert.NotEqual(t, c1, c2)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ func ErrorCaller(callDepth int, v ...interface{}) {
|
|||||||
|
|
||||||
// ErrorCallerf writes v with context in format into error log.
|
// ErrorCallerf writes v with context in format into error log.
|
||||||
func ErrorCallerf(callDepth int, format string, v ...interface{}) {
|
func ErrorCallerf(callDepth int, format string, v ...interface{}) {
|
||||||
errorTextSync(fmt.Sprintf(format, v...), callDepth+callerInnerDepth)
|
errorTextSync(fmt.Errorf(format, v...).Error(), callDepth+callerInnerDepth)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errorf writes v with format into error log.
|
// Errorf writes v with format into error log.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package logx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -242,6 +243,16 @@ func TestSetLevelWithDuration(t *testing.T) {
|
|||||||
assert.Equal(t, 0, writer.builder.Len())
|
assert.Equal(t, 0, writer.builder.Len())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorfWithWrappedError(t *testing.T) {
|
||||||
|
SetLevel(ErrorLevel)
|
||||||
|
const message = "there"
|
||||||
|
writer := new(mockWriter)
|
||||||
|
errorLog = writer
|
||||||
|
atomic.StoreUint32(&initialized, 1)
|
||||||
|
Errorf("hello %w", errors.New(message))
|
||||||
|
assert.True(t, strings.Contains(writer.builder.String(), "hello there"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestMustNil(t *testing.T) {
|
func TestMustNil(t *testing.T) {
|
||||||
Must(nil)
|
Must(nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,6 +207,8 @@ func (u *Unmarshaler) processFieldNotFromString(field reflect.StructField, value
|
|||||||
switch {
|
switch {
|
||||||
case valueKind == reflect.Map && typeKind == reflect.Struct:
|
case valueKind == reflect.Map && typeKind == reflect.Struct:
|
||||||
return u.processFieldStruct(field, value, mapValue, fullName)
|
return u.processFieldStruct(field, value, mapValue, fullName)
|
||||||
|
case valueKind == reflect.Map && typeKind == reflect.Map:
|
||||||
|
return u.fillMap(field, value, mapValue)
|
||||||
case valueKind == reflect.String && typeKind == reflect.Slice:
|
case valueKind == reflect.String && typeKind == reflect.Slice:
|
||||||
return u.fillSliceFromString(fieldType, value, mapValue)
|
return u.fillSliceFromString(fieldType, value, mapValue)
|
||||||
case valueKind == reflect.String && derefedFieldType == durationType:
|
case valueKind == reflect.String && derefedFieldType == durationType:
|
||||||
@@ -584,6 +586,8 @@ func (u *Unmarshaler) generateMap(keyType, elemType reflect.Type, mapValue inter
|
|||||||
targetValue.SetMapIndex(key, innerValue)
|
targetValue.SetMapIndex(key, innerValue)
|
||||||
default:
|
default:
|
||||||
switch v := keythData.(type) {
|
switch v := keythData.(type) {
|
||||||
|
case bool:
|
||||||
|
targetValue.SetMapIndex(key, reflect.ValueOf(v))
|
||||||
case string:
|
case string:
|
||||||
targetValue.SetMapIndex(key, reflect.ValueOf(v))
|
targetValue.SetMapIndex(key, reflect.ValueOf(v))
|
||||||
case json.Number:
|
case json.Number:
|
||||||
|
|||||||
@@ -945,6 +945,70 @@ func TestUnmarshalYamlBadReader(t *testing.T) {
|
|||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalYamlMapBool(t *testing.T) {
|
||||||
|
text := `machine:
|
||||||
|
node1: true
|
||||||
|
node2: true
|
||||||
|
node3: true
|
||||||
|
`
|
||||||
|
var v struct {
|
||||||
|
Machine map[string]bool `json:"machine,optional"`
|
||||||
|
}
|
||||||
|
reader := strings.NewReader(text)
|
||||||
|
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||||
|
assert.True(t, v.Machine["node1"])
|
||||||
|
assert.True(t, v.Machine["node2"])
|
||||||
|
assert.True(t, v.Machine["node3"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalYamlMapInt(t *testing.T) {
|
||||||
|
text := `machine:
|
||||||
|
node1: 1
|
||||||
|
node2: 2
|
||||||
|
node3: 3
|
||||||
|
`
|
||||||
|
var v struct {
|
||||||
|
Machine map[string]int `json:"machine,optional"`
|
||||||
|
}
|
||||||
|
reader := strings.NewReader(text)
|
||||||
|
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||||
|
assert.Equal(t, 1, v.Machine["node1"])
|
||||||
|
assert.Equal(t, 2, v.Machine["node2"])
|
||||||
|
assert.Equal(t, 3, v.Machine["node3"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalYamlMapByte(t *testing.T) {
|
||||||
|
text := `machine:
|
||||||
|
node1: 1
|
||||||
|
node2: 2
|
||||||
|
node3: 3
|
||||||
|
`
|
||||||
|
var v struct {
|
||||||
|
Machine map[string]byte `json:"machine,optional"`
|
||||||
|
}
|
||||||
|
reader := strings.NewReader(text)
|
||||||
|
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||||
|
assert.Equal(t, byte(1), v.Machine["node1"])
|
||||||
|
assert.Equal(t, byte(2), v.Machine["node2"])
|
||||||
|
assert.Equal(t, byte(3), v.Machine["node3"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnmarshalYamlMapRune(t *testing.T) {
|
||||||
|
text := `machine:
|
||||||
|
node1: 1
|
||||||
|
node2: 2
|
||||||
|
node3: 3
|
||||||
|
`
|
||||||
|
var v struct {
|
||||||
|
Machine map[string]rune `json:"machine,optional"`
|
||||||
|
}
|
||||||
|
reader := strings.NewReader(text)
|
||||||
|
assert.Nil(t, UnmarshalYamlReader(reader, &v))
|
||||||
|
assert.Equal(t, rune(1), v.Machine["node1"])
|
||||||
|
assert.Equal(t, rune(2), v.Machine["node2"])
|
||||||
|
assert.Equal(t, rune(3), v.Machine["node3"])
|
||||||
|
}
|
||||||
|
|
||||||
type badReader struct{}
|
type badReader struct{}
|
||||||
|
|
||||||
func (b *badReader) Read(p []byte) (n int, err error) {
|
func (b *badReader) Read(p []byte) (n int, err error) {
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
package backoff
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/rand"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Func defines the method to calculate how long to retry.
|
|
||||||
type Func func(attempt int) time.Duration
|
|
||||||
|
|
||||||
// LinearWithJitter waits a set period of time, allowing for jitter (fractional adjustment).
|
|
||||||
func LinearWithJitter(waitBetween time.Duration, jitterFraction float64) Func {
|
|
||||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
||||||
return func(attempt int) time.Duration {
|
|
||||||
multiplier := jitterFraction * (r.Float64()*2 - 1)
|
|
||||||
return time.Duration(float64(waitBetween) * (1 + multiplier))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interval it waits for a fixed period of time between calls.
|
|
||||||
func Interval(interval time.Duration) Func {
|
|
||||||
return func(attempt int) time.Duration {
|
|
||||||
return interval
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exponential produces increasing intervals for each attempt.
|
|
||||||
func Exponential(scalar time.Duration) Func {
|
|
||||||
return func(attempt int) time.Duration {
|
|
||||||
return scalar * time.Duration((1<<attempt)>>1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package backoff
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestWaitBetween(t *testing.T) {
|
|
||||||
fn := Interval(time.Second)
|
|
||||||
assert.EqualValues(t, time.Second, fn(1))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExponential(t *testing.T) {
|
|
||||||
fn := Exponential(time.Second)
|
|
||||||
assert.EqualValues(t, time.Second, fn(1))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLinearWithJitter(t *testing.T) {
|
|
||||||
const rounds = 1000000
|
|
||||||
var total time.Duration
|
|
||||||
fn := LinearWithJitter(time.Second, 0.5)
|
|
||||||
for i := 0; i < rounds; i++ {
|
|
||||||
total += fn(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 0.1% tolerance
|
|
||||||
assert.True(t, total/time.Duration(rounds)-time.Second < time.Millisecond)
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package retry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/core/retry/backoff"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
)
|
|
||||||
|
|
||||||
// WithDisable disables the retry behaviour on this call, or this interceptor.
|
|
||||||
// It's semantically the same to `WithMax(0)`
|
|
||||||
func WithDisable() *CallOption {
|
|
||||||
return WithMax(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithMax sets the maximum number of retries on this call, or this interceptor.
|
|
||||||
func WithMax(maxRetries int) *CallOption {
|
|
||||||
return &CallOption{apply: func(options *options) {
|
|
||||||
options.max = maxRetries
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithBackoff sets the `BackoffFunc` used to control time between retries.
|
|
||||||
func WithBackoff(backoffFunc backoff.Func) *CallOption {
|
|
||||||
return &CallOption{apply: func(o *options) {
|
|
||||||
o.backoffFunc = backoffFunc
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithCodes Allow code to be retried.
|
|
||||||
func WithCodes(retryCodes ...codes.Code) *CallOption {
|
|
||||||
return &CallOption{apply: func(o *options) {
|
|
||||||
o.codes = retryCodes
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithPerRetryTimeout timeout for each retry
|
|
||||||
func WithPerRetryTimeout(timeout time.Duration) *CallOption {
|
|
||||||
return &CallOption{apply: func(o *options) {
|
|
||||||
o.perCallTimeout = timeout
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package retry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/tal-tech/go-zero/core/logx"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRetryWithDisable(t *testing.T) {
|
|
||||||
opt := &options{}
|
|
||||||
assert.EqualValues(t, &options{}, parseRetryCallOptions(opt, WithDisable()))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRetryWithMax(t *testing.T) {
|
|
||||||
n := 5
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
opt := &options{}
|
|
||||||
assert.EqualValues(t, &options{max: i}, parseRetryCallOptions(opt, WithMax(i)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRetryWithBackoff(t *testing.T) {
|
|
||||||
opt := &options{}
|
|
||||||
|
|
||||||
retryCallOptions := parseRetryCallOptions(opt, WithBackoff(func(attempt int) time.Duration {
|
|
||||||
return time.Millisecond
|
|
||||||
}))
|
|
||||||
assert.EqualValues(t, time.Millisecond, retryCallOptions.backoffFunc(1))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRetryWithCodes(t *testing.T) {
|
|
||||||
opt := &options{}
|
|
||||||
c := []codes.Code{codes.Unknown, codes.NotFound}
|
|
||||||
options := parseRetryCallOptions(opt, WithCodes(c...))
|
|
||||||
assert.EqualValues(t, c, options.codes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRetryWithPerRetryTimeout(t *testing.T) {
|
|
||||||
opt := &options{}
|
|
||||||
options := parseRetryCallOptions(opt, WithPerRetryTimeout(time.Millisecond))
|
|
||||||
assert.EqualValues(t, time.Millisecond, options.perCallTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_waitRetryBackoff(t *testing.T) {
|
|
||||||
logx.Disable()
|
|
||||||
|
|
||||||
opt := &options{perCallTimeout: time.Second, backoffFunc: func(attempt int) time.Duration {
|
|
||||||
return time.Second
|
|
||||||
}}
|
|
||||||
logger := logx.WithContext(context.Background())
|
|
||||||
err := waitRetryBackoff(logger, 1, context.Background(), opt)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Millisecond)
|
|
||||||
defer cancelFunc()
|
|
||||||
err = waitRetryBackoff(logger, 1, ctx, opt)
|
|
||||||
assert.ErrorIs(t, err, status.FromContextError(context.DeadlineExceeded).Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_isRetriable(t *testing.T) {
|
|
||||||
assert.False(t, isRetriable(status.FromContextError(context.DeadlineExceeded).Err(), &options{codes: DefaultRetriableCodes}))
|
|
||||||
assert.True(t, isRetriable(status.Error(codes.ResourceExhausted, ""), &options{codes: DefaultRetriableCodes}))
|
|
||||||
assert.False(t, isRetriable(errors.New("error"), &options{}))
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_perCallContext(t *testing.T) {
|
|
||||||
opt := &options{perCallTimeout: time.Second, includeRetryHeader: true}
|
|
||||||
ctx := metadata.NewIncomingContext(context.Background(), map[string][]string{"1": {"1"}})
|
|
||||||
callContext := perCallContext(ctx, opt, 1)
|
|
||||||
md, ok := metadata.FromOutgoingContext(callContext)
|
|
||||||
assert.True(t, ok)
|
|
||||||
assert.EqualValues(t, metadata.MD{"1": {"1"}, AttemptMetadataKey: {"1"}}, md)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Test_filterCallOptions(t *testing.T) {
|
|
||||||
grpcEmptyCallOpt := &grpc.EmptyCallOption{}
|
|
||||||
retryCallOpt := &CallOption{}
|
|
||||||
options, retryCallOptions := filterCallOptions([]grpc.CallOption{
|
|
||||||
grpcEmptyCallOpt,
|
|
||||||
retryCallOpt,
|
|
||||||
})
|
|
||||||
assert.EqualValues(t, []grpc.CallOption{grpcEmptyCallOpt}, options)
|
|
||||||
assert.EqualValues(t, []*CallOption{retryCallOpt}, retryCallOptions)
|
|
||||||
}
|
|
||||||
@@ -1,189 +0,0 @@
|
|||||||
package retry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/core/logx"
|
|
||||||
"github.com/tal-tech/go-zero/core/retry/backoff"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
const AttemptMetadataKey = "x-retry-attempt"
|
|
||||||
|
|
||||||
var (
|
|
||||||
// DefaultRetriableCodes default retry code
|
|
||||||
DefaultRetriableCodes = []codes.Code{codes.ResourceExhausted, codes.Unavailable}
|
|
||||||
// defaultRetryOptions default retry configuration
|
|
||||||
defaultRetryOptions = &options{
|
|
||||||
max: 0, // disabled
|
|
||||||
perCallTimeout: 0, // disabled
|
|
||||||
includeRetryHeader: true,
|
|
||||||
codes: DefaultRetriableCodes,
|
|
||||||
backoffFunc: backoff.LinearWithJitter(50*time.Millisecond /*jitter*/, 0.10),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// options retry the configuration
|
|
||||||
options struct {
|
|
||||||
max int
|
|
||||||
perCallTimeout time.Duration
|
|
||||||
includeRetryHeader bool
|
|
||||||
codes []codes.Code
|
|
||||||
backoffFunc backoff.Func
|
|
||||||
}
|
|
||||||
|
|
||||||
// CallOption is a grpc.CallOption that is local to grpc retry.
|
|
||||||
CallOption struct {
|
|
||||||
grpc.EmptyCallOption // make sure we implement private after() and before() fields so we don't panic.
|
|
||||||
apply func(opt *options)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func waitRetryBackoff(logger logx.Logger, attempt int, ctx context.Context, retryOptions *options) error {
|
|
||||||
var waitTime time.Duration = 0
|
|
||||||
if attempt > 0 {
|
|
||||||
waitTime = retryOptions.backoffFunc(attempt)
|
|
||||||
}
|
|
||||||
if waitTime > 0 {
|
|
||||||
timer := time.NewTimer(waitTime)
|
|
||||||
defer timer.Stop()
|
|
||||||
|
|
||||||
logger.Infof("grpc retry attempt: %d, backoff for %v", attempt, waitTime)
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return status.FromContextError(ctx.Err()).Err()
|
|
||||||
case <-timer.C:
|
|
||||||
// double check
|
|
||||||
err := ctx.Err()
|
|
||||||
if err != nil {
|
|
||||||
return status.FromContextError(err).Err()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func isRetriable(err error, retryOptions *options) bool {
|
|
||||||
errCode := status.Code(err)
|
|
||||||
if isContextError(err) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, code := range retryOptions.codes {
|
|
||||||
if code == errCode {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func isContextError(err error) bool {
|
|
||||||
code := status.Code(err)
|
|
||||||
return code == codes.DeadlineExceeded || code == codes.Canceled
|
|
||||||
}
|
|
||||||
|
|
||||||
func reuseOrNewWithCallOptions(opt *options, retryCallOptions []*CallOption) *options {
|
|
||||||
if len(retryCallOptions) == 0 {
|
|
||||||
return opt
|
|
||||||
}
|
|
||||||
|
|
||||||
return parseRetryCallOptions(opt, retryCallOptions...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseRetryCallOptions(opt *options, opts ...*CallOption) *options {
|
|
||||||
for _, option := range opts {
|
|
||||||
option.apply(opt)
|
|
||||||
}
|
|
||||||
|
|
||||||
return opt
|
|
||||||
}
|
|
||||||
|
|
||||||
func perCallContext(ctx context.Context, callOpts *options, attempt int) context.Context {
|
|
||||||
if attempt > 0 {
|
|
||||||
if callOpts.perCallTimeout != 0 {
|
|
||||||
var cancel context.CancelFunc
|
|
||||||
ctx, cancel = context.WithTimeout(ctx, callOpts.perCallTimeout)
|
|
||||||
_ = cancel
|
|
||||||
}
|
|
||||||
if callOpts.includeRetryHeader {
|
|
||||||
cloneMd := extractIncomingAndClone(ctx)
|
|
||||||
cloneMd.Set(AttemptMetadataKey, strconv.Itoa(attempt))
|
|
||||||
ctx = metadata.NewOutgoingContext(ctx, cloneMd)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
func extractIncomingAndClone(ctx context.Context) metadata.MD {
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
|
||||||
if !ok {
|
|
||||||
return metadata.MD{}
|
|
||||||
}
|
|
||||||
|
|
||||||
return md.Copy()
|
|
||||||
}
|
|
||||||
|
|
||||||
func filterCallOptions(callOptions []grpc.CallOption) (grpcOptions []grpc.CallOption, retryOptions []*CallOption) {
|
|
||||||
for _, opt := range callOptions {
|
|
||||||
if co, ok := opt.(*CallOption); ok {
|
|
||||||
retryOptions = append(retryOptions, co)
|
|
||||||
} else {
|
|
||||||
grpcOptions = append(grpcOptions, opt)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return grpcOptions, retryOptions
|
|
||||||
}
|
|
||||||
|
|
||||||
func Do(ctx context.Context, call func(ctx context.Context, opts ...grpc.CallOption) error, opts ...grpc.CallOption) error {
|
|
||||||
logger := logx.WithContext(ctx)
|
|
||||||
grpcOpts, retryOpts := filterCallOptions(opts)
|
|
||||||
callOpts := reuseOrNewWithCallOptions(defaultRetryOptions, retryOpts)
|
|
||||||
|
|
||||||
if callOpts.max == 0 {
|
|
||||||
return call(ctx, opts...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var lastErr error
|
|
||||||
for attempt := 0; attempt <= callOpts.max; attempt++ {
|
|
||||||
if err := waitRetryBackoff(logger, attempt, ctx, callOpts); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
callCtx := perCallContext(ctx, callOpts, attempt)
|
|
||||||
lastErr = call(callCtx, grpcOpts...)
|
|
||||||
|
|
||||||
if lastErr == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if attempt == 0 {
|
|
||||||
logger.Errorf("grpc call failed, got err: %v", lastErr)
|
|
||||||
} else {
|
|
||||||
logger.Errorf("grpc retry attempt: %d, got err: %v", attempt, lastErr)
|
|
||||||
}
|
|
||||||
if isContextError(lastErr) {
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
logger.Errorf("grpc retry attempt: %d, parent context error: %v", attempt, ctx.Err())
|
|
||||||
return lastErr
|
|
||||||
} else if callOpts.perCallTimeout != 0 {
|
|
||||||
logger.Errorf("grpc retry attempt: %d, context error from retry call", attempt)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !isRetriable(lastErr, callOpts) {
|
|
||||||
return lastErr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastErr
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package retry
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestDo(t *testing.T) {
|
|
||||||
n := 4
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
count := 0
|
|
||||||
err := Do(context.Background(), func(ctx context.Context, opts ...grpc.CallOption) error {
|
|
||||||
count++
|
|
||||||
return status.Error(codes.ResourceExhausted, "ResourceExhausted")
|
|
||||||
}, WithMax(i))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Equal(t, i+1, count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -104,10 +104,10 @@ GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Go 1.15 及之前版本
|
# Go 1.15 及之前版本
|
||||||
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl
|
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/tal-tech/go-zero/tools/goctl@cli
|
||||||
|
|
||||||
# Go 1.16 及以后版本
|
# Go 1.16 及以后版本
|
||||||
go install github.com/tal-tech/go-zero/tools/goctl@latest
|
GOPROXY=https://goproxy.cn/,direct go install github.com/tal-tech/go-zero/tools/goctl@cli
|
||||||
```
|
```
|
||||||
|
|
||||||
确保 goctl 可执行
|
确保 goctl 可执行
|
||||||
|
|||||||
@@ -107,10 +107,10 @@ go get -u github.com/tal-tech/go-zero
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
# for Go 1.15 and earlier
|
# for Go 1.15 and earlier
|
||||||
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl
|
GO111MODULE=on go get -u github.com/tal-tech/go-zero/tools/goctl@cli
|
||||||
|
|
||||||
# for Go 1.16 and later
|
# for Go 1.16 and later
|
||||||
go install github.com/tal-tech/go-zero/tools/goctl@latest
|
go install github.com/tal-tech/go-zero/tools/goctl@cli
|
||||||
```
|
```
|
||||||
|
|
||||||
make sure goctl is executable.
|
make sure goctl is executable.
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package cors
|
package cors
|
||||||
|
|
||||||
import "net/http"
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
allowOrigin = "Access-Control-Allow-Origin"
|
allowOrigin = "Access-Control-Allow-Origin"
|
||||||
@@ -23,23 +28,30 @@ const (
|
|||||||
|
|
||||||
// NotAllowedHandler handles cross domain not allowed requests.
|
// NotAllowedHandler handles cross domain not allowed requests.
|
||||||
// At most one origin can be specified, other origins are ignored if given, default to be *.
|
// At most one origin can be specified, other origins are ignored if given, default to be *.
|
||||||
func NotAllowedHandler(origins ...string) http.Handler {
|
func NotAllowedHandler(fn func(w http.ResponseWriter), origins ...string) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
checkAndSetHeaders(w, r, origins)
|
gw := &guardedResponseWriter{w: w}
|
||||||
|
checkAndSetHeaders(gw, r, origins)
|
||||||
|
if fn != nil {
|
||||||
|
fn(gw)
|
||||||
|
}
|
||||||
|
|
||||||
if r.Method != http.MethodOptions {
|
if r.Method == http.MethodOptions {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
gw.WriteHeader(http.StatusNoContent)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
gw.WriteHeader(http.StatusNotFound)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Middleware returns a middleware that adds CORS headers to the response.
|
// Middleware returns a middleware that adds CORS headers to the response.
|
||||||
func Middleware(origins ...string) func(http.HandlerFunc) http.HandlerFunc {
|
func Middleware(fn func(w http.Header), origins ...string) func(http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(next http.HandlerFunc) http.HandlerFunc {
|
return func(next http.HandlerFunc) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
checkAndSetHeaders(w, r, origins)
|
checkAndSetHeaders(w, r, origins)
|
||||||
|
if fn != nil {
|
||||||
|
fn(w.Header())
|
||||||
|
}
|
||||||
|
|
||||||
if r.Method == http.MethodOptions {
|
if r.Method == http.MethodOptions {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
@@ -50,6 +62,44 @@ func Middleware(origins ...string) func(http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type guardedResponseWriter struct {
|
||||||
|
w http.ResponseWriter
|
||||||
|
wroteHeader bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *guardedResponseWriter) Flush() {
|
||||||
|
if flusher, ok := w.w.(http.Flusher); ok {
|
||||||
|
flusher.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *guardedResponseWriter) Header() http.Header {
|
||||||
|
return w.w.Header()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hijack implements the http.Hijacker interface.
|
||||||
|
// This expands the Response to fulfill http.Hijacker if the underlying http.ResponseWriter supports it.
|
||||||
|
func (w *guardedResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
if hijacked, ok := w.w.(http.Hijacker); ok {
|
||||||
|
return hijacked.Hijack()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, errors.New("server doesn't support hijacking")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *guardedResponseWriter) Write(bytes []byte) (int, error) {
|
||||||
|
return w.w.Write(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *guardedResponseWriter) WriteHeader(code int) {
|
||||||
|
if w.wroteHeader {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.w.WriteHeader(code)
|
||||||
|
w.wroteHeader = true
|
||||||
|
}
|
||||||
|
|
||||||
func checkAndSetHeaders(w http.ResponseWriter, r *http.Request, origins []string) {
|
func checkAndSetHeaders(w http.ResponseWriter, r *http.Request, origins []string) {
|
||||||
setVaryHeaders(w, r)
|
setVaryHeaders(w, r)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package cors
|
package cors
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -62,7 +64,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
|
|||||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||||
r.Header.Set(originHeader, test.reqOrigin)
|
r.Header.Set(originHeader, test.reqOrigin)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler := NotAllowedHandler(test.origins...)
|
handler := NotAllowedHandler(nil, test.origins...)
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
if method == http.MethodOptions {
|
if method == http.MethodOptions {
|
||||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||||
@@ -71,6 +73,22 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||||
})
|
})
|
||||||
|
t.Run(test.name+"-handler-custom", func(t *testing.T) {
|
||||||
|
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||||
|
r.Header.Set(originHeader, test.reqOrigin)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
handler := NotAllowedHandler(func(w http.ResponseWriter) {
|
||||||
|
w.Header().Set("foo", "bar")
|
||||||
|
}, test.origins...)
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
if method == http.MethodOptions {
|
||||||
|
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, http.StatusNotFound, w.Result().StatusCode)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||||
|
assert.Equal(t, "bar", w.Header().Get("foo"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +99,7 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
|
|||||||
r := httptest.NewRequest(method, "http://localhost", nil)
|
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||||
r.Header.Set(originHeader, test.reqOrigin)
|
r.Header.Set(originHeader, test.reqOrigin)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
handler := Middleware(test.origins...)(func(w http.ResponseWriter, r *http.Request) {
|
handler := Middleware(nil, test.origins...)(func(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
@@ -92,6 +110,69 @@ func TestCorsHandlerWithOrigins(t *testing.T) {
|
|||||||
}
|
}
|
||||||
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||||
})
|
})
|
||||||
|
t.Run(test.name+"-middleware-custom", func(t *testing.T) {
|
||||||
|
r := httptest.NewRequest(method, "http://localhost", nil)
|
||||||
|
r.Header.Set(originHeader, test.reqOrigin)
|
||||||
|
w := httptest.NewRecorder()
|
||||||
|
handler := Middleware(func(header http.Header) {
|
||||||
|
header.Set("foo", "bar")
|
||||||
|
}, test.origins...)(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
})
|
||||||
|
handler.ServeHTTP(w, r)
|
||||||
|
if method == http.MethodOptions {
|
||||||
|
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||||
|
} else {
|
||||||
|
assert.Equal(t, http.StatusOK, w.Result().StatusCode)
|
||||||
|
}
|
||||||
|
assert.Equal(t, test.expect, w.Header().Get(allowOrigin))
|
||||||
|
assert.Equal(t, "bar", w.Header().Get("foo"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGuardedResponseWriter_Flush(t *testing.T) {
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "http://localhost", nil)
|
||||||
|
handler := NotAllowedHandler(func(w http.ResponseWriter) {
|
||||||
|
w.Header().Set("X-Test", "test")
|
||||||
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
|
_, err := w.Write([]byte("content"))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
flusher, ok := w.(http.Flusher)
|
||||||
|
assert.True(t, ok)
|
||||||
|
flusher.Flush()
|
||||||
|
}, "foo.com")
|
||||||
|
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
handler.ServeHTTP(resp, req)
|
||||||
|
assert.Equal(t, http.StatusServiceUnavailable, resp.Code)
|
||||||
|
assert.Equal(t, "test", resp.Header().Get("X-Test"))
|
||||||
|
assert.Equal(t, "content", resp.Body.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGuardedResponseWriter_Hijack(t *testing.T) {
|
||||||
|
resp := httptest.NewRecorder()
|
||||||
|
writer := &guardedResponseWriter{
|
||||||
|
w: resp,
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
writer.Hijack()
|
||||||
|
})
|
||||||
|
|
||||||
|
writer = &guardedResponseWriter{
|
||||||
|
w: mockedHijackable{resp},
|
||||||
|
}
|
||||||
|
assert.NotPanics(t, func() {
|
||||||
|
writer.Hijack()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type mockedHijackable struct {
|
||||||
|
*httptest.ResponseRecorder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m mockedHijackable) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
return nil, nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -99,8 +99,18 @@ func ToMiddleware(handler func(next http.Handler) http.Handler) Middleware {
|
|||||||
// WithCors returns a func to enable CORS for given origin, or default to all origins (*).
|
// WithCors returns a func to enable CORS for given origin, or default to all origins (*).
|
||||||
func WithCors(origin ...string) RunOption {
|
func WithCors(origin ...string) RunOption {
|
||||||
return func(server *Server) {
|
return func(server *Server) {
|
||||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(origin...))
|
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(nil, origin...))
|
||||||
server.Use(cors.Middleware(origin...))
|
server.Use(cors.Middleware(nil, origin...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithCustomCors returns a func to enable CORS for given origin, or default to all origins (*),
|
||||||
|
// fn lets caller customizing the response.
|
||||||
|
func WithCustomCors(middlewareFn func(header http.Header), notAllowedFn func(http.ResponseWriter),
|
||||||
|
origin ...string) RunOption {
|
||||||
|
return func(server *Server) {
|
||||||
|
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(notAllowedFn, origin...))
|
||||||
|
server.Use(cors.Middleware(middlewareFn, origin...))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -310,3 +310,22 @@ Port: 54321
|
|||||||
opt := WithCors("local")
|
opt := WithCors("local")
|
||||||
opt(srv)
|
opt(srv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWithCustomCors(t *testing.T) {
|
||||||
|
const configYaml = `
|
||||||
|
Name: foo
|
||||||
|
Port: 54321
|
||||||
|
`
|
||||||
|
var cnf RestConf
|
||||||
|
assert.Nil(t, conf.LoadConfigFromYamlBytes([]byte(configYaml), &cnf))
|
||||||
|
rt := router.NewRouter()
|
||||||
|
srv, err := NewServer(cnf, WithRouter(rt))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
opt := WithCustomCors(func(header http.Header) {
|
||||||
|
header.Set("foo", "bar")
|
||||||
|
}, func(w http.ResponseWriter) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}, "local")
|
||||||
|
opt(srv)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package gogen
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/config"
|
"github.com/tal-tech/go-zero/tools/goctl/config"
|
||||||
ctlutil "github.com/tal-tech/go-zero/tools/goctl/util"
|
ctlutil "github.com/tal-tech/go-zero/tools/goctl/util"
|
||||||
@@ -64,12 +66,8 @@ func genLogicByRoute(dir, rootPkg string, cfg *config.Config, group spec.Group,
|
|||||||
var requestString string
|
var requestString string
|
||||||
if len(route.ResponseTypeName()) > 0 {
|
if len(route.ResponseTypeName()) > 0 {
|
||||||
resp := responseGoTypeName(route, typesPacket)
|
resp := responseGoTypeName(route, typesPacket)
|
||||||
responseString = "(" + resp + ", error)"
|
responseString = "(resp " + resp + ", err error)"
|
||||||
if strings.HasPrefix(resp, "*") {
|
returnString = "return"
|
||||||
returnString = fmt.Sprintf("return &%s{}, nil", strings.TrimPrefix(resp, "*"))
|
|
||||||
} else {
|
|
||||||
returnString = fmt.Sprintf("return %s{}, nil", resp)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
responseString = "error"
|
responseString = "error"
|
||||||
returnString = "return nil"
|
returnString = "return nil"
|
||||||
@@ -116,9 +114,47 @@ func genLogicImports(route spec.Route, parentPkg string) string {
|
|||||||
var imports []string
|
var imports []string
|
||||||
imports = append(imports, `"context"`+"\n")
|
imports = append(imports, `"context"`+"\n")
|
||||||
imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, contextDir)))
|
imports = append(imports, fmt.Sprintf("\"%s\"", ctlutil.JoinPackages(parentPkg, contextDir)))
|
||||||
if len(route.ResponseTypeName()) > 0 || len(route.RequestTypeName()) > 0 {
|
if shallImportTypesPackage(route) {
|
||||||
imports = append(imports, fmt.Sprintf("\"%s\"\n", ctlutil.JoinPackages(parentPkg, typesDir)))
|
imports = append(imports, fmt.Sprintf("\"%s\"\n", ctlutil.JoinPackages(parentPkg, typesDir)))
|
||||||
}
|
}
|
||||||
imports = append(imports, fmt.Sprintf("\"%s/core/logx\"", vars.ProjectOpenSourceURL))
|
imports = append(imports, fmt.Sprintf("\"%s/core/logx\"", vars.ProjectOpenSourceURL))
|
||||||
return strings.Join(imports, "\n\t")
|
return strings.Join(imports, "\n\t")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func onlyPrimitiveTypes(val string) bool {
|
||||||
|
fields := strings.FieldsFunc(val, func(r rune) bool {
|
||||||
|
return r == '[' || r == ']' || r == ' '
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, field := range fields {
|
||||||
|
if field == "map" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// ignore array dimension number, like [5]int
|
||||||
|
if _, err := strconv.Atoi(field); err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !api.IsBasicType(field) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func shallImportTypesPackage(route spec.Route) bool {
|
||||||
|
if len(route.RequestTypeName()) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
respTypeName := route.ResponseTypeName()
|
||||||
|
if len(respTypeName) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if onlyPrimitiveTypes(respTypeName) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ var mapping = map[string]string{
|
|||||||
"post": "http.MethodPost",
|
"post": "http.MethodPost",
|
||||||
"put": "http.MethodPut",
|
"put": "http.MethodPut",
|
||||||
"patch": "http.MethodPatch",
|
"patch": "http.MethodPatch",
|
||||||
|
"connect": "http.MethodConnect",
|
||||||
|
"options": "http.MethodOptions",
|
||||||
|
"trace": "http.MethodTrace",
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -63,11 +63,11 @@ serviceApi: {match(p,"service")}serviceToken=ID serviceName lbrace='{' servi
|
|||||||
serviceRoute: atDoc? (atServer|atHandler) route;
|
serviceRoute: atDoc? (atServer|atHandler) route;
|
||||||
atDoc: ATDOC lp='('? ((kvLit+)|STRING) rp=')'?;
|
atDoc: ATDOC lp='('? ((kvLit+)|STRING) rp=')'?;
|
||||||
atHandler: ATHANDLER ID;
|
atHandler: ATHANDLER ID;
|
||||||
route: {checkHttpMethod(p)}httpMethod=ID path request=body? returnToken=ID? response=replybody?;
|
route: {checkHTTPMethod(p)}httpMethod=ID path request=body? returnToken=ID? response=replybody?;
|
||||||
body: lp='(' (ID)? rp=')';
|
body: lp='(' (ID)? rp=')';
|
||||||
replybody: lp='(' dataType? rp=')';
|
replybody: lp='(' dataType? rp=')';
|
||||||
// kv
|
// kv
|
||||||
kvLit: key=ID {checkKeyValue(p)}value=LINE_VALUE;
|
kvLit: key=ID {checkKeyValue(p)}value=LINE_VALUE;
|
||||||
|
|
||||||
serviceName: (ID '-'?)+;
|
serviceName: (ID '-'?)+;
|
||||||
path: (('/' (ID ('-' ID)*))|('/:' (ID ('-' ID)?)))+;
|
path: (('/' (ID ('-' ID)*))|('/:' (ID ('-' ID)?)))+ | '/';
|
||||||
@@ -2,11 +2,14 @@ package ast
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const prefixKey = "prefix"
|
||||||
|
|
||||||
// Api describes syntax for api
|
// Api describes syntax for api
|
||||||
type Api struct {
|
type Api struct {
|
||||||
LinePrefix string
|
LinePrefix string
|
||||||
@@ -49,8 +52,15 @@ func (v *ApiVisitor) acceptService(root, final *Api) {
|
|||||||
}
|
}
|
||||||
v.duplicateServerItemCheck(service)
|
v.duplicateServerItemCheck(service)
|
||||||
|
|
||||||
|
var prefix string
|
||||||
|
if service.AtServer != nil {
|
||||||
|
p := service.AtServer.Kv.Get(prefixKey)
|
||||||
|
if p != nil {
|
||||||
|
prefix = p.Text()
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, route := range service.ServiceApi.ServiceRoute {
|
for _, route := range service.ServiceApi.ServiceRoute {
|
||||||
uniqueRoute := fmt.Sprintf("%s %s", route.Route.Method.Text(), route.Route.Path.Text())
|
uniqueRoute := fmt.Sprintf("%s %s", route.Route.Method.Text(), path.Join(prefix, route.Route.Path.Text()))
|
||||||
if _, ok := final.routeM[uniqueRoute]; ok {
|
if _, ok := final.routeM[uniqueRoute]; ok {
|
||||||
v.panic(route.Route.Method, fmt.Sprintf("duplicate route '%s'", uniqueRoute))
|
v.panic(route.Route.Method, fmt.Sprintf("duplicate route '%s'", uniqueRoute))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package ast
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -113,13 +114,13 @@ func (p *Parser) parse(filename, content string) (*Api, error) {
|
|||||||
apiAstList = append(apiAstList, root)
|
apiAstList = append(apiAstList, root)
|
||||||
for _, imp := range root.Import {
|
for _, imp := range root.Import {
|
||||||
dir := filepath.Dir(p.src)
|
dir := filepath.Dir(p.src)
|
||||||
path := filepath.Join(dir, imp.Value.Text())
|
imp := filepath.Join(dir, imp.Value.Text())
|
||||||
data, err := p.readContent(path)
|
data, err := p.readContent(imp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nestedApi, err := p.invoke(path, data)
|
nestedApi, err := p.invoke(imp, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -196,8 +197,8 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
|||||||
if handler.IsNotNil() {
|
if handler.IsNotNil() {
|
||||||
handlerName := handler.Text()
|
handlerName := handler.Text()
|
||||||
handlerMap[handlerName] = Holder
|
handlerMap[handlerName] = Holder
|
||||||
path := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
route := fmt.Sprintf("%s://%s", g.Route.Method.Text(), g.Route.Path.Text())
|
||||||
routeMap[path] = Holder
|
routeMap[route] = Holder
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,6 +240,13 @@ func (p *Parser) valid(mainApi, nestedApi *Api) error {
|
|||||||
|
|
||||||
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
|
func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMap map[string]PlaceHolder) error {
|
||||||
for _, each := range nestedApi.Service {
|
for _, each := range nestedApi.Service {
|
||||||
|
var prefix string
|
||||||
|
if each.AtServer != nil {
|
||||||
|
p := each.AtServer.Kv.Get(prefixKey)
|
||||||
|
if p != nil {
|
||||||
|
prefix = p.Text()
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, r := range each.ServiceApi.ServiceRoute {
|
for _, r := range each.ServiceApi.ServiceRoute {
|
||||||
handler := r.GetHandler()
|
handler := r.GetHandler()
|
||||||
if !handler.IsNotNil() {
|
if !handler.IsNotNil() {
|
||||||
@@ -250,8 +258,8 @@ func (p *Parser) duplicateRouteCheck(nestedApi *Api, mainHandlerMap, mainRouteMa
|
|||||||
nestedApi.LinePrefix, handler.Line(), handler.Column(), handler.Text())
|
nestedApi.LinePrefix, handler.Line(), handler.Column(), handler.Text())
|
||||||
}
|
}
|
||||||
|
|
||||||
path := fmt.Sprintf("%s://%s", r.Route.Method.Text(), r.Route.Path.Text())
|
p := fmt.Sprintf("%s://%s", r.Route.Method.Text(), path.Join(prefix, r.Route.Path.Text()))
|
||||||
if _, ok := mainRouteMap[path]; ok {
|
if _, ok := mainRouteMap[p]; ok {
|
||||||
return fmt.Errorf("%s line %d:%d duplicate route '%s'",
|
return fmt.Errorf("%s line %d:%d duplicate route '%s'",
|
||||||
nestedApi.LinePrefix, r.Route.Method.Line(), r.Route.Method.Column(), r.Route.Method.Text()+" "+r.Route.Path.Text())
|
nestedApi.LinePrefix, r.Route.Method.Line(), r.Route.Method.Column(), r.Route.Method.Text()+" "+r.Route.Path.Text())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,11 +267,8 @@ func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} {
|
|||||||
}
|
}
|
||||||
case *Literal:
|
case *Literal:
|
||||||
lit := dataType.Literal.Text()
|
lit := dataType.Literal.Text()
|
||||||
if api.IsGolangKeyWord(dataType.Literal.Text()) {
|
if api.IsGolangKeyWord(lit) {
|
||||||
v.panic(dataType.Literal, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", dataType.Literal.Text()))
|
v.panic(dataType.Literal, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", lit))
|
||||||
}
|
|
||||||
if api.IsBasicType(lit) {
|
|
||||||
v.panic(dt.Expr(), fmt.Sprintf("unsupport %s", dt.Expr().Text()))
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
v.panic(dt.Expr(), fmt.Sprintf("unsupport %s", dt.Expr().Text()))
|
v.panic(dt.Expr(), fmt.Sprintf("unsupport %s", dt.Expr().Text()))
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
|
||||||
|
|
||||||
package api // ApiParser
|
package api // ApiParser
|
||||||
import "github.com/zeromicro/antlr"
|
import "github.com/zeromicro/antlr"
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
|
||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -10,10 +8,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Suppress unused import error
|
// Suppress unused import error
|
||||||
var (
|
var _ = fmt.Printf
|
||||||
_ = fmt.Printf
|
var _ = unicode.IsLetter
|
||||||
_ = unicode.IsLetter
|
|
||||||
)
|
|
||||||
|
|
||||||
var serializedLexerAtn = []uint16{
|
var serializedLexerAtn = []uint16{
|
||||||
3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 25, 266,
|
3, 24715, 42794, 33075, 47597, 16764, 15335, 30598, 22884, 2, 25, 266,
|
||||||
|
|||||||
5304
tools/goctl/api/parser/g4/gen/api/apiparser_parser.go
Normal file → Executable file
5304
tools/goctl/api/parser/g4/gen/api/apiparser_parser.go
Normal file → Executable file
File diff suppressed because it is too large
Load Diff
615
tools/goctl/api/parser/g4/gen/api/apiparser_parser1.go
Executable file
615
tools/goctl/api/parser/g4/gen/api/apiparser_parser1.go
Executable file
@@ -0,0 +1,615 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 1
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) GetSyntaxToken() antlr.Token { return s.syntaxToken }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) GetAssign() antlr.Token { return s.assign }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) GetVersion() antlr.Token { return s.version }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) SetSyntaxToken(v antlr.Token) { s.syntaxToken = v }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) SetVersion(v antlr.Token) { s.version = v }
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) STRING() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserSTRING, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SyntaxLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitSyntaxLit(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) SyntaxLit() (localctx ISyntaxLitContext) {
|
||||||
|
localctx = NewSyntaxLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 4, ApiParserParserRULE_syntaxLit)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "syntax")
|
||||||
|
{
|
||||||
|
p.SetState(88)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*SyntaxLitContext).syntaxToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(89)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__0)
|
||||||
|
|
||||||
|
localctx.(*SyntaxLitContext).assign = _m
|
||||||
|
}
|
||||||
|
checkVersion(p)
|
||||||
|
{
|
||||||
|
p.SetState(91)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserSTRING)
|
||||||
|
|
||||||
|
localctx.(*SyntaxLitContext).version = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IImportSpecContext is an interface to support dynamic dispatch.
|
||||||
|
type IImportSpecContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsImportSpecContext differentiates from other interfaces.
|
||||||
|
IsImportSpecContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportSpecContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyImportSpecContext() *ImportSpecContext {
|
||||||
|
var p = new(ImportSpecContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importSpec
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ImportSpecContext) IsImportSpecContext() {}
|
||||||
|
|
||||||
|
func NewImportSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportSpecContext {
|
||||||
|
var p = new(ImportSpecContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importSpec
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) ImportLit() IImportLitContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportLitContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IImportLitContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) ImportBlock() IImportBlockContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportBlockContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IImportBlockContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitImportSpec(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ImportSpec() (localctx IImportSpecContext) {
|
||||||
|
localctx = NewImportSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 6, ApiParserParserRULE_importSpec)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(95)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 2, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(93)
|
||||||
|
p.ImportLit()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(94)
|
||||||
|
p.ImportBlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IImportLitContext is an interface to support dynamic dispatch.
|
||||||
|
type IImportLitContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetImportToken returns the importToken token.
|
||||||
|
GetImportToken() antlr.Token
|
||||||
|
|
||||||
|
// SetImportToken sets the importToken token.
|
||||||
|
SetImportToken(antlr.Token)
|
||||||
|
|
||||||
|
// IsImportLitContext differentiates from other interfaces.
|
||||||
|
IsImportLitContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportLitContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
importToken antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyImportLitContext() *ImportLitContext {
|
||||||
|
var p = new(ImportLitContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importLit
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ImportLitContext) IsImportLitContext() {}
|
||||||
|
|
||||||
|
func NewImportLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportLitContext {
|
||||||
|
var p = new(ImportLitContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importLit
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportLitContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ImportLitContext) GetImportToken() antlr.Token { return s.importToken }
|
||||||
|
|
||||||
|
func (s *ImportLitContext) SetImportToken(v antlr.Token) { s.importToken = v }
|
||||||
|
|
||||||
|
func (s *ImportLitContext) ImportValue() IImportValueContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportValueContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IImportValueContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportLitContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportLitContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitImportLit(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ImportLit() (localctx IImportLitContext) {
|
||||||
|
localctx = NewImportLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 8, ApiParserParserRULE_importLit)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "import")
|
||||||
|
{
|
||||||
|
p.SetState(98)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*ImportLitContext).importToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(99)
|
||||||
|
p.ImportValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IImportBlockContext is an interface to support dynamic dispatch.
|
||||||
|
type IImportBlockContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetImportToken returns the importToken token.
|
||||||
|
GetImportToken() antlr.Token
|
||||||
|
|
||||||
|
// SetImportToken sets the importToken token.
|
||||||
|
SetImportToken(antlr.Token)
|
||||||
|
|
||||||
|
// IsImportBlockContext differentiates from other interfaces.
|
||||||
|
IsImportBlockContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportBlockContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
importToken antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyImportBlockContext() *ImportBlockContext {
|
||||||
|
var p = new(ImportBlockContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importBlock
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ImportBlockContext) IsImportBlockContext() {}
|
||||||
|
|
||||||
|
func NewImportBlockContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportBlockContext {
|
||||||
|
var p = new(ImportBlockContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importBlock
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) GetImportToken() antlr.Token { return s.importToken }
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) SetImportToken(v antlr.Token) { s.importToken = v }
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) AllImportBlockValue() []IImportBlockValueContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IImportBlockValueContext)(nil)).Elem())
|
||||||
|
var tst = make([]IImportBlockValueContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IImportBlockValueContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) ImportBlockValue(i int) IImportBlockValueContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportBlockValueContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IImportBlockValueContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitImportBlock(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ImportBlock() (localctx IImportBlockContext) {
|
||||||
|
localctx = NewImportBlockContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 10, ApiParserParserRULE_importBlock)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "import")
|
||||||
|
{
|
||||||
|
p.SetState(102)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*ImportBlockContext).importToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(103)
|
||||||
|
p.Match(ApiParserParserT__1)
|
||||||
|
}
|
||||||
|
p.SetState(105)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserSTRING {
|
||||||
|
{
|
||||||
|
p.SetState(104)
|
||||||
|
p.ImportBlockValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(107)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(109)
|
||||||
|
p.Match(ApiParserParserT__2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IImportBlockValueContext is an interface to support dynamic dispatch.
|
||||||
|
type IImportBlockValueContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsImportBlockValueContext differentiates from other interfaces.
|
||||||
|
IsImportBlockValueContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportBlockValueContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyImportBlockValueContext() *ImportBlockValueContext {
|
||||||
|
var p = new(ImportBlockValueContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importBlockValue
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ImportBlockValueContext) IsImportBlockValueContext() {}
|
||||||
|
|
||||||
|
func NewImportBlockValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportBlockValueContext {
|
||||||
|
var p = new(ImportBlockValueContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importBlockValue
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockValueContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ImportBlockValueContext) ImportValue() IImportValueContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IImportValueContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IImportValueContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockValueContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportBlockValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitImportBlockValue(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ImportBlockValue() (localctx IImportBlockValueContext) {
|
||||||
|
localctx = NewImportBlockValueContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 12, ApiParserParserRULE_importBlockValue)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(111)
|
||||||
|
p.ImportValue()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IImportValueContext is an interface to support dynamic dispatch.
|
||||||
|
type IImportValueContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsImportValueContext differentiates from other interfaces.
|
||||||
|
IsImportValueContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ImportValueContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyImportValueContext() *ImportValueContext {
|
||||||
|
var p = new(ImportValueContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importValue
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ImportValueContext) IsImportValueContext() {}
|
||||||
|
|
||||||
|
func NewImportValueContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ImportValueContext {
|
||||||
|
var p = new(ImportValueContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_importValue
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
656
tools/goctl/api/parser/g4/gen/api/apiparser_parser2.go
Executable file
656
tools/goctl/api/parser/g4/gen/api/apiparser_parser2.go
Executable file
@@ -0,0 +1,656 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 2
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
func (s *ImportValueContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ImportValueContext) STRING() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserSTRING, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportValueContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportValueContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ImportValueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitImportValue(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ImportValue() (localctx IImportValueContext) {
|
||||||
|
localctx = NewImportValueContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 14, ApiParserParserRULE_importValue)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkImportValue(p)
|
||||||
|
{
|
||||||
|
p.SetState(114)
|
||||||
|
p.Match(ApiParserParserSTRING)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IInfoSpecContext is an interface to support dynamic dispatch.
|
||||||
|
type IInfoSpecContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetInfoToken returns the infoToken token.
|
||||||
|
GetInfoToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetInfoToken sets the infoToken token.
|
||||||
|
SetInfoToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsInfoSpecContext differentiates from other interfaces.
|
||||||
|
IsInfoSpecContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type InfoSpecContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
infoToken antlr.Token
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyInfoSpecContext() *InfoSpecContext {
|
||||||
|
var p = new(InfoSpecContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_infoSpec
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*InfoSpecContext) IsInfoSpecContext() {}
|
||||||
|
|
||||||
|
func NewInfoSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *InfoSpecContext {
|
||||||
|
var p = new(InfoSpecContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_infoSpec
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) GetInfoToken() antlr.Token { return s.infoToken }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) SetInfoToken(v antlr.Token) { s.infoToken = v }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) AllKvLit() []IKvLitContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||||
|
var tst = make([]IKvLitContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) KvLit(i int) IKvLitContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InfoSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitInfoSpec(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) InfoSpec() (localctx IInfoSpecContext) {
|
||||||
|
localctx = NewInfoSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 16, ApiParserParserRULE_infoSpec)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "info")
|
||||||
|
{
|
||||||
|
p.SetState(117)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*InfoSpecContext).infoToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(118)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*InfoSpecContext).lp = _m
|
||||||
|
}
|
||||||
|
p.SetState(120)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(119)
|
||||||
|
p.KvLit()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(122)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(124)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*InfoSpecContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeSpecContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeSpecContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsTypeSpecContext differentiates from other interfaces.
|
||||||
|
IsTypeSpecContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeSpecContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeSpecContext() *TypeSpecContext {
|
||||||
|
var p = new(TypeSpecContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeSpec
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeSpecContext) IsTypeSpecContext() {}
|
||||||
|
|
||||||
|
func NewTypeSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeSpecContext {
|
||||||
|
var p = new(TypeSpecContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeSpec
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) TypeLit() ITypeLitContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeLitContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeLitContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) TypeBlock() ITypeBlockContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeBlockContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeSpec(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeSpec() (localctx ITypeSpecContext) {
|
||||||
|
localctx = NewTypeSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 18, ApiParserParserRULE_typeSpec)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(128)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 5, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(126)
|
||||||
|
p.TypeLit()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(127)
|
||||||
|
p.TypeBlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeLitContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeLitContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetTypeToken returns the typeToken token.
|
||||||
|
GetTypeToken() antlr.Token
|
||||||
|
|
||||||
|
// SetTypeToken sets the typeToken token.
|
||||||
|
SetTypeToken(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeLitContext differentiates from other interfaces.
|
||||||
|
IsTypeLitContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeLitContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
typeToken antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeLitContext() *TypeLitContext {
|
||||||
|
var p = new(TypeLitContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeLit
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeLitContext) IsTypeLitContext() {}
|
||||||
|
|
||||||
|
func NewTypeLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeLitContext {
|
||||||
|
var p = new(TypeLitContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeLit
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeLitContext) GetTypeToken() antlr.Token { return s.typeToken }
|
||||||
|
|
||||||
|
func (s *TypeLitContext) SetTypeToken(v antlr.Token) { s.typeToken = v }
|
||||||
|
|
||||||
|
func (s *TypeLitContext) TypeLitBody() ITypeLitBodyContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeLitBodyContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeLitBodyContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeLit(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeLit() (localctx ITypeLitContext) {
|
||||||
|
localctx = NewTypeLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 20, ApiParserParserRULE_typeLit)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "type")
|
||||||
|
{
|
||||||
|
p.SetState(131)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeLitContext).typeToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(132)
|
||||||
|
p.TypeLitBody()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeBlockContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeBlockContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetTypeToken returns the typeToken token.
|
||||||
|
GetTypeToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetTypeToken sets the typeToken token.
|
||||||
|
SetTypeToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeBlockContext differentiates from other interfaces.
|
||||||
|
IsTypeBlockContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeBlockContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
typeToken antlr.Token
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeBlockContext() *TypeBlockContext {
|
||||||
|
var p = new(TypeBlockContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlock
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeBlockContext) IsTypeBlockContext() {}
|
||||||
|
|
||||||
|
func NewTypeBlockContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockContext {
|
||||||
|
var p = new(TypeBlockContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlock
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) GetTypeToken() antlr.Token { return s.typeToken }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) SetTypeToken(v antlr.Token) { s.typeToken = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) AllTypeBlockBody() []ITypeBlockBodyContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*ITypeBlockBodyContext)(nil)).Elem())
|
||||||
|
var tst = make([]ITypeBlockBodyContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(ITypeBlockBodyContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) TypeBlockBody(i int) ITypeBlockBodyContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockBodyContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeBlockBodyContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeBlock(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeBlock() (localctx ITypeBlockContext) {
|
||||||
|
localctx = NewTypeBlockContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 22, ApiParserParserRULE_typeBlock)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "type")
|
||||||
|
{
|
||||||
|
p.SetState(135)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockContext).typeToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(136)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockContext).lp = _m
|
||||||
|
}
|
||||||
|
p.SetState(140)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
for _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(137)
|
||||||
|
p.TypeBlockBody()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(142)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(143)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
637
tools/goctl/api/parser/g4/gen/api/apiparser_parser3.go
Executable file
637
tools/goctl/api/parser/g4/gen/api/apiparser_parser3.go
Executable file
@@ -0,0 +1,637 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 3
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
// ITypeLitBodyContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeLitBodyContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsTypeLitBodyContext differentiates from other interfaces.
|
||||||
|
IsTypeLitBodyContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeLitBodyContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeLitBodyContext() *TypeLitBodyContext {
|
||||||
|
var p = new(TypeLitBodyContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeLitBody
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeLitBodyContext) IsTypeLitBodyContext() {}
|
||||||
|
|
||||||
|
func NewTypeLitBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeLitBodyContext {
|
||||||
|
var p = new(TypeLitBodyContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeLitBody
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) TypeStruct() ITypeStructContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeStructContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeStructContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) TypeAlias() ITypeAliasContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeAliasContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeAliasContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeLitBodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeLitBody(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeLitBody() (localctx ITypeLitBodyContext) {
|
||||||
|
localctx = NewTypeLitBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 24, ApiParserParserRULE_typeLitBody)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(147)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 7, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(145)
|
||||||
|
p.TypeStruct()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(146)
|
||||||
|
p.TypeAlias()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeBlockBodyContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeBlockBodyContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsTypeBlockBodyContext differentiates from other interfaces.
|
||||||
|
IsTypeBlockBodyContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeBlockBodyContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeBlockBodyContext() *TypeBlockBodyContext {
|
||||||
|
var p = new(TypeBlockBodyContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockBody
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeBlockBodyContext) IsTypeBlockBodyContext() {}
|
||||||
|
|
||||||
|
func NewTypeBlockBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockBodyContext {
|
||||||
|
var p = new(TypeBlockBodyContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockBody
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) TypeBlockStruct() ITypeBlockStructContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockStructContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeBlockStructContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) TypeBlockAlias() ITypeBlockAliasContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeBlockAliasContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeBlockAliasContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockBodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeBlockBody(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeBlockBody() (localctx ITypeBlockBodyContext) {
|
||||||
|
localctx = NewTypeBlockBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 26, ApiParserParserRULE_typeBlockBody)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(151)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 8, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(149)
|
||||||
|
p.TypeBlockStruct()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(150)
|
||||||
|
p.TypeBlockAlias()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeStructContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeStructContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetStructName returns the structName token.
|
||||||
|
GetStructName() antlr.Token
|
||||||
|
|
||||||
|
// GetStructToken returns the structToken token.
|
||||||
|
GetStructToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLbrace returns the lbrace token.
|
||||||
|
GetLbrace() antlr.Token
|
||||||
|
|
||||||
|
// GetRbrace returns the rbrace token.
|
||||||
|
GetRbrace() antlr.Token
|
||||||
|
|
||||||
|
// SetStructName sets the structName token.
|
||||||
|
SetStructName(antlr.Token)
|
||||||
|
|
||||||
|
// SetStructToken sets the structToken token.
|
||||||
|
SetStructToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLbrace sets the lbrace token.
|
||||||
|
SetLbrace(antlr.Token)
|
||||||
|
|
||||||
|
// SetRbrace sets the rbrace token.
|
||||||
|
SetRbrace(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeStructContext differentiates from other interfaces.
|
||||||
|
IsTypeStructContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeStructContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
structName antlr.Token
|
||||||
|
structToken antlr.Token
|
||||||
|
lbrace antlr.Token
|
||||||
|
rbrace antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeStructContext() *TypeStructContext {
|
||||||
|
var p = new(TypeStructContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeStruct
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeStructContext) IsTypeStructContext() {}
|
||||||
|
|
||||||
|
func NewTypeStructContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeStructContext {
|
||||||
|
var p = new(TypeStructContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeStruct
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetStructName() antlr.Token { return s.structName }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetStructToken() antlr.Token { return s.structToken }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) SetStructName(v antlr.Token) { s.structName = v }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) SetStructToken(v antlr.Token) { s.structToken = v }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||||
|
|
||||||
|
func (s *TypeStructContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) AllField() []IFieldContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IFieldContext)(nil)).Elem())
|
||||||
|
var tst = make([]IFieldContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IFieldContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) Field(i int) IFieldContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IFieldContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IFieldContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeStructContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeStruct(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeStruct() (localctx ITypeStructContext) {
|
||||||
|
localctx = NewTypeStructContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 28, ApiParserParserRULE_typeStruct)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var _alt int
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(154)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeStructContext).structName = _m
|
||||||
|
}
|
||||||
|
p.SetState(156)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(155)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeStructContext).structToken = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(158)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__3)
|
||||||
|
|
||||||
|
localctx.(*TypeStructContext).lbrace = _m
|
||||||
|
}
|
||||||
|
p.SetState(162)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 10, p.GetParserRuleContext())
|
||||||
|
|
||||||
|
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
||||||
|
if _alt == 1 {
|
||||||
|
{
|
||||||
|
p.SetState(159)
|
||||||
|
p.Field()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(164)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 10, p.GetParserRuleContext())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(165)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__4)
|
||||||
|
|
||||||
|
localctx.(*TypeStructContext).rbrace = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeAliasContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeAliasContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetAlias returns the alias token.
|
||||||
|
GetAlias() antlr.Token
|
||||||
|
|
||||||
|
// GetAssign returns the assign token.
|
||||||
|
GetAssign() antlr.Token
|
||||||
|
|
||||||
|
// SetAlias sets the alias token.
|
||||||
|
SetAlias(antlr.Token)
|
||||||
|
|
||||||
|
// SetAssign sets the assign token.
|
||||||
|
SetAssign(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeAliasContext differentiates from other interfaces.
|
||||||
|
IsTypeAliasContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeAliasContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
alias antlr.Token
|
||||||
|
assign antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeAliasContext() *TypeAliasContext {
|
||||||
|
var p = new(TypeAliasContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeAlias
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeAliasContext) IsTypeAliasContext() {}
|
||||||
|
|
||||||
|
func NewTypeAliasContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeAliasContext {
|
||||||
|
var p = new(TypeAliasContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeAlias
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) GetAlias() antlr.Token { return s.alias }
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) GetAssign() antlr.Token { return s.assign }
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) SetAlias(v antlr.Token) { s.alias = v }
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeAliasContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeAlias(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeAlias() (localctx ITypeAliasContext) {
|
||||||
|
localctx = NewTypeAliasContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 30, ApiParserParserRULE_typeAlias)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(168)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeAliasContext).alias = _m
|
||||||
|
}
|
||||||
|
p.SetState(170)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__0 {
|
||||||
|
{
|
||||||
|
p.SetState(169)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__0)
|
||||||
|
|
||||||
|
localctx.(*TypeAliasContext).assign = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(172)
|
||||||
|
p.DataType()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeBlockStructContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeBlockStructContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetStructName returns the structName token.
|
||||||
|
GetStructName() antlr.Token
|
||||||
|
|
||||||
|
// GetStructToken returns the structToken token.
|
||||||
|
GetStructToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLbrace returns the lbrace token.
|
||||||
|
GetLbrace() antlr.Token
|
||||||
|
|
||||||
|
// GetRbrace returns the rbrace token.
|
||||||
|
GetRbrace() antlr.Token
|
||||||
|
|
||||||
|
// SetStructName sets the structName token.
|
||||||
|
SetStructName(antlr.Token)
|
||||||
|
|
||||||
|
// SetStructToken sets the structToken token.
|
||||||
|
SetStructToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLbrace sets the lbrace token.
|
||||||
|
SetLbrace(antlr.Token)
|
||||||
|
|
||||||
|
// SetRbrace sets the rbrace token.
|
||||||
|
SetRbrace(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeBlockStructContext differentiates from other interfaces.
|
||||||
|
IsTypeBlockStructContext()
|
||||||
|
}
|
||||||
617
tools/goctl/api/parser/g4/gen/api/apiparser_parser4.go
Executable file
617
tools/goctl/api/parser/g4/gen/api/apiparser_parser4.go
Executable file
@@ -0,0 +1,617 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 4
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
type TypeBlockStructContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
structName antlr.Token
|
||||||
|
structToken antlr.Token
|
||||||
|
lbrace antlr.Token
|
||||||
|
rbrace antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeBlockStructContext() *TypeBlockStructContext {
|
||||||
|
var p = new(TypeBlockStructContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockStruct
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeBlockStructContext) IsTypeBlockStructContext() {}
|
||||||
|
|
||||||
|
func NewTypeBlockStructContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockStructContext {
|
||||||
|
var p = new(TypeBlockStructContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockStruct
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetStructName() antlr.Token { return s.structName }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetStructToken() antlr.Token { return s.structToken }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) SetStructName(v antlr.Token) { s.structName = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) SetStructToken(v antlr.Token) { s.structToken = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) AllField() []IFieldContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IFieldContext)(nil)).Elem())
|
||||||
|
var tst = make([]IFieldContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IFieldContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) Field(i int) IFieldContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IFieldContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IFieldContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockStructContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeBlockStruct(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeBlockStruct() (localctx ITypeBlockStructContext) {
|
||||||
|
localctx = NewTypeBlockStructContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 32, ApiParserParserRULE_typeBlockStruct)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
var _alt int
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(175)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockStructContext).structName = _m
|
||||||
|
}
|
||||||
|
p.SetState(177)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(176)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockStructContext).structToken = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(179)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__3)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockStructContext).lbrace = _m
|
||||||
|
}
|
||||||
|
p.SetState(183)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 13, p.GetParserRuleContext())
|
||||||
|
|
||||||
|
for _alt != 2 && _alt != antlr.ATNInvalidAltNumber {
|
||||||
|
if _alt == 1 {
|
||||||
|
{
|
||||||
|
p.SetState(180)
|
||||||
|
p.Field()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(185)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_alt = p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 13, p.GetParserRuleContext())
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(186)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__4)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockStructContext).rbrace = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITypeBlockAliasContext is an interface to support dynamic dispatch.
|
||||||
|
type ITypeBlockAliasContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetAlias returns the alias token.
|
||||||
|
GetAlias() antlr.Token
|
||||||
|
|
||||||
|
// GetAssign returns the assign token.
|
||||||
|
GetAssign() antlr.Token
|
||||||
|
|
||||||
|
// SetAlias sets the alias token.
|
||||||
|
SetAlias(antlr.Token)
|
||||||
|
|
||||||
|
// SetAssign sets the assign token.
|
||||||
|
SetAssign(antlr.Token)
|
||||||
|
|
||||||
|
// IsTypeBlockAliasContext differentiates from other interfaces.
|
||||||
|
IsTypeBlockAliasContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type TypeBlockAliasContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
alias antlr.Token
|
||||||
|
assign antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyTypeBlockAliasContext() *TypeBlockAliasContext {
|
||||||
|
var p = new(TypeBlockAliasContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockAlias
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*TypeBlockAliasContext) IsTypeBlockAliasContext() {}
|
||||||
|
|
||||||
|
func NewTypeBlockAliasContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *TypeBlockAliasContext {
|
||||||
|
var p = new(TypeBlockAliasContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_typeBlockAlias
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) GetAlias() antlr.Token { return s.alias }
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) GetAssign() antlr.Token { return s.assign }
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) SetAlias(v antlr.Token) { s.alias = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) SetAssign(v antlr.Token) { s.assign = v }
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TypeBlockAliasContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitTypeBlockAlias(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) TypeBlockAlias() (localctx ITypeBlockAliasContext) {
|
||||||
|
localctx = NewTypeBlockAliasContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 34, ApiParserParserRULE_typeBlockAlias)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(189)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockAliasContext).alias = _m
|
||||||
|
}
|
||||||
|
p.SetState(191)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__0 {
|
||||||
|
{
|
||||||
|
p.SetState(190)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__0)
|
||||||
|
|
||||||
|
localctx.(*TypeBlockAliasContext).assign = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(193)
|
||||||
|
p.DataType()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IFieldContext is an interface to support dynamic dispatch.
|
||||||
|
type IFieldContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsFieldContext differentiates from other interfaces.
|
||||||
|
IsFieldContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type FieldContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyFieldContext() *FieldContext {
|
||||||
|
var p = new(FieldContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_field
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*FieldContext) IsFieldContext() {}
|
||||||
|
|
||||||
|
func NewFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *FieldContext {
|
||||||
|
var p = new(FieldContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_field
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FieldContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *FieldContext) NormalField() INormalFieldContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*INormalFieldContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(INormalFieldContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FieldContext) AnonymousFiled() IAnonymousFiledContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAnonymousFiledContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IAnonymousFiledContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FieldContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *FieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitField(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Field() (localctx IFieldContext) {
|
||||||
|
localctx = NewFieldContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 36, ApiParserParserRULE_field)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(198)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 15, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(195)
|
||||||
|
|
||||||
|
if !(isNormal(p)) {
|
||||||
|
panic(antlr.NewFailedPredicateException(p, "isNormal(p)", ""))
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(196)
|
||||||
|
p.NormalField()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(197)
|
||||||
|
p.AnonymousFiled()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// INormalFieldContext is an interface to support dynamic dispatch.
|
||||||
|
type INormalFieldContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetFieldName returns the fieldName token.
|
||||||
|
GetFieldName() antlr.Token
|
||||||
|
|
||||||
|
// GetTag returns the tag token.
|
||||||
|
GetTag() antlr.Token
|
||||||
|
|
||||||
|
// SetFieldName sets the fieldName token.
|
||||||
|
SetFieldName(antlr.Token)
|
||||||
|
|
||||||
|
// SetTag sets the tag token.
|
||||||
|
SetTag(antlr.Token)
|
||||||
|
|
||||||
|
// IsNormalFieldContext differentiates from other interfaces.
|
||||||
|
IsNormalFieldContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type NormalFieldContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
fieldName antlr.Token
|
||||||
|
tag antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyNormalFieldContext() *NormalFieldContext {
|
||||||
|
var p = new(NormalFieldContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_normalField
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*NormalFieldContext) IsNormalFieldContext() {}
|
||||||
|
|
||||||
|
func NewNormalFieldContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *NormalFieldContext {
|
||||||
|
var p = new(NormalFieldContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_normalField
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) GetFieldName() antlr.Token { return s.fieldName }
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) GetTag() antlr.Token { return s.tag }
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) SetFieldName(v antlr.Token) { s.fieldName = v }
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) SetTag(v antlr.Token) { s.tag = v }
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) RAW_STRING() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserRAW_STRING, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *NormalFieldContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitNormalField(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) NormalField() (localctx INormalFieldContext) {
|
||||||
|
localctx = NewNormalFieldContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 38, ApiParserParserRULE_normalField)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(201)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*NormalFieldContext).fieldName = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(202)
|
||||||
|
p.DataType()
|
||||||
|
}
|
||||||
|
p.SetState(204)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
if p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 16, p.GetParserRuleContext()) == 1 {
|
||||||
|
{
|
||||||
|
p.SetState(203)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserRAW_STRING)
|
||||||
|
|
||||||
|
localctx.(*NormalFieldContext).tag = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IAnonymousFiledContext is an interface to support dynamic dispatch.
|
||||||
|
type IAnonymousFiledContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetStar returns the star token.
|
||||||
|
GetStar() antlr.Token
|
||||||
|
|
||||||
|
// SetStar sets the star token.
|
||||||
|
SetStar(antlr.Token)
|
||||||
|
|
||||||
|
// IsAnonymousFiledContext differentiates from other interfaces.
|
||||||
|
IsAnonymousFiledContext()
|
||||||
|
}
|
||||||
618
tools/goctl/api/parser/g4/gen/api/apiparser_parser5.go
Executable file
618
tools/goctl/api/parser/g4/gen/api/apiparser_parser5.go
Executable file
@@ -0,0 +1,618 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 5
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
type AnonymousFiledContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
star antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyAnonymousFiledContext() *AnonymousFiledContext {
|
||||||
|
var p = new(AnonymousFiledContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_anonymousFiled
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AnonymousFiledContext) IsAnonymousFiledContext() {}
|
||||||
|
|
||||||
|
func NewAnonymousFiledContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AnonymousFiledContext {
|
||||||
|
var p = new(AnonymousFiledContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_anonymousFiled
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) GetStar() antlr.Token { return s.star }
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) SetStar(v antlr.Token) { s.star = v }
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AnonymousFiledContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitAnonymousFiled(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) AnonymousFiled() (localctx IAnonymousFiledContext) {
|
||||||
|
localctx = NewAnonymousFiledContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 40, ApiParserParserRULE_anonymousFiled)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(207)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__5 {
|
||||||
|
{
|
||||||
|
p.SetState(206)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__5)
|
||||||
|
|
||||||
|
localctx.(*AnonymousFiledContext).star = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(209)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDataTypeContext is an interface to support dynamic dispatch.
|
||||||
|
type IDataTypeContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetInter returns the inter token.
|
||||||
|
GetInter() antlr.Token
|
||||||
|
|
||||||
|
// GetTime returns the time token.
|
||||||
|
GetTime() antlr.Token
|
||||||
|
|
||||||
|
// SetInter sets the inter token.
|
||||||
|
SetInter(antlr.Token)
|
||||||
|
|
||||||
|
// SetTime sets the time token.
|
||||||
|
SetTime(antlr.Token)
|
||||||
|
|
||||||
|
// IsDataTypeContext differentiates from other interfaces.
|
||||||
|
IsDataTypeContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataTypeContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
inter antlr.Token
|
||||||
|
time antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyDataTypeContext() *DataTypeContext {
|
||||||
|
var p = new(DataTypeContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_dataType
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DataTypeContext) IsDataTypeContext() {}
|
||||||
|
|
||||||
|
func NewDataTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *DataTypeContext {
|
||||||
|
var p = new(DataTypeContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_dataType
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *DataTypeContext) GetInter() antlr.Token { return s.inter }
|
||||||
|
|
||||||
|
func (s *DataTypeContext) GetTime() antlr.Token { return s.time }
|
||||||
|
|
||||||
|
func (s *DataTypeContext) SetInter(v antlr.Token) { s.inter = v }
|
||||||
|
|
||||||
|
func (s *DataTypeContext) SetTime(v antlr.Token) { s.time = v }
|
||||||
|
|
||||||
|
func (s *DataTypeContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) MapType() IMapTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IMapTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IMapTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) ArrayType() IArrayTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IArrayTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IArrayTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) INTERFACE() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserINTERFACE, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) PointerType() IPointerTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IPointerTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IPointerTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) TypeStruct() ITypeStructContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*ITypeStructContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(ITypeStructContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *DataTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitDataType(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) DataType() (localctx IDataTypeContext) {
|
||||||
|
localctx = NewDataTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 42, ApiParserParserRULE_dataType)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(219)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 18, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
isInterface(p)
|
||||||
|
{
|
||||||
|
p.SetState(212)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(213)
|
||||||
|
p.MapType()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
p.EnterOuterAlt(localctx, 3)
|
||||||
|
{
|
||||||
|
p.SetState(214)
|
||||||
|
p.ArrayType()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
p.EnterOuterAlt(localctx, 4)
|
||||||
|
{
|
||||||
|
p.SetState(215)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserINTERFACE)
|
||||||
|
|
||||||
|
localctx.(*DataTypeContext).inter = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
p.EnterOuterAlt(localctx, 5)
|
||||||
|
{
|
||||||
|
p.SetState(216)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__6)
|
||||||
|
|
||||||
|
localctx.(*DataTypeContext).time = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
p.EnterOuterAlt(localctx, 6)
|
||||||
|
{
|
||||||
|
p.SetState(217)
|
||||||
|
p.PointerType()
|
||||||
|
}
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
p.EnterOuterAlt(localctx, 7)
|
||||||
|
{
|
||||||
|
p.SetState(218)
|
||||||
|
p.TypeStruct()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPointerTypeContext is an interface to support dynamic dispatch.
|
||||||
|
type IPointerTypeContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetStar returns the star token.
|
||||||
|
GetStar() antlr.Token
|
||||||
|
|
||||||
|
// SetStar sets the star token.
|
||||||
|
SetStar(antlr.Token)
|
||||||
|
|
||||||
|
// IsPointerTypeContext differentiates from other interfaces.
|
||||||
|
IsPointerTypeContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type PointerTypeContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
star antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyPointerTypeContext() *PointerTypeContext {
|
||||||
|
var p = new(PointerTypeContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_pointerType
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*PointerTypeContext) IsPointerTypeContext() {}
|
||||||
|
|
||||||
|
func NewPointerTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PointerTypeContext {
|
||||||
|
var p = new(PointerTypeContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_pointerType
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) GetStar() antlr.Token { return s.star }
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) SetStar(v antlr.Token) { s.star = v }
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PointerTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitPointerType(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) PointerType() (localctx IPointerTypeContext) {
|
||||||
|
localctx = NewPointerTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 44, ApiParserParserRULE_pointerType)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(221)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__5)
|
||||||
|
|
||||||
|
localctx.(*PointerTypeContext).star = _m
|
||||||
|
}
|
||||||
|
checkKeyword(p)
|
||||||
|
{
|
||||||
|
p.SetState(223)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IMapTypeContext is an interface to support dynamic dispatch.
|
||||||
|
type IMapTypeContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetMapToken returns the mapToken token.
|
||||||
|
GetMapToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLbrack returns the lbrack token.
|
||||||
|
GetLbrack() antlr.Token
|
||||||
|
|
||||||
|
// GetKey returns the key token.
|
||||||
|
GetKey() antlr.Token
|
||||||
|
|
||||||
|
// GetRbrack returns the rbrack token.
|
||||||
|
GetRbrack() antlr.Token
|
||||||
|
|
||||||
|
// SetMapToken sets the mapToken token.
|
||||||
|
SetMapToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLbrack sets the lbrack token.
|
||||||
|
SetLbrack(antlr.Token)
|
||||||
|
|
||||||
|
// SetKey sets the key token.
|
||||||
|
SetKey(antlr.Token)
|
||||||
|
|
||||||
|
// SetRbrack sets the rbrack token.
|
||||||
|
SetRbrack(antlr.Token)
|
||||||
|
|
||||||
|
// GetValue returns the value rule contexts.
|
||||||
|
GetValue() IDataTypeContext
|
||||||
|
|
||||||
|
// SetValue sets the value rule contexts.
|
||||||
|
SetValue(IDataTypeContext)
|
||||||
|
|
||||||
|
// IsMapTypeContext differentiates from other interfaces.
|
||||||
|
IsMapTypeContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type MapTypeContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
mapToken antlr.Token
|
||||||
|
lbrack antlr.Token
|
||||||
|
key antlr.Token
|
||||||
|
rbrack antlr.Token
|
||||||
|
value IDataTypeContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyMapTypeContext() *MapTypeContext {
|
||||||
|
var p = new(MapTypeContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_mapType
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*MapTypeContext) IsMapTypeContext() {}
|
||||||
|
|
||||||
|
func NewMapTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *MapTypeContext {
|
||||||
|
var p = new(MapTypeContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_mapType
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetMapToken() antlr.Token { return s.mapToken }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetLbrack() antlr.Token { return s.lbrack }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetKey() antlr.Token { return s.key }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetRbrack() antlr.Token { return s.rbrack }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) SetMapToken(v antlr.Token) { s.mapToken = v }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) SetLbrack(v antlr.Token) { s.lbrack = v }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) SetKey(v antlr.Token) { s.key = v }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) SetRbrack(v antlr.Token) { s.rbrack = v }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetValue() IDataTypeContext { return s.value }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) SetValue(v IDataTypeContext) { s.value = v }
|
||||||
|
|
||||||
|
func (s *MapTypeContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *MapTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitMapType(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) MapType() (localctx IMapTypeContext) {
|
||||||
|
localctx = NewMapTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 46, ApiParserParserRULE_mapType)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "map")
|
||||||
|
{
|
||||||
|
p.SetState(226)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*MapTypeContext).mapToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(227)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__7)
|
||||||
|
|
||||||
|
localctx.(*MapTypeContext).lbrack = _m
|
||||||
|
}
|
||||||
|
checkKey(p)
|
||||||
|
{
|
||||||
|
p.SetState(229)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*MapTypeContext).key = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(230)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__8)
|
||||||
|
|
||||||
|
localctx.(*MapTypeContext).rbrack = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(231)
|
||||||
|
|
||||||
|
var _x = p.DataType()
|
||||||
|
|
||||||
|
localctx.(*MapTypeContext).value = _x
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
613
tools/goctl/api/parser/g4/gen/api/apiparser_parser6.go
Executable file
613
tools/goctl/api/parser/g4/gen/api/apiparser_parser6.go
Executable file
@@ -0,0 +1,613 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 6
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
// IArrayTypeContext is an interface to support dynamic dispatch.
|
||||||
|
type IArrayTypeContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetLbrack returns the lbrack token.
|
||||||
|
GetLbrack() antlr.Token
|
||||||
|
|
||||||
|
// GetRbrack returns the rbrack token.
|
||||||
|
GetRbrack() antlr.Token
|
||||||
|
|
||||||
|
// SetLbrack sets the lbrack token.
|
||||||
|
SetLbrack(antlr.Token)
|
||||||
|
|
||||||
|
// SetRbrack sets the rbrack token.
|
||||||
|
SetRbrack(antlr.Token)
|
||||||
|
|
||||||
|
// IsArrayTypeContext differentiates from other interfaces.
|
||||||
|
IsArrayTypeContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArrayTypeContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
lbrack antlr.Token
|
||||||
|
rbrack antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyArrayTypeContext() *ArrayTypeContext {
|
||||||
|
var p = new(ArrayTypeContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_arrayType
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ArrayTypeContext) IsArrayTypeContext() {}
|
||||||
|
|
||||||
|
func NewArrayTypeContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ArrayTypeContext {
|
||||||
|
var p = new(ArrayTypeContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_arrayType
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) GetLbrack() antlr.Token { return s.lbrack }
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) GetRbrack() antlr.Token { return s.rbrack }
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) SetLbrack(v antlr.Token) { s.lbrack = v }
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) SetRbrack(v antlr.Token) { s.rbrack = v }
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ArrayTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitArrayType(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ArrayType() (localctx IArrayTypeContext) {
|
||||||
|
localctx = NewArrayTypeContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 48, ApiParserParserRULE_arrayType)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(233)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__7)
|
||||||
|
|
||||||
|
localctx.(*ArrayTypeContext).lbrack = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(234)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__8)
|
||||||
|
|
||||||
|
localctx.(*ArrayTypeContext).rbrack = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(235)
|
||||||
|
p.DataType()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IServiceSpecContext is an interface to support dynamic dispatch.
|
||||||
|
type IServiceSpecContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsServiceSpecContext differentiates from other interfaces.
|
||||||
|
IsServiceSpecContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServiceSpecContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyServiceSpecContext() *ServiceSpecContext {
|
||||||
|
var p = new(ServiceSpecContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceSpec
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServiceSpecContext) IsServiceSpecContext() {}
|
||||||
|
|
||||||
|
func NewServiceSpecContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceSpecContext {
|
||||||
|
var p = new(ServiceSpecContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceSpec
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) ServiceApi() IServiceApiContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceApiContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IServiceApiContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) AtServer() IAtServerContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtServerContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IAtServerContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceSpecContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitServiceSpec(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ServiceSpec() (localctx IServiceSpecContext) {
|
||||||
|
localctx = NewServiceSpecContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 50, ApiParserParserRULE_serviceSpec)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(238)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserATSERVER {
|
||||||
|
{
|
||||||
|
p.SetState(237)
|
||||||
|
p.AtServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(240)
|
||||||
|
p.ServiceApi()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IAtServerContext is an interface to support dynamic dispatch.
|
||||||
|
type IAtServerContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsAtServerContext differentiates from other interfaces.
|
||||||
|
IsAtServerContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type AtServerContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyAtServerContext() *AtServerContext {
|
||||||
|
var p = new(AtServerContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atServer
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AtServerContext) IsAtServerContext() {}
|
||||||
|
|
||||||
|
func NewAtServerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtServerContext {
|
||||||
|
var p = new(AtServerContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atServer
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *AtServerContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *AtServerContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *AtServerContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *AtServerContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *AtServerContext) ATSERVER() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserATSERVER, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) AllKvLit() []IKvLitContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||||
|
var tst = make([]IKvLitContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) KvLit(i int) IKvLitContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtServerContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitAtServer(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) AtServer() (localctx IAtServerContext) {
|
||||||
|
localctx = NewAtServerContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 52, ApiParserParserRULE_atServer)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(242)
|
||||||
|
p.Match(ApiParserParserATSERVER)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(243)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*AtServerContext).lp = _m
|
||||||
|
}
|
||||||
|
p.SetState(245)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(244)
|
||||||
|
p.KvLit()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(247)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(249)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*AtServerContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IServiceApiContext is an interface to support dynamic dispatch.
|
||||||
|
type IServiceApiContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetServiceToken returns the serviceToken token.
|
||||||
|
GetServiceToken() antlr.Token
|
||||||
|
|
||||||
|
// GetLbrace returns the lbrace token.
|
||||||
|
GetLbrace() antlr.Token
|
||||||
|
|
||||||
|
// GetRbrace returns the rbrace token.
|
||||||
|
GetRbrace() antlr.Token
|
||||||
|
|
||||||
|
// SetServiceToken sets the serviceToken token.
|
||||||
|
SetServiceToken(antlr.Token)
|
||||||
|
|
||||||
|
// SetLbrace sets the lbrace token.
|
||||||
|
SetLbrace(antlr.Token)
|
||||||
|
|
||||||
|
// SetRbrace sets the rbrace token.
|
||||||
|
SetRbrace(antlr.Token)
|
||||||
|
|
||||||
|
// IsServiceApiContext differentiates from other interfaces.
|
||||||
|
IsServiceApiContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServiceApiContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
serviceToken antlr.Token
|
||||||
|
lbrace antlr.Token
|
||||||
|
rbrace antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyServiceApiContext() *ServiceApiContext {
|
||||||
|
var p = new(ServiceApiContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceApi
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServiceApiContext) IsServiceApiContext() {}
|
||||||
|
|
||||||
|
func NewServiceApiContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceApiContext {
|
||||||
|
var p = new(ServiceApiContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceApi
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) GetServiceToken() antlr.Token { return s.serviceToken }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) GetLbrace() antlr.Token { return s.lbrace }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) GetRbrace() antlr.Token { return s.rbrace }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) SetServiceToken(v antlr.Token) { s.serviceToken = v }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) SetLbrace(v antlr.Token) { s.lbrace = v }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) SetRbrace(v antlr.Token) { s.rbrace = v }
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) ServiceName() IServiceNameContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceNameContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IServiceNameContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) AllServiceRoute() []IServiceRouteContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IServiceRouteContext)(nil)).Elem())
|
||||||
|
var tst = make([]IServiceRouteContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IServiceRouteContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) ServiceRoute(i int) IServiceRouteContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IServiceRouteContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IServiceRouteContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceApiContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitServiceApi(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ServiceApi() (localctx IServiceApiContext) {
|
||||||
|
localctx = NewServiceApiContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 54, ApiParserParserRULE_serviceApi)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
match(p, "service")
|
||||||
|
{
|
||||||
|
p.SetState(252)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*ServiceApiContext).serviceToken = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(253)
|
||||||
|
p.ServiceName()
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(254)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__3)
|
||||||
|
|
||||||
|
localctx.(*ServiceApiContext).lbrace = _m
|
||||||
|
}
|
||||||
|
p.SetState(258)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
for ((_la)&-(0x1f+1)) == 0 && ((1<<uint(_la))&((1<<ApiParserParserATDOC)|(1<<ApiParserParserATHANDLER)|(1<<ApiParserParserATSERVER))) != 0 {
|
||||||
|
{
|
||||||
|
p.SetState(255)
|
||||||
|
p.ServiceRoute()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(260)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(261)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__4)
|
||||||
|
|
||||||
|
localctx.(*ServiceApiContext).rbrace = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
676
tools/goctl/api/parser/g4/gen/api/apiparser_parser7.go
Executable file
676
tools/goctl/api/parser/g4/gen/api/apiparser_parser7.go
Executable file
@@ -0,0 +1,676 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 7
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
// IServiceRouteContext is an interface to support dynamic dispatch.
|
||||||
|
type IServiceRouteContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsServiceRouteContext differentiates from other interfaces.
|
||||||
|
IsServiceRouteContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServiceRouteContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyServiceRouteContext() *ServiceRouteContext {
|
||||||
|
var p = new(ServiceRouteContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceRoute
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServiceRouteContext) IsServiceRouteContext() {}
|
||||||
|
|
||||||
|
func NewServiceRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceRouteContext {
|
||||||
|
var p = new(ServiceRouteContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceRoute
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) Route() IRouteContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IRouteContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IRouteContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) AtServer() IAtServerContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtServerContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IAtServerContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) AtHandler() IAtHandlerContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtHandlerContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IAtHandlerContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) AtDoc() IAtDocContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IAtDocContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IAtDocContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceRouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitServiceRoute(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ServiceRoute() (localctx IServiceRouteContext) {
|
||||||
|
localctx = NewServiceRouteContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 56, ApiParserParserRULE_serviceRoute)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(264)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserATDOC {
|
||||||
|
{
|
||||||
|
p.SetState(263)
|
||||||
|
p.AtDoc()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(268)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
switch p.GetTokenStream().LA(1) {
|
||||||
|
case ApiParserParserATSERVER:
|
||||||
|
{
|
||||||
|
p.SetState(266)
|
||||||
|
p.AtServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
case ApiParserParserATHANDLER:
|
||||||
|
{
|
||||||
|
p.SetState(267)
|
||||||
|
p.AtHandler()
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(270)
|
||||||
|
p.Route()
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IAtDocContext is an interface to support dynamic dispatch.
|
||||||
|
type IAtDocContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsAtDocContext differentiates from other interfaces.
|
||||||
|
IsAtDocContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type AtDocContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyAtDocContext() *AtDocContext {
|
||||||
|
var p = new(AtDocContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atDoc
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AtDocContext) IsAtDocContext() {}
|
||||||
|
|
||||||
|
func NewAtDocContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtDocContext {
|
||||||
|
var p = new(AtDocContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atDoc
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *AtDocContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *AtDocContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *AtDocContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *AtDocContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *AtDocContext) ATDOC() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserATDOC, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) STRING() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserSTRING, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) AllKvLit() []IKvLitContext {
|
||||||
|
var ts = s.GetTypedRuleContexts(reflect.TypeOf((*IKvLitContext)(nil)).Elem())
|
||||||
|
var tst = make([]IKvLitContext, len(ts))
|
||||||
|
|
||||||
|
for i, t := range ts {
|
||||||
|
if t != nil {
|
||||||
|
tst[i] = t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tst
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) KvLit(i int) IKvLitContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IKvLitContext)(nil)).Elem(), i)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IKvLitContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtDocContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitAtDoc(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) AtDoc() (localctx IAtDocContext) {
|
||||||
|
localctx = NewAtDocContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 58, ApiParserParserRULE_atDoc)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(272)
|
||||||
|
p.Match(ApiParserParserATDOC)
|
||||||
|
}
|
||||||
|
p.SetState(274)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__1 {
|
||||||
|
{
|
||||||
|
p.SetState(273)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*AtDocContext).lp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(282)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
switch p.GetTokenStream().LA(1) {
|
||||||
|
case ApiParserParserID:
|
||||||
|
p.SetState(277)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(276)
|
||||||
|
p.KvLit()
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(279)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
case ApiParserParserSTRING:
|
||||||
|
{
|
||||||
|
p.SetState(281)
|
||||||
|
p.Match(ApiParserParserSTRING)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||||
|
}
|
||||||
|
p.SetState(285)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__2 {
|
||||||
|
{
|
||||||
|
p.SetState(284)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*AtDocContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IAtHandlerContext is an interface to support dynamic dispatch.
|
||||||
|
type IAtHandlerContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsAtHandlerContext differentiates from other interfaces.
|
||||||
|
IsAtHandlerContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type AtHandlerContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyAtHandlerContext() *AtHandlerContext {
|
||||||
|
var p = new(AtHandlerContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atHandler
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*AtHandlerContext) IsAtHandlerContext() {}
|
||||||
|
|
||||||
|
func NewAtHandlerContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *AtHandlerContext {
|
||||||
|
var p = new(AtHandlerContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_atHandler
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) ATHANDLER() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserATHANDLER, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AtHandlerContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitAtHandler(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) AtHandler() (localctx IAtHandlerContext) {
|
||||||
|
localctx = NewAtHandlerContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 60, ApiParserParserRULE_atHandler)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(287)
|
||||||
|
p.Match(ApiParserParserATHANDLER)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(288)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IRouteContext is an interface to support dynamic dispatch.
|
||||||
|
type IRouteContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetHttpMethod returns the httpMethod token.
|
||||||
|
GetHttpMethod() antlr.Token
|
||||||
|
|
||||||
|
// GetReturnToken returns the returnToken token.
|
||||||
|
GetReturnToken() antlr.Token
|
||||||
|
|
||||||
|
// SetHttpMethod sets the httpMethod token.
|
||||||
|
SetHttpMethod(antlr.Token)
|
||||||
|
|
||||||
|
// SetReturnToken sets the returnToken token.
|
||||||
|
SetReturnToken(antlr.Token)
|
||||||
|
|
||||||
|
// GetRequest returns the request rule contexts.
|
||||||
|
GetRequest() IBodyContext
|
||||||
|
|
||||||
|
// GetResponse returns the response rule contexts.
|
||||||
|
GetResponse() IReplybodyContext
|
||||||
|
|
||||||
|
// SetRequest sets the request rule contexts.
|
||||||
|
SetRequest(IBodyContext)
|
||||||
|
|
||||||
|
// SetResponse sets the response rule contexts.
|
||||||
|
SetResponse(IReplybodyContext)
|
||||||
|
|
||||||
|
// IsRouteContext differentiates from other interfaces.
|
||||||
|
IsRouteContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type RouteContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
httpMethod antlr.Token
|
||||||
|
request IBodyContext
|
||||||
|
returnToken antlr.Token
|
||||||
|
response IReplybodyContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyRouteContext() *RouteContext {
|
||||||
|
var p = new(RouteContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_route
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*RouteContext) IsRouteContext() {}
|
||||||
|
|
||||||
|
func NewRouteContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *RouteContext {
|
||||||
|
var p = new(RouteContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_route
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *RouteContext) GetHttpMethod() antlr.Token { return s.httpMethod }
|
||||||
|
|
||||||
|
func (s *RouteContext) GetReturnToken() antlr.Token { return s.returnToken }
|
||||||
|
|
||||||
|
func (s *RouteContext) SetHttpMethod(v antlr.Token) { s.httpMethod = v }
|
||||||
|
|
||||||
|
func (s *RouteContext) SetReturnToken(v antlr.Token) { s.returnToken = v }
|
||||||
|
|
||||||
|
func (s *RouteContext) GetRequest() IBodyContext { return s.request }
|
||||||
|
|
||||||
|
func (s *RouteContext) GetResponse() IReplybodyContext { return s.response }
|
||||||
|
|
||||||
|
func (s *RouteContext) SetRequest(v IBodyContext) { s.request = v }
|
||||||
|
|
||||||
|
func (s *RouteContext) SetResponse(v IReplybodyContext) { s.response = v }
|
||||||
|
|
||||||
|
func (s *RouteContext) Path() IPathContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IPathContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IPathContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) Body() IBodyContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IBodyContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IBodyContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) Replybody() IReplybodyContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IReplybodyContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IReplybodyContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *RouteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitRoute(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Route() (localctx IRouteContext) {
|
||||||
|
localctx = NewRouteContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 62, ApiParserParserRULE_route)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
checkHTTPMethod(p)
|
||||||
|
{
|
||||||
|
p.SetState(291)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*RouteContext).httpMethod = _m
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(292)
|
||||||
|
p.Path()
|
||||||
|
}
|
||||||
|
p.SetState(294)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
if p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 28, p.GetParserRuleContext()) == 1 {
|
||||||
|
{
|
||||||
|
p.SetState(293)
|
||||||
|
|
||||||
|
var _x = p.Body()
|
||||||
|
|
||||||
|
localctx.(*RouteContext).request = _x
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(297)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(296)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*RouteContext).returnToken = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
p.SetState(300)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__1 {
|
||||||
|
{
|
||||||
|
p.SetState(299)
|
||||||
|
|
||||||
|
var _x = p.Replybody()
|
||||||
|
|
||||||
|
localctx.(*RouteContext).response = _x
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
697
tools/goctl/api/parser/g4/gen/api/apiparser_parser8.go
Executable file
697
tools/goctl/api/parser/g4/gen/api/apiparser_parser8.go
Executable file
@@ -0,0 +1,697 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 8
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
// IBodyContext is an interface to support dynamic dispatch.
|
||||||
|
type IBodyContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsBodyContext differentiates from other interfaces.
|
||||||
|
IsBodyContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type BodyContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyBodyContext() *BodyContext {
|
||||||
|
var p = new(BodyContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_body
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*BodyContext) IsBodyContext() {}
|
||||||
|
|
||||||
|
func NewBodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *BodyContext {
|
||||||
|
var p = new(BodyContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_body
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *BodyContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *BodyContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *BodyContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *BodyContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *BodyContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *BodyContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *BodyContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *BodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *BodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitBody(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Body() (localctx IBodyContext) {
|
||||||
|
localctx = NewBodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 64, ApiParserParserRULE_body)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(302)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*BodyContext).lp = _m
|
||||||
|
}
|
||||||
|
p.SetState(304)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(303)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(306)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*BodyContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IReplybodyContext is an interface to support dynamic dispatch.
|
||||||
|
type IReplybodyContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetLp returns the lp token.
|
||||||
|
GetLp() antlr.Token
|
||||||
|
|
||||||
|
// GetRp returns the rp token.
|
||||||
|
GetRp() antlr.Token
|
||||||
|
|
||||||
|
// SetLp sets the lp token.
|
||||||
|
SetLp(antlr.Token)
|
||||||
|
|
||||||
|
// SetRp sets the rp token.
|
||||||
|
SetRp(antlr.Token)
|
||||||
|
|
||||||
|
// IsReplybodyContext differentiates from other interfaces.
|
||||||
|
IsReplybodyContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReplybodyContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
lp antlr.Token
|
||||||
|
rp antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyReplybodyContext() *ReplybodyContext {
|
||||||
|
var p = new(ReplybodyContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_replybody
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ReplybodyContext) IsReplybodyContext() {}
|
||||||
|
|
||||||
|
func NewReplybodyContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ReplybodyContext {
|
||||||
|
var p = new(ReplybodyContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_replybody
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) GetLp() antlr.Token { return s.lp }
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) GetRp() antlr.Token { return s.rp }
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) SetLp(v antlr.Token) { s.lp = v }
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) SetRp(v antlr.Token) { s.rp = v }
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) DataType() IDataTypeContext {
|
||||||
|
var t = s.GetTypedRuleContext(reflect.TypeOf((*IDataTypeContext)(nil)).Elem(), 0)
|
||||||
|
|
||||||
|
if t == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.(IDataTypeContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ReplybodyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitReplybody(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Replybody() (localctx IReplybodyContext) {
|
||||||
|
localctx = NewReplybodyContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 66, ApiParserParserRULE_replybody)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(308)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__1)
|
||||||
|
|
||||||
|
localctx.(*ReplybodyContext).lp = _m
|
||||||
|
}
|
||||||
|
p.SetState(310)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if ((_la)&-(0x1f+1)) == 0 && ((1<<uint(_la))&((1<<ApiParserParserT__5)|(1<<ApiParserParserT__6)|(1<<ApiParserParserT__7)|(1<<ApiParserParserINTERFACE)|(1<<ApiParserParserID))) != 0 {
|
||||||
|
{
|
||||||
|
p.SetState(309)
|
||||||
|
p.DataType()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(312)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserT__2)
|
||||||
|
|
||||||
|
localctx.(*ReplybodyContext).rp = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IKvLitContext is an interface to support dynamic dispatch.
|
||||||
|
type IKvLitContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// GetKey returns the key token.
|
||||||
|
GetKey() antlr.Token
|
||||||
|
|
||||||
|
// GetValue returns the value token.
|
||||||
|
GetValue() antlr.Token
|
||||||
|
|
||||||
|
// SetKey sets the key token.
|
||||||
|
SetKey(antlr.Token)
|
||||||
|
|
||||||
|
// SetValue sets the value token.
|
||||||
|
SetValue(antlr.Token)
|
||||||
|
|
||||||
|
// IsKvLitContext differentiates from other interfaces.
|
||||||
|
IsKvLitContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type KvLitContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
key antlr.Token
|
||||||
|
value antlr.Token
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyKvLitContext() *KvLitContext {
|
||||||
|
var p = new(KvLitContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_kvLit
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*KvLitContext) IsKvLitContext() {}
|
||||||
|
|
||||||
|
func NewKvLitContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *KvLitContext {
|
||||||
|
var p = new(KvLitContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_kvLit
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *KvLitContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *KvLitContext) GetKey() antlr.Token { return s.key }
|
||||||
|
|
||||||
|
func (s *KvLitContext) GetValue() antlr.Token { return s.value }
|
||||||
|
|
||||||
|
func (s *KvLitContext) SetKey(v antlr.Token) { s.key = v }
|
||||||
|
|
||||||
|
func (s *KvLitContext) SetValue(v antlr.Token) { s.value = v }
|
||||||
|
|
||||||
|
func (s *KvLitContext) ID() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *KvLitContext) LINE_VALUE() antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserLINE_VALUE, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *KvLitContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *KvLitContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *KvLitContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitKvLit(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) KvLit() (localctx IKvLitContext) {
|
||||||
|
localctx = NewKvLitContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 68, ApiParserParserRULE_kvLit)
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
{
|
||||||
|
p.SetState(314)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserID)
|
||||||
|
|
||||||
|
localctx.(*KvLitContext).key = _m
|
||||||
|
}
|
||||||
|
checkKeyValue(p)
|
||||||
|
{
|
||||||
|
p.SetState(316)
|
||||||
|
|
||||||
|
var _m = p.Match(ApiParserParserLINE_VALUE)
|
||||||
|
|
||||||
|
localctx.(*KvLitContext).value = _m
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IServiceNameContext is an interface to support dynamic dispatch.
|
||||||
|
type IServiceNameContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsServiceNameContext differentiates from other interfaces.
|
||||||
|
IsServiceNameContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type ServiceNameContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyServiceNameContext() *ServiceNameContext {
|
||||||
|
var p = new(ServiceNameContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceName
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ServiceNameContext) IsServiceNameContext() {}
|
||||||
|
|
||||||
|
func NewServiceNameContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *ServiceNameContext {
|
||||||
|
var p = new(ServiceNameContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_serviceName
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServiceNameContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitServiceName(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) ServiceName() (localctx IServiceNameContext) {
|
||||||
|
localctx = NewServiceNameContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 70, ApiParserParserRULE_serviceName)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(322)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserID {
|
||||||
|
{
|
||||||
|
p.SetState(318)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
p.SetState(320)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__9 {
|
||||||
|
{
|
||||||
|
p.SetState(319)
|
||||||
|
p.Match(ApiParserParserT__9)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(324)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPathContext is an interface to support dynamic dispatch.
|
||||||
|
type IPathContext interface {
|
||||||
|
antlr.ParserRuleContext
|
||||||
|
|
||||||
|
// GetParser returns the parser.
|
||||||
|
GetParser() antlr.Parser
|
||||||
|
|
||||||
|
// IsPathContext differentiates from other interfaces.
|
||||||
|
IsPathContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
type PathContext struct {
|
||||||
|
*antlr.BaseParserRuleContext
|
||||||
|
parser antlr.Parser
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewEmptyPathContext() *PathContext {
|
||||||
|
var p = new(PathContext)
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(nil, -1)
|
||||||
|
p.RuleIndex = ApiParserParserRULE_path
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*PathContext) IsPathContext() {}
|
||||||
|
|
||||||
|
func NewPathContext(parser antlr.Parser, parent antlr.ParserRuleContext, invokingState int) *PathContext {
|
||||||
|
var p = new(PathContext)
|
||||||
|
|
||||||
|
p.BaseParserRuleContext = antlr.NewBaseParserRuleContext(parent, invokingState)
|
||||||
|
|
||||||
|
p.parser = parser
|
||||||
|
p.RuleIndex = ApiParserParserRULE_path
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PathContext) GetParser() antlr.Parser { return s.parser }
|
||||||
|
|
||||||
|
func (s *PathContext) AllID() []antlr.TerminalNode {
|
||||||
|
return s.GetTokens(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PathContext) ID(i int) antlr.TerminalNode {
|
||||||
|
return s.GetToken(ApiParserParserID, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PathContext) GetRuleContext() antlr.RuleContext {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PathContext) ToStringTree(ruleNames []string, recog antlr.Recognizer) string {
|
||||||
|
return antlr.TreesStringTree(s, ruleNames, recog)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PathContext) Accept(visitor antlr.ParseTreeVisitor) interface{} {
|
||||||
|
switch t := visitor.(type) {
|
||||||
|
case ApiParserVisitor:
|
||||||
|
return t.VisitPath(s)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return t.VisitChildren(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Path() (localctx IPathContext) {
|
||||||
|
localctx = NewPathContext(p, p.GetParserRuleContext(), p.GetState())
|
||||||
|
p.EnterRule(localctx, 72, ApiParserParserRULE_path)
|
||||||
|
var _la int
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
p.ExitRule()
|
||||||
|
}()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
if v, ok := err.(antlr.RecognitionException); ok {
|
||||||
|
localctx.SetException(v)
|
||||||
|
p.GetErrorHandler().ReportError(p, v)
|
||||||
|
p.GetErrorHandler().Recover(p, v)
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
p.SetState(346)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
switch p.GetInterpreter().AdaptivePredict(p.GetTokenStream(), 39, p.GetParserRuleContext()) {
|
||||||
|
case 1:
|
||||||
|
p.EnterOuterAlt(localctx, 1)
|
||||||
|
p.SetState(341)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
for ok := true; ok; ok = _la == ApiParserParserT__10 || _la == ApiParserParserT__11 {
|
||||||
|
p.SetState(341)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
|
||||||
|
switch p.GetTokenStream().LA(1) {
|
||||||
|
case ApiParserParserT__10:
|
||||||
|
{
|
||||||
|
p.SetState(326)
|
||||||
|
p.Match(ApiParserParserT__10)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
p.SetState(327)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
p.SetState(332)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
for _la == ApiParserParserT__9 {
|
||||||
|
{
|
||||||
|
p.SetState(328)
|
||||||
|
p.Match(ApiParserParserT__9)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(329)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(334)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
case ApiParserParserT__11:
|
||||||
|
{
|
||||||
|
p.SetState(335)
|
||||||
|
p.Match(ApiParserParserT__11)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
p.SetState(336)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
p.SetState(339)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
|
||||||
|
if _la == ApiParserParserT__9 {
|
||||||
|
{
|
||||||
|
p.SetState(337)
|
||||||
|
p.Match(ApiParserParserT__9)
|
||||||
|
}
|
||||||
|
{
|
||||||
|
p.SetState(338)
|
||||||
|
p.Match(ApiParserParserID)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(antlr.NewNoViableAltException(p, nil, nil, nil, nil, nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
p.SetState(343)
|
||||||
|
p.GetErrorHandler().Sync(p)
|
||||||
|
_la = p.GetTokenStream().LA(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
p.EnterOuterAlt(localctx, 2)
|
||||||
|
{
|
||||||
|
p.SetState(345)
|
||||||
|
p.Match(ApiParserParserT__10)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return localctx
|
||||||
|
}
|
||||||
35
tools/goctl/api/parser/g4/gen/api/apiparser_parser9.go
Executable file
35
tools/goctl/api/parser/g4/gen/api/apiparser_parser9.go
Executable file
@@ -0,0 +1,35 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zeromicro/antlr"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Part 9
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Sempred(localctx antlr.RuleContext, ruleIndex, predIndex int) bool {
|
||||||
|
switch ruleIndex {
|
||||||
|
case 18:
|
||||||
|
var t *FieldContext = nil
|
||||||
|
if localctx != nil {
|
||||||
|
t = localctx.(*FieldContext)
|
||||||
|
}
|
||||||
|
return p.Field_Sempred(t, predIndex)
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic("No predicate with index: " + fmt.Sprint(ruleIndex))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ApiParserParser) Field_Sempred(localctx antlr.RuleContext, predIndex int) bool {
|
||||||
|
switch predIndex {
|
||||||
|
case 0:
|
||||||
|
return isNormal(p)
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic("No predicate with index: " + fmt.Sprint(predIndex))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
// Code generated from tools/goctl/api/parser/g4/ApiParser.g4 by ANTLR 4.9. DO NOT EDIT.
|
|
||||||
|
|
||||||
package api // ApiParser
|
package api // ApiParser
|
||||||
import "github.com/zeromicro/antlr"
|
import "github.com/zeromicro/antlr"
|
||||||
|
|
||||||
|
|||||||
79
tools/goctl/api/parser/g4/gen/api/file_splitor_test.go
Normal file
79
tools/goctl/api/parser/g4/gen/api/file_splitor_test.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// DO NOT EDIT.
|
||||||
|
// Tool: split apiparser_parser.go
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
package api
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFileSplitor(t *testing.T) {
|
||||||
|
dir := "."
|
||||||
|
data, err := ioutil.ReadFile(filepath.Join(dir, "apiparser_parser.go"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
reader := bufio.NewReader(r)
|
||||||
|
var lines, files int
|
||||||
|
buffer := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
for {
|
||||||
|
var fn, part = "apiparser_parser0.go", "main"
|
||||||
|
if files > 0 {
|
||||||
|
fn = fmt.Sprintf("apiparser_parser%d.go", files)
|
||||||
|
part = fmt.Sprintf("%d", files)
|
||||||
|
}
|
||||||
|
fp := filepath.Join(dir, fn)
|
||||||
|
buffer.Reset()
|
||||||
|
if files > 0 {
|
||||||
|
buffer.WriteString(fmt.Sprintf(`package api
|
||||||
|
import "github.com/zeromicro/antlr"
|
||||||
|
|
||||||
|
// Part %s
|
||||||
|
// The apiparser_parser.go file was split into multiple files because it
|
||||||
|
// was too large and caused a possible memory overflow during goctl installation.
|
||||||
|
`, part))
|
||||||
|
}
|
||||||
|
|
||||||
|
var exit bool
|
||||||
|
for {
|
||||||
|
line, _, err := reader.ReadLine()
|
||||||
|
buffer.Write(line)
|
||||||
|
buffer.WriteRune('\n')
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%+v\n", err)
|
||||||
|
exit = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lines += 1
|
||||||
|
if string(line) == "}" && lines >= 650 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(fp, buffer.Bytes(), os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%+v\n", err)
|
||||||
|
}
|
||||||
|
if exit {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
lines = 0
|
||||||
|
files += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.Rename(filepath.Join(dir, "apiparser_parser0.go"), filepath.Join(dir, "apiparser_parser.go"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -174,7 +174,7 @@ func TestRoute(t *testing.T) {
|
|||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|
||||||
_, err = parser.Accept(fn, ` post /foo/bar returns (int)`)
|
_, err = parser.Accept(fn, ` post /foo/bar returns (int)`)
|
||||||
assert.Error(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
_, err = parser.Accept(fn, ` post /foo/bar returns (*int)`)
|
_, err = parser.Accept(fn, ` post /foo/bar returns (*int)`)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildVersion is the version of goctl.
|
// BuildVersion is the version of goctl.
|
||||||
const BuildVersion = "1.2.3"
|
const BuildVersion = "1.2.3-cli"
|
||||||
|
|
||||||
|
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||||
|
|
||||||
// GetGoctlVersion returns BuildVersion
|
// GetGoctlVersion returns BuildVersion
|
||||||
func GetGoctlVersion() string {
|
func GetGoctlVersion() string {
|
||||||
return BuildVersion
|
return BuildVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
|
||||||
|
|
||||||
// IsVersionGreaterThan compares whether the current goctl version
|
// IsVersionGreaterThan compares whether the current goctl version
|
||||||
// is greater than the target version
|
// is greater than the target version
|
||||||
func IsVersionGreaterThan(version, target string) bool {
|
func IsVersionGreaterThan(version, target string) bool {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/core/discov"
|
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal"
|
"github.com/tal-tech/go-zero/zrpc/internal"
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/auth"
|
"github.com/tal-tech/go-zero/zrpc/internal/auth"
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/clientinterceptors"
|
"github.com/tal-tech/go-zero/zrpc/internal/clientinterceptors"
|
||||||
@@ -18,10 +17,6 @@ var (
|
|||||||
WithNonBlock = internal.WithNonBlock
|
WithNonBlock = internal.WithNonBlock
|
||||||
// WithTimeout is an alias of internal.WithTimeout.
|
// WithTimeout is an alias of internal.WithTimeout.
|
||||||
WithTimeout = internal.WithTimeout
|
WithTimeout = internal.WithTimeout
|
||||||
// WithRetry is an alias of internal.WithRetry.
|
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// WithRetry = internal.WithRetry
|
|
||||||
|
|
||||||
// WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
|
// WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
|
||||||
WithTransportCredentials = internal.WithTransportCredentials
|
WithTransportCredentials = internal.WithTransportCredentials
|
||||||
// WithUnaryClientInterceptor is an alias of internal.WithUnaryClientInterceptor.
|
// WithUnaryClientInterceptor is an alias of internal.WithUnaryClientInterceptor.
|
||||||
@@ -65,30 +60,14 @@ func NewClient(c RpcClientConf, options ...ClientOption) (Client, error) {
|
|||||||
if c.Timeout > 0 {
|
if c.Timeout > 0 {
|
||||||
opts = append(opts, WithTimeout(time.Duration(c.Timeout)*time.Millisecond))
|
opts = append(opts, WithTimeout(time.Duration(c.Timeout)*time.Millisecond))
|
||||||
}
|
}
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// if c.Retry {
|
|
||||||
// opts = append(opts, WithRetry())
|
|
||||||
// }
|
|
||||||
opts = append(opts, options...)
|
opts = append(opts, options...)
|
||||||
|
|
||||||
var target string
|
target, err := c.BuildTarget()
|
||||||
var err error
|
if err != nil {
|
||||||
if len(c.Endpoints) > 0 {
|
|
||||||
target = internal.BuildDirectTarget(c.Endpoints)
|
|
||||||
} else if len(c.Target) > 0 {
|
|
||||||
target = c.Target
|
|
||||||
} else {
|
|
||||||
if err = c.Etcd.Validate(); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Etcd.HasAccount() {
|
|
||||||
discov.RegisterAccount(c.Etcd.Hosts, c.Etcd.User, c.Etcd.Pass)
|
|
||||||
}
|
|
||||||
|
|
||||||
target = internal.BuildDiscovTarget(c.Etcd.Hosts, c.Etcd.Key)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := internal.NewClient(target, opts...)
|
client, err := internal.NewClient(target, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -96,21 +96,6 @@ func TestDepositServer_Deposit(t *testing.T) {
|
|||||||
return invoker(ctx, method, req, reply, cc, opts...)
|
return invoker(ctx, method, req, reply, cc, opts...)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// retryClient := MustNewClient(
|
|
||||||
// RpcClientConf{
|
|
||||||
// Endpoints: []string{"foo"},
|
|
||||||
// App: "foo",
|
|
||||||
// Token: "bar",
|
|
||||||
// Timeout: 1000,
|
|
||||||
// Retry: true,
|
|
||||||
// },
|
|
||||||
// WithDialOption(grpc.WithContextDialer(dialer())),
|
|
||||||
// WithUnaryClientInterceptor(func(ctx context.Context, method string, req, reply interface{},
|
|
||||||
// cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
||||||
// return invoker(ctx, method, req, reply, cc, opts...)
|
|
||||||
// }),
|
|
||||||
// )
|
|
||||||
tarConfClient := MustNewClient(
|
tarConfClient := MustNewClient(
|
||||||
RpcClientConf{
|
RpcClientConf{
|
||||||
Target: "foo",
|
Target: "foo",
|
||||||
@@ -135,8 +120,6 @@ func TestDepositServer_Deposit(t *testing.T) {
|
|||||||
clients := []Client{
|
clients := []Client{
|
||||||
directClient,
|
directClient,
|
||||||
nonBlockClient,
|
nonBlockClient,
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// retryClient,
|
|
||||||
tarConfClient,
|
tarConfClient,
|
||||||
targetClient,
|
targetClient,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/tal-tech/go-zero/core/discov"
|
"github.com/tal-tech/go-zero/core/discov"
|
||||||
"github.com/tal-tech/go-zero/core/service"
|
"github.com/tal-tech/go-zero/core/service"
|
||||||
"github.com/tal-tech/go-zero/core/stores/redis"
|
"github.com/tal-tech/go-zero/core/stores/redis"
|
||||||
|
"github.com/tal-tech/go-zero/zrpc/resolver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -18,8 +19,6 @@ type (
|
|||||||
// setting 0 means no timeout
|
// setting 0 means no timeout
|
||||||
Timeout int64 `json:",default=2000"`
|
Timeout int64 `json:",default=2000"`
|
||||||
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
CpuThreshold int64 `json:",default=900,range=[0:1000]"`
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// MaxRetries int `json:",default=0,range=[0:]"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A RpcClientConf is a rpc client config.
|
// A RpcClientConf is a rpc client config.
|
||||||
@@ -30,8 +29,6 @@ type (
|
|||||||
App string `json:",optional"`
|
App string `json:",optional"`
|
||||||
Token string `json:",optional"`
|
Token string `json:",optional"`
|
||||||
NonBlock bool `json:",optional"`
|
NonBlock bool `json:",optional"`
|
||||||
// TODO: enable it in v1.2.4
|
|
||||||
// Retry bool `json:",optional"` // grpc auto retry
|
|
||||||
Timeout int64 `json:",default=2000"`
|
Timeout int64 `json:",default=2000"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -71,6 +68,25 @@ func (sc RpcServerConf) Validate() error {
|
|||||||
return sc.Redis.Validate()
|
return sc.Redis.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildTarget builds the rpc target from the given config.
|
||||||
|
func (cc RpcClientConf) BuildTarget() (string, error) {
|
||||||
|
if len(cc.Endpoints) > 0 {
|
||||||
|
return resolver.BuildDirectTarget(cc.Endpoints), nil
|
||||||
|
} else if len(cc.Target) > 0 {
|
||||||
|
return cc.Target, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cc.Etcd.Validate(); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cc.Etcd.HasAccount() {
|
||||||
|
discov.RegisterAccount(cc.Etcd.Hosts, cc.Etcd.User, cc.Etcd.Pass)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolver.BuildDiscovTarget(cc.Etcd.Hosts, cc.Etcd.Key), nil
|
||||||
|
}
|
||||||
|
|
||||||
// HasCredential checks if there is a credential in config.
|
// HasCredential checks if there is a credential in config.
|
||||||
func (cc RpcClientConf) HasCredential() bool {
|
func (cc RpcClientConf) HasCredential() bool {
|
||||||
return len(cc.App) > 0 && len(cc.Token) > 0
|
return len(cc.App) > 0 && len(cc.Token) > 0
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c"
|
"github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c"
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/clientinterceptors"
|
"github.com/tal-tech/go-zero/zrpc/internal/clientinterceptors"
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/resolver"
|
"github.com/tal-tech/go-zero/zrpc/resolver"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
@@ -20,7 +20,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
resolver.RegisterResolver()
|
resolver.Register()
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -34,7 +34,6 @@ type (
|
|||||||
NonBlock bool
|
NonBlock bool
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
Secure bool
|
Secure bool
|
||||||
Retry bool
|
|
||||||
DialOptions []grpc.DialOption
|
DialOptions []grpc.DialOption
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +82,6 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
|
|||||||
clientinterceptors.PrometheusInterceptor,
|
clientinterceptors.PrometheusInterceptor,
|
||||||
clientinterceptors.BreakerInterceptor,
|
clientinterceptors.BreakerInterceptor,
|
||||||
clientinterceptors.TimeoutInterceptor(cliOpts.Timeout),
|
clientinterceptors.TimeoutInterceptor(cliOpts.Timeout),
|
||||||
clientinterceptors.RetryInterceptor(cliOpts.Retry),
|
|
||||||
),
|
),
|
||||||
WithStreamClientInterceptors(
|
WithStreamClientInterceptors(
|
||||||
clientinterceptors.StreamTracingInterceptor,
|
clientinterceptors.StreamTracingInterceptor,
|
||||||
@@ -136,13 +134,6 @@ func WithTimeout(timeout time.Duration) ClientOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithRetry returns a func to customize a ClientOptions with auto retry.
|
|
||||||
func WithRetry() ClientOption {
|
|
||||||
return func(options *ClientOptions) {
|
|
||||||
options.Retry = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
|
// WithTransportCredentials return a func to make the gRPC calls secured with given credentials.
|
||||||
func WithTransportCredentials(creds credentials.TransportCredentials) ClientOption {
|
func WithTransportCredentials(creds credentials.TransportCredentials) ClientOption {
|
||||||
return func(options *ClientOptions) {
|
return func(options *ClientOptions) {
|
||||||
|
|||||||
@@ -24,13 +24,6 @@ func TestWithTimeout(t *testing.T) {
|
|||||||
assert.Equal(t, time.Second, options.Timeout)
|
assert.Equal(t, time.Second, options.Timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithRetry(t *testing.T) {
|
|
||||||
var options ClientOptions
|
|
||||||
opt := WithRetry()
|
|
||||||
opt(&options)
|
|
||||||
assert.True(t, options.Retry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWithNonBlock(t *testing.T) {
|
func TestWithNonBlock(t *testing.T) {
|
||||||
var options ClientOptions
|
var options ClientOptions
|
||||||
opt := WithNonBlock()
|
opt := WithNonBlock()
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package clientinterceptors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/core/retry"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RetryInterceptor retry interceptor
|
|
||||||
func RetryInterceptor(enable bool) grpc.UnaryClientInterceptor {
|
|
||||||
if !enable {
|
|
||||||
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
||||||
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
||||||
return invoker(ctx, method, req, reply, cc, opts...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
||||||
invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
|
||||||
return retry.Do(ctx, func(ctx context.Context, callOpts ...grpc.CallOption) error {
|
|
||||||
return invoker(ctx, method, req, reply, cc, callOpts...)
|
|
||||||
}, opts...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package clientinterceptors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/tal-tech/go-zero/core/retry"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRetryInterceptor_WithMax(t *testing.T) {
|
|
||||||
n := 4
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
count := 0
|
|
||||||
cc := new(grpc.ClientConn)
|
|
||||||
err := RetryInterceptor(true)(context.Background(), "/1", nil, nil, cc,
|
|
||||||
func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn,
|
|
||||||
opts ...grpc.CallOption) error {
|
|
||||||
count++
|
|
||||||
return status.Error(codes.ResourceExhausted, "ResourceExhausted")
|
|
||||||
}, retry.WithMax(i))
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Equal(t, i+1, count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,6 @@ type (
|
|||||||
|
|
||||||
rpcServerOptions struct {
|
rpcServerOptions struct {
|
||||||
metrics *stat.Metrics
|
metrics *stat.Metrics
|
||||||
MaxRetries int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcServer struct {
|
rpcServer struct {
|
||||||
@@ -56,7 +55,6 @@ func (s *rpcServer) Start(register RegisterFn) error {
|
|||||||
|
|
||||||
unaryInterceptors := []grpc.UnaryServerInterceptor{
|
unaryInterceptors := []grpc.UnaryServerInterceptor{
|
||||||
serverinterceptors.UnaryTracingInterceptor,
|
serverinterceptors.UnaryTracingInterceptor,
|
||||||
serverinterceptors.RetryInterceptor(s.maxRetries),
|
|
||||||
serverinterceptors.UnaryCrashInterceptor,
|
serverinterceptors.UnaryCrashInterceptor,
|
||||||
serverinterceptors.UnaryStatInterceptor(s.metrics),
|
serverinterceptors.UnaryStatInterceptor(s.metrics),
|
||||||
serverinterceptors.UnaryPrometheusInterceptor,
|
serverinterceptors.UnaryPrometheusInterceptor,
|
||||||
@@ -89,10 +87,3 @@ func WithMetrics(metrics *stat.Metrics) ServerOption {
|
|||||||
options.metrics = metrics
|
options.metrics = metrics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithMaxRetries returns a func that sets a max retries to a Server.
|
|
||||||
func WithMaxRetries(maxRetries int) ServerOption {
|
|
||||||
return func(options *rpcServerOptions) {
|
|
||||||
options.MaxRetries = maxRetries
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type (
|
|||||||
baseRpcServer struct {
|
baseRpcServer struct {
|
||||||
address string
|
address string
|
||||||
metrics *stat.Metrics
|
metrics *stat.Metrics
|
||||||
maxRetries int
|
|
||||||
options []grpc.ServerOption
|
options []grpc.ServerOption
|
||||||
streamInterceptors []grpc.StreamServerInterceptor
|
streamInterceptors []grpc.StreamServerInterceptor
|
||||||
unaryInterceptors []grpc.UnaryServerInterceptor
|
unaryInterceptors []grpc.UnaryServerInterceptor
|
||||||
@@ -32,7 +31,6 @@ func newBaseRpcServer(address string, rpcServerOpts *rpcServerOptions) *baseRpcS
|
|||||||
return &baseRpcServer{
|
return &baseRpcServer{
|
||||||
address: address,
|
address: address,
|
||||||
metrics: rpcServerOpts.metrics,
|
metrics: rpcServerOpts.metrics,
|
||||||
maxRetries: rpcServerOpts.MaxRetries,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
package serverinterceptors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/core/logx"
|
|
||||||
"github.com/tal-tech/go-zero/core/retry"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/grpc/codes"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
"google.golang.org/grpc/status"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RetryInterceptor(maxAttempt int) grpc.UnaryServerInterceptor {
|
|
||||||
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
|
|
||||||
handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
||||||
var md metadata.MD
|
|
||||||
requestMd, ok := metadata.FromIncomingContext(ctx)
|
|
||||||
if ok {
|
|
||||||
md = requestMd.Copy()
|
|
||||||
attemptMd := md.Get(retry.AttemptMetadataKey)
|
|
||||||
if len(attemptMd) != 0 && attemptMd[0] != "" {
|
|
||||||
if attempt, err := strconv.Atoi(attemptMd[0]); err == nil {
|
|
||||||
if attempt > maxAttempt {
|
|
||||||
logx.WithContext(ctx).Errorf("retries exceeded:%d, max retries:%d", attempt, maxAttempt)
|
|
||||||
return nil, status.Error(codes.FailedPrecondition, "Retries exceeded")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return handler(ctx, req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package serverinterceptors
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/tal-tech/go-zero/core/retry"
|
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRetryInterceptor(t *testing.T) {
|
|
||||||
t.Run("retries exceeded", func(t *testing.T) {
|
|
||||||
interceptor := RetryInterceptor(2)
|
|
||||||
ctx := metadata.NewIncomingContext(context.Background(),
|
|
||||||
metadata.New(map[string]string{retry.AttemptMetadataKey: "3"}))
|
|
||||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context,
|
|
||||||
req interface{}) (interface{}, error) {
|
|
||||||
return nil, nil
|
|
||||||
})
|
|
||||||
assert.Error(t, err)
|
|
||||||
assert.Nil(t, resp)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("reasonable retries", func(t *testing.T) {
|
|
||||||
interceptor := RetryInterceptor(2)
|
|
||||||
ctx := metadata.NewIncomingContext(context.Background(),
|
|
||||||
metadata.New(map[string]string{retry.AttemptMetadataKey: "2"}))
|
|
||||||
resp, err := interceptor(ctx, nil, nil, func(ctx context.Context,
|
|
||||||
req interface{}) (interface{}, error) {
|
|
||||||
return nil, nil
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Nil(t, resp)
|
|
||||||
})
|
|
||||||
t.Run("no retries", func(t *testing.T) {
|
|
||||||
interceptor := RetryInterceptor(0)
|
|
||||||
resp, err := interceptor(context.Background(), nil, nil,
|
|
||||||
func(ctx context.Context, req interface{}) (interface{}, error) {
|
|
||||||
return nil, nil
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.Nil(t, resp)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
type discovBuilder struct{}
|
type discovBuilder struct{}
|
||||||
|
|
||||||
func (b *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (
|
func (b *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, _ resolver.BuildOptions) (
|
||||||
resolver.Resolver, error) {
|
resolver.Resolver, error) {
|
||||||
hosts := strings.FieldsFunc(target.Authority, func(r rune) bool {
|
hosts := strings.FieldsFunc(target.Authority, func(r rune) bool {
|
||||||
return r == EndpointSepChar
|
return r == EndpointSepChar
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
9
zrpc/resolver/internal/etcdbuilder.go
Normal file
9
zrpc/resolver/internal/etcdbuilder.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
type etcdBuilder struct {
|
||||||
|
discovBuilder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *etcdBuilder) Scheme() string {
|
||||||
|
return EtcdScheme
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/tal-tech/go-zero/core/logx"
|
"github.com/tal-tech/go-zero/core/logx"
|
||||||
"github.com/tal-tech/go-zero/core/proc"
|
"github.com/tal-tech/go-zero/core/proc"
|
||||||
"github.com/tal-tech/go-zero/core/threading"
|
"github.com/tal-tech/go-zero/core/threading"
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/resolver/kube"
|
"github.com/tal-tech/go-zero/zrpc/resolver/internal/kube"
|
||||||
"google.golang.org/grpc/resolver"
|
"google.golang.org/grpc/resolver"
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/informers"
|
"k8s.io/client-go/informers"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -11,6 +11,8 @@ const (
|
|||||||
DirectScheme = "direct"
|
DirectScheme = "direct"
|
||||||
// DiscovScheme stands for discov scheme.
|
// DiscovScheme stands for discov scheme.
|
||||||
DiscovScheme = "discov"
|
DiscovScheme = "discov"
|
||||||
|
// EtcdScheme stands for etcd scheme.
|
||||||
|
EtcdScheme = "etcd"
|
||||||
// KubernetesScheme stands for k8s scheme.
|
// KubernetesScheme stands for k8s scheme.
|
||||||
KubernetesScheme = "k8s"
|
KubernetesScheme = "k8s"
|
||||||
// EndpointSepChar is the separator cha in endpoints.
|
// EndpointSepChar is the separator cha in endpoints.
|
||||||
@@ -23,16 +25,18 @@ var (
|
|||||||
// EndpointSep is the separator string in endpoints.
|
// EndpointSep is the separator string in endpoints.
|
||||||
EndpointSep = fmt.Sprintf("%c", EndpointSepChar)
|
EndpointSep = fmt.Sprintf("%c", EndpointSepChar)
|
||||||
|
|
||||||
dirBuilder directBuilder
|
directResolverBuilder directBuilder
|
||||||
disBuilder discovBuilder
|
discovResolverBuilder discovBuilder
|
||||||
k8sBuilder kubeBuilder
|
etcdResolverBuilder etcdBuilder
|
||||||
|
k8sResolverBuilder kubeBuilder
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterResolver registers the direct and discov schemes to the resolver.
|
// RegisterResolver registers the direct and discov schemes to the resolver.
|
||||||
func RegisterResolver() {
|
func RegisterResolver() {
|
||||||
resolver.Register(&dirBuilder)
|
resolver.Register(&directResolverBuilder)
|
||||||
resolver.Register(&disBuilder)
|
resolver.Register(&discovResolverBuilder)
|
||||||
resolver.Register(&k8sBuilder)
|
resolver.Register(&etcdResolverBuilder)
|
||||||
|
resolver.Register(&k8sResolverBuilder)
|
||||||
}
|
}
|
||||||
|
|
||||||
type nopResolver struct {
|
type nopResolver struct {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import "math/rand"
|
import "math/rand"
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package resolver
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
11
zrpc/resolver/register.go
Normal file
11
zrpc/resolver/register.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package resolver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tal-tech/go-zero/zrpc/resolver/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Register registers schemes defined zrpc.
|
||||||
|
// Keep it in a separated package to let third party register manually.
|
||||||
|
func Register() {
|
||||||
|
internal.RegisterResolver()
|
||||||
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
package internal
|
package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tal-tech/go-zero/zrpc/internal/resolver"
|
"github.com/tal-tech/go-zero/zrpc/resolver/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BuildDirectTarget returns a string that represents the given endpoints with direct schema.
|
// BuildDirectTarget returns a string that represents the given endpoints with direct schema.
|
||||||
func BuildDirectTarget(endpoints []string) string {
|
func BuildDirectTarget(endpoints []string) string {
|
||||||
return fmt.Sprintf("%s:///%s", resolver.DirectScheme,
|
return fmt.Sprintf("%s:///%s", internal.DirectScheme,
|
||||||
strings.Join(endpoints, resolver.EndpointSep))
|
strings.Join(endpoints, internal.EndpointSep))
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildDiscovTarget returns a string that represents the given endpoints with discov schema.
|
// BuildDiscovTarget returns a string that represents the given endpoints with discov schema.
|
||||||
func BuildDiscovTarget(endpoints []string, key string) string {
|
func BuildDiscovTarget(endpoints []string, key string) string {
|
||||||
return fmt.Sprintf("%s://%s/%s", resolver.DiscovScheme,
|
return fmt.Sprintf("%s://%s/%s", internal.DiscovScheme,
|
||||||
strings.Join(endpoints, resolver.EndpointSep), key)
|
strings.Join(endpoints, internal.EndpointSep), key)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package internal
|
package resolver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -38,9 +38,9 @@ func NewServer(c RpcServerConf, register internal.RegisterFn) (*RpcServer, error
|
|||||||
|
|
||||||
var server internal.Server
|
var server internal.Server
|
||||||
metrics := stat.NewMetrics(c.ListenOn)
|
metrics := stat.NewMetrics(c.ListenOn)
|
||||||
// TODO: enable it in v1.2.4
|
serverOptions := []internal.ServerOption{
|
||||||
// serverOptions := []internal.ServerOption{internal.WithMetrics(metrics), internal.WithMaxRetries(c.MaxRetries)}
|
internal.WithMetrics(metrics),
|
||||||
serverOptions := []internal.ServerOption{internal.WithMetrics(metrics)}
|
}
|
||||||
|
|
||||||
if c.HasEtcd() {
|
if c.HasEtcd() {
|
||||||
server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, serverOptions...)
|
server, err = internal.NewRpcPubServer(c.Etcd, c.ListenOn, serverOptions...)
|
||||||
|
|||||||
Reference in New Issue
Block a user