├── test ├── alter_table_rename.sql ├── create_index.sql ├── drop_index.sql ├── alter_table_drop_column.sql ├── drop_table.sql ├── alter_table_modify_column.sql ├── test_comments.sql ├── alter_table_constraint.sql ├── alter_table_add_column.sql └── create_table.sql ├── vendor ├── github.com │ ├── timtadh │ │ ├── lexmachine │ │ │ ├── .gitignore │ │ │ ├── .activate │ │ │ ├── .gitmodules │ │ │ ├── CHANGELOG │ │ │ ├── grammar │ │ │ ├── Gopkg.lock │ │ │ ├── Gopkg.toml │ │ │ ├── queue │ │ │ │ └── queue.go │ │ │ ├── frontend │ │ │ │ ├── desugar.go │ │ │ │ ├── ast_equality.go │ │ │ │ ├── gen.go │ │ │ │ └── ast.go │ │ │ ├── LICENSE │ │ │ ├── inst │ │ │ │ └── inst.go │ │ │ ├── machines │ │ │ │ ├── dfa_machine.go │ │ │ │ └── machine.go │ │ │ ├── doc.go │ │ │ └── dfa │ │ │ │ └── dfa_helpers.go │ │ └── data-structures │ │ │ ├── types │ │ │ ├── map_entry.go │ │ │ ├── string.go │ │ │ ├── types.go │ │ │ ├── int.go │ │ │ └── util.go │ │ │ ├── rand │ │ │ └── rand.go │ │ │ ├── set │ │ │ ├── ops.go │ │ │ ├── setmap.go │ │ │ ├── mapset.go │ │ │ └── sortedset.go │ │ │ ├── LICENSE │ │ │ ├── errors │ │ │ └── errors.go │ │ │ ├── linked │ │ │ ├── unique.go │ │ │ └── linked.go │ │ │ ├── tree │ │ │ ├── util.go │ │ │ └── avl │ │ │ │ ├── avltree.go │ │ │ │ └── imm_avltree.go │ │ │ ├── hashtable │ │ │ ├── linhash.go │ │ │ └── hashtable.go │ │ │ └── list │ │ │ └── sorted.go │ ├── stretchr │ │ └── testify │ │ │ ├── assert │ │ │ ├── assertion_format.go.tmpl │ │ │ ├── assertion_forward.go.tmpl │ │ │ ├── errors.go │ │ │ ├── forward_assertions.go │ │ │ ├── doc.go │ │ │ ├── assertion_order.go │ │ │ └── http_assertions.go │ │ │ └── LICENSE │ ├── davecgh │ │ └── go-spew │ │ │ ├── LICENSE │ │ │ └── spew │ │ │ ├── bypasssafe.go │ │ │ ├── bypass.go │ │ │ ├── spew.go │ │ │ └── doc.go │ └── pmezard │ │ └── go-difflib │ │ └── LICENSE ├── gopkg.in │ └── yaml.v3 │ │ ├── go.mod │ │ ├── .travis.yml │ │ ├── NOTICE │ │ ├── writerc.go │ │ ├── LICENSE │ │ ├── sorter.go │ │ ├── README.md │ │ └── yamlprivateh.go └── modules.txt ├── go.mod ├── .gitignore ├── ast ├── element │ ├── basic.go │ └── datatype.go ├── node.go ├── base.go └── ddl.go ├── parser.go ├── lexer_test.go ├── go.sum ├── README.md └── parser_test.go /test/alter_table_rename.sql: -------------------------------------------------------------------------------- 1 | alter table db1.table1 rename column id to new_id; -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | bin 4 | pkg 5 | vendor 6 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/.activate: -------------------------------------------------------------------------------- 1 | export GOPATH=$(readlink -e $(pwd)/../../../..) 2 | export PATH=$GOPATH/bin:$PATH 3 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/go.mod: -------------------------------------------------------------------------------- 1 | module "gopkg.in/yaml.v3" 2 | 3 | require ( 4 | "gopkg.in/check.v1" v0.0.0-20161208181325-20d25e280405 5 | ) 6 | -------------------------------------------------------------------------------- /test/create_index.sql: -------------------------------------------------------------------------------- 1 | create index db1.idx1 on db1.table1 (id); 2 | 3 | CREATE UNIQUE INDEX "TEST"."SYS_C00385176" on "TEST"."SBTEST1"("ID") NOPARALLEL; -------------------------------------------------------------------------------- /test/drop_index.sql: -------------------------------------------------------------------------------- 1 | drop index idx_1; 2 | 3 | drop index db1.idx_1; 4 | 5 | drop index db1.idx_1 online; 6 | 7 | drop index db1.idx_1 online force; -------------------------------------------------------------------------------- /test/alter_table_drop_column.sql: -------------------------------------------------------------------------------- 1 | alter table db1.table1 drop column id; 2 | 3 | alter table db1.table1 drop (id,name); 4 | 5 | alter table db1.table1 set unused column id; -------------------------------------------------------------------------------- /test/drop_table.sql: -------------------------------------------------------------------------------- 1 | drop table db1.table1; 2 | 3 | drop table table1; 4 | 5 | drop table db1.table1 cascade constraints purge; 6 | 7 | drop table table1 cascade constraints; 8 | 9 | drop table db1.table1 purge; -------------------------------------------------------------------------------- /test/alter_table_modify_column.sql: -------------------------------------------------------------------------------- 1 | alter table db1.table1 modify (id varchar2(255)); 2 | 3 | alter table db1.table1 modify (id varchar2(255) default '123'); 4 | 5 | alter table db1.table1 modify (id varchar2(255) unique); -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/sjjian/oracle-sql-parser 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/stretchr/testify v1.7.0 7 | github.com/timtadh/data-structures v0.5.3 // indirect 8 | github.com/timtadh/lexmachine v0.2.2 9 | ) 10 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | y.output 15 | 16 | .idea/ 17 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.4.x" 5 | - "1.5.x" 6 | - "1.6.x" 7 | - "1.7.x" 8 | - "1.8.x" 9 | - "1.9.x" 10 | - "1.10.x" 11 | - "1.11.x" 12 | - "1.12.x" 13 | - "1.13.x" 14 | - "tip" 15 | 16 | go_import_path: gopkg.in/yaml.v3 17 | -------------------------------------------------------------------------------- /ast/element/basic.go: -------------------------------------------------------------------------------- 1 | package element 2 | 3 | const ( 4 | IdentifierTypeQuoted = iota // "schema" . "table" 5 | IdentifierTypeNonQuoted // schema . table 6 | ) 7 | 8 | type Identifier struct { 9 | Typ int 10 | Value string 11 | } 12 | 13 | type NumberOrAsterisk struct { 14 | Number int 15 | IsAsterisk bool 16 | } -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/github.com/timtadh/getopt"] 2 | path = src/github.com/timtadh/getopt 3 | url = git@github.com:timtadh/getopt.git 4 | [submodule "src/github.com/timtadh/data-structures"] 5 | path = src/github.com/timtadh/data-structures 6 | url = git@github.com:timtadh/data-structures.git 7 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/CHANGELOG: -------------------------------------------------------------------------------- 1 | ## 0.2.1 2 | 3 | - Fixed regression bugs in new DFA backend 4 | 5 | ## 0.2.0 6 | 7 | - Added DFA backend 8 | - Improved documentation 9 | - Fixed lint issues 10 | 11 | ## 0.1.1 12 | 13 | - Improved regex parser 14 | - Added documentation 15 | 16 | ## 0.1.0 initial release 17 | -------------------------------------------------------------------------------- /parser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "fmt" 5 | "github.com/sjjian/oracle-sql-parser/ast" 6 | ) 7 | 8 | func Parser(query string) ([]ast.Node, error) { 9 | l, err := NewLexer(query) 10 | if err != nil { 11 | fmt.Println(err) 12 | return nil, err 13 | } 14 | 15 | //yyDebug = 4 16 | yyParse(l) 17 | if l.err != nil { 18 | return nil, l.err 19 | } 20 | return l.result, nil 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /ast/node.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | type Node interface { 4 | Text() string 5 | SetText(text string) 6 | } 7 | 8 | // node is the struct implements Node interface 9 | type node struct { 10 | text string 11 | } 12 | 13 | // Text implements Node interface. 14 | func (n *node) Text() string { 15 | return n.text 16 | } 17 | 18 | // SetText implements Node interface. 19 | func (n *node) SetText(text string) { 20 | n.text = text 21 | } 22 | -------------------------------------------------------------------------------- /test/test_comments.sql: -------------------------------------------------------------------------------- 1 | --comment 2 | CREATE TABLE db1.t1 ( 3 | id int, -- comment 4 | name varchar2(255) -- comment comment 5 | ); -- !@#$%^&*( 6 | 7 | /* 8 | comment comment comment 9 | */ 10 | CREATE TABLE db1.t1 ( 11 | /* comment */ 12 | id int, 13 | name varchar2(255) 14 | ); 15 | 16 | /* 17 | comment comment comment 18 | */ 19 | CREATE TABLE db1.t1 ( 20 | /* comment */ 21 | id int, -- comment 22 | name varchar2(255) -- comment comment 23 | ); -- !@#$%^&*( -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs" 17 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2016 Canonical Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/grammar: -------------------------------------------------------------------------------- 1 | Regex : Alternation 2 | 3 | Alternation : AtomicOps Alternation' 4 | 5 | Alternation' : '|' AtomicOps Alternation' 6 | | e 7 | 8 | AtomicOps : AtomicOp AtomicOps 9 | | e 10 | 11 | AtomicOp : Atomic 12 | | Atomic Op 13 | 14 | Atomic : Concat 15 | | Group 16 | 17 | Op : '+' 18 | | '*' 19 | | '?' 20 | 21 | Group : '(' Alternation ')' 22 | 23 | Concat : Char Concat 24 | | e 25 | 26 | Char : CHAR 27 | | CharRange 28 | 29 | CharRange : '[' RangeInner ']' 30 | | '[' '^' RangeInner ']' 31 | 32 | RangeInner : RangeComponent RangeInner 33 | | e 34 | 35 | RangeComponent : CHAR 36 | | CHAR '-' CHAR 37 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/types/map_entry.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | type MapEntry struct { 8 | Key Hashable 9 | Value interface{} 10 | } 11 | 12 | func (m *MapEntry) Equals(other Equatable) bool { 13 | if o, ok := other.(*MapEntry); ok { 14 | return m.Key.Equals(o.Key) 15 | } else { 16 | return m.Key.Equals(other) 17 | } 18 | } 19 | 20 | func (m *MapEntry) Less(other Sortable) bool { 21 | if o, ok := other.(*MapEntry); ok { 22 | return m.Key.Less(o.Key) 23 | } else { 24 | return m.Key.Less(other) 25 | } 26 | } 27 | 28 | func (m *MapEntry) Hash() int { 29 | return m.Key.Hash() 30 | } 31 | 32 | func (m *MapEntry) String() string { 33 | return fmt.Sprintf("", m.Key, m.Value) 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/timtadh/data-structures" 6 | packages = ["errors","hashtable","linked","list","rand","set","test","tree","tree/avl","types"] 7 | revision = "cd0c1de5390876f92ce0762c9c626a569b124f24" 8 | version = "v0.5.2" 9 | 10 | [[projects]] 11 | name = "github.com/timtadh/getopt" 12 | packages = ["."] 13 | revision = "29f1208d827b977f2e4060ca9923032b34094187" 14 | version = "v1.0.0" 15 | 16 | [solve-meta] 17 | analyzer-name = "dep" 18 | analyzer-version = 1 19 | inputs-digest = "76403af9b8313eb4c8dec248b6daa284bd8bf99ca2aebb7c22bd1b5ad203cb65" 20 | solver-name = "gps-cdcl" 21 | solver-version = 1 22 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/Gopkg.toml: -------------------------------------------------------------------------------- 1 | ## "required" lists a set of packages (not projects) that must be included in 2 | ## Gopkg.lock. This list is merged with the set of packages imported by the current 3 | ## project. Use it when your project needs a package it doesn't explicitly import - 4 | ## including "main" packages. 5 | required = [] 6 | 7 | ## "ignored" lists a set of packages (not projects) that are ignored when 8 | ## dep statically analyzes source code. Ignored packages can be in this project, 9 | ## or in a dependency. 10 | ignored = [] 11 | 12 | ## Constraints are rules for how directly imported projects 13 | ## may be incorporated into the depgraph. They are respected by 14 | ## dep whether coming from the Gopkg.toml of the current project or a dependency. 15 | [[constraint]] 16 | name = "github.com/timtadh/data-structures" 17 | version = ">=0.5.2" 18 | -------------------------------------------------------------------------------- /test/alter_table_constraint.sql: -------------------------------------------------------------------------------- 1 | alter table db1.table1 add primary key(id); 2 | 3 | alter table db1.table1 drop primary key; 4 | 5 | alter table db1.table1 drop unique(name,age); 6 | 7 | alter table db1.table1 drop constraint idx_1; 8 | 9 | alter table db1.table1 drop primary key drop unique(name,age); 10 | 11 | alter table db1.table1 drop primary key drop unique(name,age) drop constraint idx_1; 12 | 13 | alter table db1.table1 rename constraint idx_1 to idx_2; 14 | 15 | alter table db1.table1 modify primary key using index; 16 | 17 | alter table db1.table1 modify primary key rely using index idx_1 enable validate; 18 | 19 | alter table db1.table1 modify constraint idx_1 using index; 20 | 21 | alter table db1.table1 modify unique(name,age) using index; 22 | 23 | alter table db1.table1 drop primary key keep index; 24 | 25 | alter table db1.table1 drop primary key keep index drop unique(name,age) drop index; -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/davecgh/go-spew v1.1.0 2 | github.com/davecgh/go-spew/spew 3 | # github.com/pmezard/go-difflib v1.0.0 4 | github.com/pmezard/go-difflib/difflib 5 | # github.com/stretchr/testify v1.7.0 6 | ## explicit 7 | github.com/stretchr/testify/assert 8 | # github.com/timtadh/data-structures v0.5.3 9 | ## explicit 10 | github.com/timtadh/data-structures/errors 11 | github.com/timtadh/data-structures/hashtable 12 | github.com/timtadh/data-structures/linked 13 | github.com/timtadh/data-structures/list 14 | github.com/timtadh/data-structures/rand 15 | github.com/timtadh/data-structures/set 16 | github.com/timtadh/data-structures/tree 17 | github.com/timtadh/data-structures/tree/avl 18 | github.com/timtadh/data-structures/types 19 | # github.com/timtadh/lexmachine v0.2.2 20 | ## explicit 21 | github.com/timtadh/lexmachine 22 | github.com/timtadh/lexmachine/dfa 23 | github.com/timtadh/lexmachine/frontend 24 | github.com/timtadh/lexmachine/inst 25 | github.com/timtadh/lexmachine/machines 26 | github.com/timtadh/lexmachine/queue 27 | # gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c 28 | gopkg.in/yaml.v3 29 | -------------------------------------------------------------------------------- /test/alter_table_add_column.sql: -------------------------------------------------------------------------------- 1 | alter table db1.table1 add (id number); 2 | 3 | alter table db1.table1 add (id number, name varchar(255)); 4 | 5 | alter table db1.table1 add (id number(*)); 6 | 7 | alter table db1.table1 add (id number(5)); 8 | 9 | alter table db1.table1 add (id number(5, 3)); 10 | 11 | alter table db1.table1 add (id float(*)); 12 | 13 | alter table db1.table1 add (id float(5)); 14 | 15 | alter table db1.table1 add (id varchar2(255)); 16 | 17 | alter table db1.table1 add (id varchar2(255) collate binary_ci); 18 | 19 | alter table db1.table1 add (id varchar2(255) sort); 20 | 21 | alter table db1.table1 add (id varchar2(255) collate binary_ci sort); 22 | 23 | alter table db1.table1 add (id varchar2(255) collate binary_ci invisible); 24 | 25 | alter table db1.table1 add (id varchar2(255) collate binary_ci visible); 26 | 27 | alter table db1.table1 add (id varchar2(255) collate binary_ci sort invisible); 28 | 29 | alter table db1.table1 add (id varchar2(255) default 'test'); 30 | 31 | alter table db1.table1 add (id number default 123); 32 | 33 | alter table db1.table1 add (id number not null, name varchar(255) unique); 34 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/queue/queue.go: -------------------------------------------------------------------------------- 1 | package queue 2 | 3 | // Queue is a fast unique items queue which stores positive integers up to a 4 | // fixed bound. 5 | type Queue struct { 6 | list []uint32 7 | set []uint32 8 | } 9 | 10 | // New creates a Queue where n-1 is the maximum positive integer which can be 11 | // stored in the queue. 12 | func New(n int) *Queue { 13 | q := new(Queue) 14 | q.list = make([]uint32, 0, 10) 15 | q.set = make([]uint32, n) 16 | return q 17 | } 18 | 19 | // Empty returns true if the queue is empty 20 | func (q *Queue) Empty() bool { return len(q.list) <= 0 } 21 | 22 | // Has checks the queue to see if pc is in it 23 | func (q *Queue) Has(pc uint32) bool { 24 | idx := q.set[pc] 25 | return idx < uint32(len(q.list)) && q.list[idx] == pc 26 | } 27 | 28 | // Clear clears the queue 29 | func (q *Queue) Clear() { 30 | q.list = q.list[:0] 31 | } 32 | 33 | // Push adds an item to the queue 34 | func (q *Queue) Push(pc uint32) { 35 | if q.Has(pc) { 36 | return 37 | } 38 | q.set[pc] = uint32(len(q.list)) 39 | q.list = append(q.list, pc) 40 | } 41 | 42 | // Pop removes an item from the queue 43 | func (q *Queue) Pop() uint32 { 44 | pc := q.list[len(q.list)-1] 45 | q.list = q.list[:len(q.list)-1] 46 | return pc 47 | } 48 | -------------------------------------------------------------------------------- /lexer_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestGenKeywordIdent(t *testing.T) { 10 | testCases := map[string][]byte{ 11 | "a": []byte("[Aa]"), 12 | "B": []byte("[Bb]"), 13 | "case": []byte("[Cc][Aa][Ss][Ee]"), 14 | "CASE": []byte("[Cc][Aa][Ss][Ee]"), 15 | "CaSe": []byte("[Cc][Aa][Ss][Ee]"), 16 | "a_b": []byte("[Aa]_[Bb]"), 17 | "": nil, 18 | } 19 | for input, expect := range testCases { 20 | actual := genKeywordIdent(input) 21 | assert.Equal(t, string(expect), string(actual)) 22 | } 23 | } 24 | 25 | type genGroupKeywordCase struct { 26 | expect []byte 27 | input []string 28 | } 29 | 30 | func TestGenGroupKeywordIdent(t *testing.T) { 31 | testCases := []genGroupKeywordCase{ 32 | { 33 | input: []string{}, 34 | expect: nil, 35 | }, 36 | { 37 | input: []string{"a"}, 38 | expect: []byte("[Aa]"), 39 | }, 40 | { 41 | input: []string{"B"}, 42 | expect: []byte("[Bb]"), 43 | }, 44 | { 45 | input: []string{"a", "B"}, 46 | expect: []byte("[Aa]( |\t|\n|\r)+[Bb]"), 47 | }, 48 | { 49 | input: []string{"a", "B", "CasE"}, 50 | expect: []byte("[Aa]( |\t|\n|\r)+[Bb]( |\t|\n|\r)+[Cc][Aa][Ss][Ee]"), 51 | }, 52 | } 53 | for _, c := range testCases { 54 | actual := genGroupKeywordIdent(c.input...) 55 | assert.Equal(t, string(c.expect), string(actual)) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= 2 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 4 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 5 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 6 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 7 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 8 | github.com/timtadh/data-structures v0.5.3 h1:F2tEjoG9qWIyUjbvXVgJqEOGJPMIiYn7U5W5mE+i/vQ= 9 | github.com/timtadh/data-structures v0.5.3/go.mod h1:9R4XODhJ8JdWFEI8P/HJKqxuJctfBQw6fDibMQny2oU= 10 | github.com/timtadh/lexmachine v0.2.2 h1:g55RnjdYazm5wnKv59pwFcBJHOyvTPfDEoz21s4PHmY= 11 | github.com/timtadh/lexmachine v0.2.2/go.mod h1:GBJvD5OAfRn/gnp92zb9KTgHLB7akKyxmVivoYCcjQI= 12 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 13 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 14 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 15 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 16 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/frontend/desugar.go: -------------------------------------------------------------------------------- 1 | package frontend 2 | 3 | import "fmt" 4 | 5 | // DesugarRanges transform all Range nodes into Alternatives with individual characters 6 | func DesugarRanges(ast AST) AST { 7 | switch n := ast.(type) { 8 | case *AltMatch: 9 | return &AltMatch{A: DesugarRanges(n.A), B: DesugarRanges(n.B)} 10 | case *Match: 11 | return &Match{AST: DesugarRanges(n.AST)} 12 | case *Alternation: 13 | return &Alternation{A: DesugarRanges(n.A), B: DesugarRanges(n.B)} 14 | case *Star: 15 | return &Star{AST: DesugarRanges(n.AST)} 16 | case *Plus: 17 | return &Plus{AST: DesugarRanges(n.AST)} 18 | case *Maybe: 19 | return &Maybe{AST: DesugarRanges(n.AST)} 20 | case *Concat: 21 | items := make([]AST, 0, len(n.Items)) 22 | for _, i := range n.Items { 23 | items = append(items, DesugarRanges(i)) 24 | } 25 | return &Concat{Items: items} 26 | case *Character: 27 | return n 28 | case *EOS: 29 | return n 30 | case *Range: 31 | chars := make([]*Character, 0, n.To-n.From+1) 32 | for i := int(n.From); i <= int(n.To); i++ { 33 | chars = append(chars, NewCharacter(byte(i))) 34 | } 35 | if len(chars) <= 0 { 36 | panic(fmt.Errorf("Empty, unmatchable range: %v", n)) 37 | } 38 | if len(chars) == 1 { 39 | return chars[0] 40 | } 41 | alt := NewAlternation(chars[0], chars[1]) 42 | for i := 2; i < len(chars); i++ { 43 | alt = NewAlternation(alt, chars[i]) 44 | } 45 | return alt 46 | default: 47 | panic(fmt.Errorf("Unexpected node type %T", n)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Oracle SQL Parser 2 | this is an oracle sql parser. ref: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf 3 | 4 | ## supported statement 5 | |statement| sub statement |yacc|ast| 6 | |----|----|----|----| 7 | |Alter table|Add column| :heavy_check_mark:|:heavy_check_mark:| 8 | |Alter table|Modify column| :heavy_check_mark:|:heavy_check_mark:| 9 | |Alter table|Drop column| :heavy_check_mark:|:heavy_check_mark:| 10 | |Alter table|Rename column| :heavy_check_mark:|:heavy_check_mark:| 11 | |Alter table|Add constraint| :heavy_check_mark:| :heavy_check_mark:| 12 | |Alter table|Modify constraint| :heavy_check_mark:| :heavy_check_mark:| 13 | |Alter table|Rename constraint| :heavy_check_mark:| :heavy_check_mark:| 14 | |Alter table|Drop constraint| :heavy_check_mark:| :heavy_check_mark:| 15 | |Create table|Relational table|:heavy_check_mark:|:heavy_check_mark:| 16 | |Create index|Relational table|:heavy_check_mark:| | 17 | |Drop table|-|:heavy_check_mark:|:heavy_check_mark:| 18 | |Drop index|-|:heavy_check_mark:|:heavy_check_mark:| 19 | 20 | ## usage 21 | ```go 22 | package main 23 | 24 | import ( 25 | "fmt" 26 | "github.com/sjjian/oracle-sql-parser" 27 | "github.com/sjjian/oracle-sql-parser/ast" 28 | ) 29 | 30 | func main() { 31 | stmts, err := parser.Parser("alter table db1.t1 add (id number, name varchar2(255))") 32 | if err != nil { 33 | fmt.Println(err) 34 | return 35 | } 36 | stmt := stmts[0] 37 | switch s := stmt.(type) { 38 | case *ast.AlterTableStmt: 39 | fmt.Println(s.TableName.Table.Value) // t1 40 | } 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/types/string.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | import ( 4 | "bytes" 5 | "hash/fnv" 6 | ) 7 | 8 | type String string 9 | type ByteSlice []byte 10 | 11 | func (self *String) MarshalBinary() ([]byte, error) { 12 | return []byte(*self), nil 13 | } 14 | 15 | func (self *String) UnmarshalBinary(data []byte) error { 16 | *self = String(data) 17 | return nil 18 | } 19 | 20 | func (self String) Equals(other Equatable) bool { 21 | if o, ok := other.(String); ok { 22 | return self == o 23 | } else { 24 | return false 25 | } 26 | } 27 | 28 | func (self String) Less(other Sortable) bool { 29 | if o, ok := other.(String); ok { 30 | return self < o 31 | } else { 32 | return false 33 | } 34 | } 35 | 36 | func (self String) Hash() int { 37 | h := fnv.New32a() 38 | h.Write([]byte(string(self))) 39 | return int(h.Sum32()) 40 | } 41 | 42 | func (self *ByteSlice) MarshalBinary() ([]byte, error) { 43 | return []byte(*self), nil 44 | } 45 | 46 | func (self *ByteSlice) UnmarshalBinary(data []byte) error { 47 | *self = ByteSlice(data) 48 | return nil 49 | } 50 | 51 | func (self ByteSlice) Equals(other Equatable) bool { 52 | if o, ok := other.(ByteSlice); ok { 53 | return bytes.Equal(self, o) 54 | } else { 55 | return false 56 | } 57 | } 58 | 59 | func (self ByteSlice) Less(other Sortable) bool { 60 | if o, ok := other.(ByteSlice); ok { 61 | return bytes.Compare(self, o) < 0 // -1 if a < b 62 | } else { 63 | return false 64 | } 65 | } 66 | 67 | func (self ByteSlice) Hash() int { 68 | h := fnv.New32a() 69 | h.Write([]byte(self)) 70 | return int(h.Sum32()) 71 | } 72 | -------------------------------------------------------------------------------- /ast/base.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import ( 4 | "github.com/sjjian/oracle-sql-parser/ast/element" 5 | ) 6 | 7 | type TableName struct { 8 | Schema *element.Identifier 9 | Table *element.Identifier 10 | } 11 | 12 | type IndexName struct { 13 | Schema *element.Identifier 14 | Index *element.Identifier 15 | } 16 | 17 | type Collation struct { 18 | Name *element.Identifier 19 | } 20 | 21 | type ColumnProp int 22 | 23 | const ( 24 | ColumnPropEmpty ColumnProp = iota 25 | ColumnPropSort // for add column 26 | ColumnPropInvisible 27 | ColumnPropVisible 28 | ColumnPropSubstitutable // for modify column 29 | ColumnPropNotSubstitutable // for modify column 30 | ColumnPropSubstitutableForce // for modify column 31 | ColumnPropNotSubstitutableForce // for modify column 32 | ) 33 | 34 | type ColumnDefault struct { 35 | OnNull bool 36 | Value interface{} 37 | } 38 | 39 | type ConstraintType int 40 | 41 | const ( 42 | ConstraintTypeDefault ConstraintType = iota 43 | ConstraintTypeNull 44 | ConstraintTypeNotNull 45 | ConstraintTypeUnique 46 | ConstraintTypePK 47 | ConstraintTypeReferences 48 | ) 49 | 50 | //type ConstraintState int 51 | 52 | //const ( 53 | // ConstraintStateDeferrable ConstraintState = iota 54 | // ConstraintStateNotDeferrable 55 | // ConstraintStateInitiallyDeferred 56 | // ConstraintStateInitiallyImmediate 57 | // ConstraintStateRely 58 | // ConstraintStateNorely 59 | //) 60 | 61 | type DropColumnType int 62 | 63 | const ( 64 | DropColumnTypeDrop DropColumnType = iota 65 | DropColumnTypeSetUnused 66 | DropColumnTypeDropUnusedColumns 67 | DropColumnTypeDropColumnsContinue 68 | ) 69 | 70 | type DropColumnProp int 71 | 72 | const ( 73 | DropColumnPropEmpty DropColumnProp = iota 74 | DropColumnPropCascade 75 | DropColumnPropInvalidate 76 | DropColumnPropOnline 77 | ) 78 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/rand/rand.go: -------------------------------------------------------------------------------- 1 | package rand 2 | 3 | import ( 4 | "math/rand" 5 | "sync" 6 | ) 7 | 8 | // ThreadSafeRand provides a thread safe version of math/rand.Rand using 9 | // the same technique used in the math/rand package to make the top level 10 | // functions thread safe. 11 | func ThreadSafeRand(seed int64) *rand.Rand { 12 | return rand.New(&lockedSource{src: rand.NewSource(seed).(rand.Source64)}) 13 | } 14 | 15 | // from: https://golang.org/src/math/rand/rand.go?s=8161:8175#L317 16 | type lockedSource struct { 17 | lk sync.Mutex 18 | src rand.Source64 19 | } 20 | 21 | func (r *lockedSource) Int63() (n int64) { 22 | r.lk.Lock() 23 | n = r.src.Int63() 24 | r.lk.Unlock() 25 | return 26 | } 27 | 28 | func (r *lockedSource) Uint64() (n uint64) { 29 | r.lk.Lock() 30 | n = r.src.Uint64() 31 | r.lk.Unlock() 32 | return 33 | } 34 | 35 | func (r *lockedSource) Seed(seed int64) { 36 | r.lk.Lock() 37 | r.src.Seed(seed) 38 | r.lk.Unlock() 39 | } 40 | 41 | // seedPos implements Seed for a lockedSource without a race condiiton. 42 | func (r *lockedSource) seedPos(seed int64, readPos *int8) { 43 | r.lk.Lock() 44 | r.src.Seed(seed) 45 | *readPos = 0 46 | r.lk.Unlock() 47 | } 48 | 49 | // read implements Read for a lockedSource without a race condition. 50 | func (r *lockedSource) read(p []byte, readVal *int64, readPos *int8) (n int, err error) { 51 | r.lk.Lock() 52 | n, err = read(p, r.src.Int63, readVal, readPos) 53 | r.lk.Unlock() 54 | return 55 | } 56 | 57 | func read(p []byte, int63 func() int64, readVal *int64, readPos *int8) (n int, err error) { 58 | pos := *readPos 59 | val := *readVal 60 | for n = 0; n < len(p); n++ { 61 | if pos == 0 { 62 | val = int63() 63 | pos = 7 64 | } 65 | p[n] = byte(val) 66 | val >>= 8 67 | pos-- 68 | } 69 | *readPos = pos 70 | *readVal = val 71 | return 72 | } 73 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/LICENSE: -------------------------------------------------------------------------------- 1 | lexmachine 2 | 3 | This library is wholly written by the authors below. Please respect all 4 | licensing terms. 5 | 6 | Copyright (c) 2014-2017 All rights reserved. Portions owned by 7 | * Tim Henderson 8 | * Case Western Reserve Univserity 9 | * Google Inc. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, 15 | this list of conditions and the following disclaimer. 16 | * Redistributions in binary form must reproduce the above copyright notice, 17 | this list of conditions and the following disclaimer in the documentation 18 | and/or other materials provided with the distribution. 19 | * Neither the name of the lexmachine nor the names of its contributors may 20 | be used to endorse or promote products derived from this software without 21 | specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 30 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/writerc.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011-2019 Canonical Ltd 3 | // Copyright (c) 2006-2010 Kirill Simonov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | // of the Software, and to permit persons to whom the Software is furnished to do 10 | // so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | // SOFTWARE. 22 | 23 | package yaml 24 | 25 | // Set the writer error and return false. 26 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 27 | emitter.error = yaml_WRITER_ERROR 28 | emitter.problem = problem 29 | return false 30 | } 31 | 32 | // Flush the output buffer. 33 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 34 | if emitter.write_handler == nil { 35 | panic("write handler not set") 36 | } 37 | 38 | // Check if the buffer is empty. 39 | if emitter.buffer_pos == 0 { 40 | return true 41 | } 42 | 43 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 44 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 45 | } 46 | emitter.buffer_pos = 0 47 | return true 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/set/ops.go: -------------------------------------------------------------------------------- 1 | package set 2 | 3 | import ( 4 | "github.com/timtadh/data-structures/hashtable" 5 | "github.com/timtadh/data-structures/types" 6 | ) 7 | 8 | func newSetBestType(a types.Set, sizeHint int) types.Set { 9 | switch a.(type) { 10 | case *MapSet: 11 | return NewMapSet(NewSortedSet(sizeHint)) 12 | case *SortedSet: 13 | return NewSortedSet(sizeHint) 14 | case *SetMap: 15 | return NewSetMap(hashtable.NewLinearHash()) 16 | default: 17 | return NewSortedSet(sizeHint) 18 | } 19 | } 20 | 21 | func Union(a, b types.Set) (types.Set, error) { 22 | c := newSetBestType(a, a.Size()+b.Size()) 23 | err := c.Extend(a.Items()) 24 | if err != nil { 25 | return nil, err 26 | } 27 | err = c.Extend(b.Items()) 28 | if err != nil { 29 | return nil, err 30 | } 31 | return c, nil 32 | } 33 | 34 | func Intersect(a, b types.Set) (types.Set, error) { 35 | c := newSetBestType(a, a.Size()+b.Size()) 36 | for item, next := a.Items()(); next != nil; item, next = next() { 37 | if b.Has(item) { 38 | err := c.Add(item) 39 | if err != nil { 40 | return nil, err 41 | } 42 | } 43 | } 44 | return c, nil 45 | } 46 | 47 | // Unions s with o and returns a new Sorted Set 48 | func Subtract(a, b types.Set) (types.Set, error) { 49 | c := newSetBestType(a, a.Size()+b.Size()) 50 | for item, next := a.Items()(); next != nil; item, next = next() { 51 | if !b.Has(item) { 52 | err := c.Add(item) 53 | if err != nil { 54 | return nil, err 55 | } 56 | } 57 | } 58 | return c, nil 59 | } 60 | 61 | func Subset(a, b types.Set) bool { 62 | if a.Size() > b.Size() { 63 | return false 64 | } 65 | for item, next := a.Items()(); next != nil; item, next = next() { 66 | if !b.Has(item) { 67 | return false 68 | } 69 | } 70 | return true 71 | } 72 | 73 | func ProperSubset(a, b types.Set) bool { 74 | if a.Size() >= b.Size() { 75 | return false 76 | } 77 | return Subset(a, b) 78 | } 79 | 80 | func Superset(a, b types.Set) bool { 81 | return Subset(b, a) 82 | } 83 | 84 | func ProperSuperset(a, b types.Set) bool { 85 | return ProperSubset(b, a) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/frontend/ast_equality.go: -------------------------------------------------------------------------------- 1 | package frontend 2 | 3 | // Equals checks deep equality of the two trees 4 | func (c *Concat) Equals(o AST) bool { 5 | if x, is := o.(*Concat); is { 6 | if len(c.Items) != len(x.Items) { 7 | return false 8 | } 9 | for i := range c.Items { 10 | if !c.Items[i].Equals(x.Items[i]) { 11 | return false 12 | } 13 | } 14 | return true 15 | } 16 | return false 17 | } 18 | 19 | // Equals checks deep equality of the two trees 20 | func (a *AltMatch) Equals(o AST) bool { 21 | if x, is := o.(*AltMatch); is { 22 | return a.A.Equals(x.A) && a.B.Equals(x.B) 23 | } 24 | return false 25 | } 26 | 27 | // Equals checks deep equality of the two trees 28 | func (a *Alternation) Equals(o AST) bool { 29 | if x, is := o.(*Alternation); is { 30 | return a.A.Equals(x.A) && a.B.Equals(x.B) 31 | } 32 | return false 33 | } 34 | 35 | // Equals checks deep equality of the two trees 36 | func (m *Match) Equals(o AST) bool { 37 | if x, is := o.(*Match); is { 38 | return m.AST.Equals(x.AST) 39 | } 40 | return false 41 | } 42 | 43 | // Equals checks deep equality of the two trees 44 | func (s *Star) Equals(o AST) bool { 45 | if x, is := o.(*Star); is { 46 | return s.AST.Equals(x.AST) 47 | } 48 | return false 49 | } 50 | 51 | // Equals checks deep equality of the two trees 52 | func (p *Plus) Equals(o AST) bool { 53 | if x, is := o.(*Plus); is { 54 | return p.AST.Equals(x.AST) 55 | } 56 | return false 57 | } 58 | 59 | // Equals checks deep equality of the two trees 60 | func (m *Maybe) Equals(o AST) bool { 61 | if x, is := o.(*Maybe); is { 62 | return m.AST.Equals(x.AST) 63 | } 64 | return false 65 | } 66 | 67 | // Equals checks deep equality of the two trees 68 | func (c *Character) Equals(o AST) bool { 69 | if x, is := o.(*Character); is { 70 | return *c == *x 71 | } 72 | return false 73 | } 74 | 75 | // Equals checks deep equality of the two trees 76 | func (r *Range) Equals(o AST) bool { 77 | if x, is := o.(*Range); is { 78 | return *r == *x 79 | } 80 | return false 81 | } 82 | 83 | // Equals checks deep equality of the two trees 84 | func (e *EOS) Equals(o AST) bool { 85 | if x, is := o.(*EOS); is { 86 | return *e == *x 87 | } 88 | return false 89 | } 90 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/inst/inst.go: -------------------------------------------------------------------------------- 1 | package inst 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | const ( 9 | CHAR = iota // CHAR instruction op code: match a byte in the range [X, Y] (inclusive) 10 | SPLIT // SPLIT instruction op code: split jump to both X and Y 11 | JMP // JMP instruction op code: jmp to X 12 | MATCH // MATCH instruction op code: match the string 13 | ) 14 | 15 | // Inst represents an NFA byte code instruction 16 | type Inst struct { 17 | Op uint8 18 | X uint32 19 | Y uint32 20 | } 21 | 22 | // Slice is a list of NFA instructions 23 | type Slice []*Inst 24 | 25 | // New creates a new instruction 26 | func New(op uint8, x, y uint32) *Inst { 27 | return &Inst{ 28 | Op: op, 29 | X: x, 30 | Y: y, 31 | } 32 | } 33 | 34 | // String humanizes the byte code 35 | func (i Inst) String() (s string) { 36 | switch i.Op { 37 | case CHAR: 38 | if i.X == i.Y { 39 | s = fmt.Sprintf("CHAR %d (%q)", i.X, string([]byte{byte(i.X)})) 40 | } else { 41 | s = fmt.Sprintf("CHAR %d (%q), %d (%q)", i.X, string([]byte{byte(i.X)}), i.Y, string([]byte{byte(i.Y)})) 42 | } 43 | case SPLIT: 44 | s = fmt.Sprintf("SPLIT %v, %v", i.X, i.Y) 45 | case JMP: 46 | s = fmt.Sprintf("JMP %v", i.X) 47 | case MATCH: 48 | s = "MATCH" 49 | } 50 | return 51 | } 52 | 53 | // Serialize outputs machine readable assembly 54 | func (i Inst) Serialize() (s string) { 55 | switch i.Op { 56 | case CHAR: 57 | s = fmt.Sprintf("CHAR %d, %d", i.X, i.Y) 58 | case SPLIT: 59 | s = fmt.Sprintf("SPLIT %v, %v", i.X, i.Y) 60 | case JMP: 61 | s = fmt.Sprintf("JMP %v", i.X) 62 | case MATCH: 63 | s = "MATCH" 64 | } 65 | return 66 | } 67 | 68 | // String humanizes the byte code 69 | func (is Slice) String() (s string) { 70 | s = "{\n" 71 | for i, inst := range is { 72 | if inst == nil { 73 | continue 74 | } 75 | if i < 10 { 76 | s += fmt.Sprintf(" 0%v %v\n", i, inst) 77 | } else { 78 | s += fmt.Sprintf(" %v %v\n", i, inst) 79 | } 80 | } 81 | s += "}" 82 | return 83 | } 84 | 85 | // Serialize outputs machine readable assembly 86 | func (is Slice) Serialize() (s string) { 87 | lines := make([]string, 0, len(is)) 88 | for i, inst := range is { 89 | lines = append(lines, fmt.Sprintf("%3d %s", i, inst.Serialize())) 90 | } 91 | return strings.Join(lines, "\n") 92 | } 93 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | This project is covered by two different licenses: MIT and Apache. 3 | 4 | #### MIT License #### 5 | 6 | The following files were ported to Go from C files of libyaml, and thus 7 | are still covered by their original MIT license, with the additional 8 | copyright staring in 2011 when the project was ported over: 9 | 10 | apic.go emitterc.go parserc.go readerc.go scannerc.go 11 | writerc.go yamlh.go yamlprivateh.go 12 | 13 | Copyright (c) 2006-2010 Kirill Simonov 14 | Copyright (c) 2006-2011 Kirill Simonov 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy of 17 | this software and associated documentation files (the "Software"), to deal in 18 | the Software without restriction, including without limitation the rights to 19 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 20 | of the Software, and to permit persons to whom the Software is furnished to do 21 | so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | 34 | ### Apache License ### 35 | 36 | All the remaining project files are covered by the Apache license: 37 | 38 | Copyright (c) 2011-2019 Canonical Ltd 39 | 40 | Licensed under the Apache License, Version 2.0 (the "License"); 41 | you may not use this file except in compliance with the License. 42 | You may obtain a copy of the License at 43 | 44 | http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | Unless required by applicable law or agreed to in writing, software 47 | distributed under the License is distributed on an "AS IS" BASIS, 48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | See the License for the specific language governing permissions and 50 | limitations under the License. 51 | -------------------------------------------------------------------------------- /parser_test.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "path/filepath" 7 | "strings" 8 | "testing" 9 | 10 | "github.com/sjjian/oracle-sql-parser/ast" 11 | "github.com/stretchr/testify/assert" 12 | ) 13 | 14 | func TestParserSQLCoverage(t *testing.T) { 15 | path := "./test" 16 | files, err := ioutil.ReadDir(path) 17 | if err != nil { 18 | t.Error(err) 19 | return 20 | } 21 | for _, f := range files { 22 | fmt.Printf("test sql file %s\n", f.Name()) 23 | if !strings.HasSuffix(f.Name(), ".sql") { 24 | continue 25 | } 26 | data, err := ioutil.ReadFile(filepath.Join(path, f.Name())) 27 | if err != nil { 28 | t.Error(err) 29 | return 30 | } 31 | query := string(data) 32 | stmts, err := Parser(query) 33 | if err != nil { 34 | t.Error(err) 35 | return 36 | } 37 | for _, stmt := range stmts { 38 | assert.NotNil(t, stmt) 39 | assert.Equal(t, len(stmt.Text()) > 0, true) 40 | } 41 | } 42 | } 43 | 44 | func TestSingleQuery(t *testing.T) { 45 | stmt, err := Parser(`create table db1.table1 (id number(10))`) 46 | assert.NoError(t, err) 47 | assert.Equal(t, 1, len(stmt)) 48 | assert.IsType(t, &ast.CreateTableStmt{}, stmt[0]) 49 | assert.Equal(t, `create table db1.table1 (id number(10))`, stmt[0].Text()) 50 | 51 | stmt, err = Parser(`create table db1.table1 (id number(10));`) 52 | assert.NoError(t, err) 53 | assert.Equal(t, 1, len(stmt)) 54 | assert.IsType(t, &ast.CreateTableStmt{}, stmt[0]) 55 | assert.Equal(t, `create table db1.table1 (id number(10));`, stmt[0].Text()) 56 | } 57 | 58 | func TestMultiQuery(t *testing.T) { 59 | stmt, err := Parser(`create table db1.table1 (id number(10)); 60 | alter table db1.table1 add (name varchar(255))`) 61 | assert.NoError(t, err) 62 | assert.Equal(t, 2, len(stmt)) 63 | assert.IsType(t, &ast.CreateTableStmt{}, stmt[0]) 64 | assert.Equal(t, "create table db1.table1 (id number(10));", stmt[0].Text()) 65 | assert.IsType(t, &ast.AlterTableStmt{}, stmt[1]) 66 | assert.Equal(t, "alter table db1.table1 add (name varchar(255))", stmt[1].Text()) 67 | 68 | stmt, err = Parser(`create table db1.table1 (id number(10)); 69 | alter table db1.table1 add (name varchar(255));`) 70 | assert.NoError(t, err) 71 | assert.Equal(t, 2, len(stmt)) 72 | assert.IsType(t, &ast.CreateTableStmt{}, stmt[0]) 73 | assert.Equal(t, "create table db1.table1 (id number(10));", stmt[0].Text()) 74 | assert.IsType(t, &ast.AlterTableStmt{}, stmt[1]) 75 | assert.Equal(t, "alter table db1.table1 add (name varchar(255));", stmt[1].Text()) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/set/setmap.go: -------------------------------------------------------------------------------- 1 | package set 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | 7 | "github.com/timtadh/data-structures/errors" 8 | "github.com/timtadh/data-structures/types" 9 | ) 10 | 11 | type SetMap struct { 12 | types.Map 13 | } 14 | 15 | func NewSetMap(m types.Map) *SetMap { 16 | return &SetMap{m} 17 | } 18 | 19 | func (s *SetMap) String() string { 20 | if s.Size() <= 0 { 21 | return "{}" 22 | } 23 | items := make([]string, 0, s.Size()) 24 | for item, next := s.Items()(); next != nil; item, next = next() { 25 | items = append(items, fmt.Sprintf("%v", item)) 26 | } 27 | return "{" + strings.Join(items, ", ") + "}" 28 | } 29 | 30 | func (s *SetMap) Items() types.KIterator { 31 | return s.Keys() 32 | } 33 | 34 | // unimplemented 35 | func (s *SetMap) Item(item types.Hashable) (types.Hashable, error) { 36 | return nil, errors.Errorf("un-implemented") 37 | } 38 | 39 | // unimplemented 40 | func (s *SetMap) Equals(o types.Equatable) bool { 41 | panic(errors.Errorf("un-implemented")) 42 | } 43 | 44 | func (s *SetMap) Add(item types.Hashable) (err error) { 45 | return s.Put(item, nil) 46 | } 47 | 48 | func (s *SetMap) Delete(item types.Hashable) (err error) { 49 | _, err = s.Remove(item) 50 | return err 51 | } 52 | 53 | func (s *SetMap) Extend(items types.KIterator) (err error) { 54 | for item, next := items(); next != nil; item, next = next() { 55 | err := s.Add(item) 56 | if err != nil { 57 | return err 58 | } 59 | } 60 | return nil 61 | } 62 | 63 | // Unions s with o and returns a new SetMap (with a LinearHash) 64 | func (s *SetMap) Union(other types.Set) (types.Set, error) { 65 | return Union(s, other) 66 | } 67 | 68 | // Unions s with o and returns a new SetMap (with a LinearHash) 69 | func (s *SetMap) Intersect(other types.Set) (types.Set, error) { 70 | return Intersect(s, other) 71 | } 72 | 73 | // Unions s with o and returns a new SetMap (with a LinearHash) 74 | func (s *SetMap) Subtract(other types.Set) (types.Set, error) { 75 | return Subtract(s, other) 76 | } 77 | 78 | // Is s a subset of o? 79 | func (s *SetMap) Subset(o types.Set) bool { 80 | return Subset(s, o) 81 | } 82 | 83 | // Is s a proper subset of o? 84 | func (s *SetMap) ProperSubset(o types.Set) bool { 85 | return ProperSubset(s, o) 86 | } 87 | 88 | // Is s a superset of o? 89 | func (s *SetMap) Superset(o types.Set) bool { 90 | return Superset(s, o) 91 | } 92 | 93 | // Is s a proper superset of o? 94 | func (s *SetMap) ProperSuperset(o types.Set) bool { 95 | return ProperSuperset(s, o) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/LICENSE: -------------------------------------------------------------------------------- 1 | The data-structures library 2 | 3 | Copyright (C) 2013-2017 Tim Henderson (tim.tadh@gmail.com) 4 | Case Western Reserve University, Cleveland, Ohio 5 | Google Inc. 6 | 7 | This program is free software; you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation; either version 2 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License along 18 | with this program; if not, write to the Free Software Foundation, Inc., 19 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | 22 | 23 | Copyright (C) 2009 The Go Authors (for portions of rand/) 24 | This portion is used under the terms of the Go license: 25 | https://github.com/golang/go/blob/master/LICENSE 26 | (which is a BSD 3-clause license copied below) 27 | 28 | Redistribution and use in source and binary forms, with or without 29 | modification, are permitted provided that the following conditions 30 | are met: 31 | 32 | * Redistributions of source code must retain the above copyright 33 | notice, this list of conditions and the following disclaimer. 34 | * Redistributions in binary form must reproduce the above 35 | copyright notice, this list of conditions and the following 36 | disclaimer in the documentation and/or other materials provided with 37 | the distribution. 38 | * Neither the name of Google Inc. nor the names of its 39 | contributors may be used to endorse or promote products derived from 40 | this software without specific prior written permission. 41 | 42 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 43 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 44 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 45 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 46 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 47 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 48 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 49 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 50 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 51 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 52 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 53 | POSSIBILITY OF SUCH DAMAGE. 54 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/errors/errors.go: -------------------------------------------------------------------------------- 1 | package errors 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "runtime" 7 | "strings" 8 | ) 9 | 10 | var SkipLogging map[string]bool 11 | 12 | func init() { 13 | SkipLogging = make(map[string]bool, 10) 14 | } 15 | 16 | type Error struct { 17 | Errs []error 18 | Stack []byte 19 | } 20 | 21 | func Errorf(format string, args ...interface{}) error { 22 | buf := make([]byte, 50000) 23 | n := runtime.Stack(buf, true) 24 | trace := make([]byte, n) 25 | copy(trace, buf) 26 | return &Error{ 27 | Errs: []error{fmt.Errorf(format, args...)}, 28 | Stack: trace, 29 | } 30 | } 31 | 32 | func Logf(level, format string, args ...interface{}) { 33 | if SkipLogging[level] { 34 | return 35 | } 36 | pc, _, line, ok := runtime.Caller(1) 37 | if !ok { 38 | log.Printf(format, args) 39 | return 40 | } 41 | fn := runtime.FuncForPC(pc) 42 | msg := fmt.Sprintf(format, args...) 43 | log.Printf("%v (%v:%v): %v", level, fn.Name(), line, msg) 44 | } 45 | 46 | func (e *Error) Chain(err error) error { 47 | e.Errs = append(e.Errs, err) 48 | return e 49 | } 50 | 51 | func (e *Error) Error() string { 52 | if e == nil { 53 | return "Error " 54 | } else if len(e.Errs) == 0 { 55 | return fmt.Sprintf("%v\n%s", e.Errs, string(e.Stack)) 56 | } else if len(e.Errs) == 1 { 57 | return fmt.Sprintf("%v\n%s", e.Errs[0], string(e.Stack)) 58 | } else { 59 | errs := make([]string, 0, len(e.Errs)) 60 | for _, err := range e.Errs { 61 | errs = append(errs, err.Error()) 62 | } 63 | return fmt.Sprintf("{%v}\n%s", strings.Join(errs, ", "), string(e.Stack)) 64 | } 65 | } 66 | 67 | func (e *Error) String() string { 68 | return e.Error() 69 | } 70 | 71 | type ErrorFmter func(a ...interface{}) error 72 | 73 | func NotFound(a ...interface{}) error { 74 | // return fmt.Errorf("Key '%v' was not found.", a...) 75 | return Errorf("Key was not found.") 76 | } 77 | 78 | func NotFoundInBucket(a ...interface{}) error { 79 | return Errorf("Key, '%v', was not in bucket when expected.", a...) 80 | } 81 | 82 | func InvalidKey(a ...interface{}) error { 83 | return Errorf("Key, '%v', is invalid, %s", a...) 84 | } 85 | 86 | func TSTError(a ...interface{}) error { 87 | return Errorf("Internal TST error - "+a[0].(string), a[1:]...) 88 | } 89 | 90 | func NegativeSize(a ...interface{}) error { 91 | return Errorf("Negative size") 92 | } 93 | 94 | func BpTreeError(a ...interface{}) error { 95 | return Errorf("Internal B+ Tree error - "+a[0].(string), a[1:]...) 96 | } 97 | 98 | var Errors map[string]ErrorFmter = map[string]ErrorFmter{ 99 | "not-found": NotFound, 100 | "not-found-in-bucket": NotFoundInBucket, 101 | "invalid-key": InvalidKey, 102 | "tst-error": TSTError, 103 | "negative-size": NegativeSize, 104 | "bptree-error": BpTreeError, 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/linked/unique.go: -------------------------------------------------------------------------------- 1 | package linked 2 | 3 | import ( 4 | "github.com/timtadh/data-structures/hashtable" 5 | "github.com/timtadh/data-structures/list" 6 | "github.com/timtadh/data-structures/set" 7 | "github.com/timtadh/data-structures/types" 8 | ) 9 | 10 | type UniqueDeque struct { 11 | queue *LinkedList 12 | set types.Set 13 | } 14 | 15 | // A double ended queue that only allows unique items inside. Constructed from a 16 | // doubly linked list and a linear hash table. 17 | func NewUniqueDeque() *UniqueDeque { 18 | return &UniqueDeque{ 19 | queue: New(), 20 | set: set.NewSetMap(hashtable.NewLinearHash()), 21 | } 22 | } 23 | 24 | func (l *UniqueDeque) Size() int { 25 | return l.queue.Size() 26 | } 27 | 28 | func (l *UniqueDeque) Items() (it types.KIterator) { 29 | return l.queue.Items() 30 | } 31 | 32 | func (l *UniqueDeque) Backwards() (it types.KIterator) { 33 | return l.queue.Backwards() 34 | } 35 | 36 | func (l *UniqueDeque) Has(item types.Hashable) bool { 37 | return l.set.Has(item) 38 | } 39 | 40 | func (l *UniqueDeque) Push(item types.Hashable) (err error) { 41 | return l.EnqueBack(item) 42 | } 43 | 44 | func (l *UniqueDeque) Pop() (item types.Hashable, err error) { 45 | return l.DequeBack() 46 | } 47 | 48 | func (l *UniqueDeque) EnqueFront(item types.Hashable) (err error) { 49 | if l.Has(item) { 50 | return nil 51 | } 52 | err = l.queue.EnqueFront(item) 53 | if err != nil { 54 | return err 55 | } 56 | return l.set.Add(item) 57 | } 58 | 59 | func (l *UniqueDeque) EnqueBack(item types.Hashable) (err error) { 60 | if l.Has(item) { 61 | return nil 62 | } 63 | err = l.queue.EnqueBack(item) 64 | if err != nil { 65 | return err 66 | } 67 | return l.set.Add(item) 68 | } 69 | 70 | func (l *UniqueDeque) DequeFront() (item types.Hashable, err error) { 71 | item, err = l.queue.DequeFront() 72 | if err != nil { 73 | return nil, err 74 | } 75 | err = l.set.Delete(item) 76 | if err != nil { 77 | return nil, err 78 | } 79 | return item, nil 80 | } 81 | 82 | func (l *UniqueDeque) DequeBack() (item types.Hashable, err error) { 83 | item, err = l.queue.DequeBack() 84 | if err != nil { 85 | return nil, err 86 | } 87 | err = l.set.Delete(item) 88 | if err != nil { 89 | return nil, err 90 | } 91 | return item, nil 92 | } 93 | 94 | func (l *UniqueDeque) First() (item types.Hashable) { 95 | return l.queue.First() 96 | } 97 | 98 | func (l *UniqueDeque) Last() (item types.Hashable) { 99 | return l.queue.Last() 100 | } 101 | 102 | // Can be compared to any types.IterableContainer 103 | func (l *UniqueDeque) Equals(b types.Equatable) bool { 104 | return l.queue.Equals(b) 105 | } 106 | 107 | // Can be compared to any types.IterableContainer 108 | func (l *UniqueDeque) Less(b types.Sortable) bool { 109 | return l.queue.Less(b) 110 | } 111 | 112 | func (l *UniqueDeque) Hash() int { 113 | return list.Hash(l.queue) 114 | } 115 | 116 | func (l *UniqueDeque) String() string { 117 | return l.queue.String() 118 | } 119 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/tree/util.go: -------------------------------------------------------------------------------- 1 | package tree 2 | 3 | import ( 4 | "github.com/timtadh/data-structures/types" 5 | ) 6 | 7 | func pop(stack []types.TreeNode) ([]types.TreeNode, types.TreeNode) { 8 | if len(stack) <= 0 { 9 | return stack, nil 10 | } else { 11 | return stack[0 : len(stack)-1], stack[len(stack)-1] 12 | } 13 | } 14 | 15 | func btn_expose_nil(node types.BinaryTreeNode) types.BinaryTreeNode { 16 | if types.IsNil(node) { 17 | return nil 18 | } 19 | return node 20 | } 21 | 22 | func tn_expose_nil(node types.TreeNode) types.TreeNode { 23 | if types.IsNil(node) { 24 | return nil 25 | } 26 | return node 27 | } 28 | 29 | func TraverseBinaryTreeInOrder(node types.BinaryTreeNode) types.TreeNodeIterator { 30 | stack := make([]types.TreeNode, 0, 10) 31 | var cur types.TreeNode = btn_expose_nil(node) 32 | var tn_iterator types.TreeNodeIterator 33 | tn_iterator = func() (tn types.TreeNode, next types.TreeNodeIterator) { 34 | if len(stack) > 0 || cur != nil { 35 | for cur != nil { 36 | stack = append(stack, cur) 37 | cur = cur.(types.BinaryTreeNode).Left() 38 | } 39 | stack, cur = pop(stack) 40 | tn = cur 41 | cur = cur.(types.BinaryTreeNode).Right() 42 | return tn, tn_iterator 43 | } else { 44 | return nil, nil 45 | } 46 | } 47 | return tn_iterator 48 | } 49 | 50 | func TraverseTreePreOrder(node types.TreeNode) types.TreeNodeIterator { 51 | stack := append(make([]types.TreeNode, 0, 10), tn_expose_nil(node)) 52 | var tn_iterator types.TreeNodeIterator 53 | tn_iterator = func() (tn types.TreeNode, next types.TreeNodeIterator) { 54 | if len(stack) <= 0 { 55 | return nil, nil 56 | } 57 | stack, tn = pop(stack) 58 | kid_count := 1 59 | if tn.ChildCount() >= 0 { 60 | kid_count = tn.ChildCount() 61 | } 62 | kids := make([]types.TreeNode, 0, kid_count) 63 | for child, next := tn.Children()(); next != nil; child, next = next() { 64 | kids = append(kids, child) 65 | } 66 | for i := len(kids) - 1; i >= 0; i-- { 67 | stack = append(stack, kids[i]) 68 | } 69 | return tn, tn_iterator 70 | } 71 | return tn_iterator 72 | } 73 | 74 | func TraverseTreePostOrder(node types.TreeNode) types.TreeNodeIterator { 75 | type entry struct { 76 | tn types.TreeNode 77 | i int 78 | } 79 | 80 | pop := func(stack []entry) ([]entry, types.TreeNode, int) { 81 | if len(stack) <= 0 { 82 | return stack, nil, 0 83 | } else { 84 | e := stack[len(stack)-1] 85 | return stack[0 : len(stack)-1], e.tn, e.i 86 | } 87 | } 88 | 89 | stack := append(make([]entry, 0, 10), entry{tn_expose_nil(node), 0}) 90 | 91 | var tn_iterator types.TreeNodeIterator 92 | tn_iterator = func() (tn types.TreeNode, next types.TreeNodeIterator) { 93 | var i int 94 | 95 | if len(stack) <= 0 { 96 | return nil, nil 97 | } 98 | 99 | stack, tn, i = pop(stack) 100 | for i < tn.ChildCount() { 101 | kid := tn.GetChild(i) 102 | stack = append(stack, entry{tn, i + 1}) 103 | tn = kid 104 | i = 0 105 | } 106 | return tn, tn_iterator 107 | } 108 | return tn_iterator 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_order.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | // isOrdered checks that collection contains orderable elements. 9 | func isOrdered(t TestingT, object interface{}, allowedComparesResults []CompareType, failMessage string, msgAndArgs ...interface{}) bool { 10 | objKind := reflect.TypeOf(object).Kind() 11 | if objKind != reflect.Slice && objKind != reflect.Array { 12 | return false 13 | } 14 | 15 | objValue := reflect.ValueOf(object) 16 | objLen := objValue.Len() 17 | 18 | if objLen <= 1 { 19 | return true 20 | } 21 | 22 | value := objValue.Index(0) 23 | valueInterface := value.Interface() 24 | firstValueKind := value.Kind() 25 | 26 | for i := 1; i < objLen; i++ { 27 | prevValue := value 28 | prevValueInterface := valueInterface 29 | 30 | value = objValue.Index(i) 31 | valueInterface = value.Interface() 32 | 33 | compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind) 34 | 35 | if !isComparable { 36 | return Fail(t, fmt.Sprintf("Can not compare type \"%s\" and \"%s\"", reflect.TypeOf(value), reflect.TypeOf(prevValue)), msgAndArgs...) 37 | } 38 | 39 | if !containsValue(allowedComparesResults, compareResult) { 40 | return Fail(t, fmt.Sprintf(failMessage, prevValue, value), msgAndArgs...) 41 | } 42 | } 43 | 44 | return true 45 | } 46 | 47 | // IsIncreasing asserts that the collection is increasing 48 | // 49 | // assert.IsIncreasing(t, []int{1, 2, 3}) 50 | // assert.IsIncreasing(t, []float{1, 2}) 51 | // assert.IsIncreasing(t, []string{"a", "b"}) 52 | func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 53 | return isOrdered(t, object, []CompareType{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs) 54 | } 55 | 56 | // IsNonIncreasing asserts that the collection is not increasing 57 | // 58 | // assert.IsNonIncreasing(t, []int{2, 1, 1}) 59 | // assert.IsNonIncreasing(t, []float{2, 1}) 60 | // assert.IsNonIncreasing(t, []string{"b", "a"}) 61 | func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 62 | return isOrdered(t, object, []CompareType{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs) 63 | } 64 | 65 | // IsDecreasing asserts that the collection is decreasing 66 | // 67 | // assert.IsDecreasing(t, []int{2, 1, 0}) 68 | // assert.IsDecreasing(t, []float{2, 1}) 69 | // assert.IsDecreasing(t, []string{"b", "a"}) 70 | func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 71 | return isOrdered(t, object, []CompareType{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs) 72 | } 73 | 74 | // IsNonDecreasing asserts that the collection is not decreasing 75 | // 76 | // assert.IsNonDecreasing(t, []int{1, 1, 2}) 77 | // assert.IsNonDecreasing(t, []float{1, 2}) 78 | // assert.IsNonDecreasing(t, []string{"a", "b"}) 79 | func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 80 | return isOrdered(t, object, []CompareType{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs) 81 | } 82 | -------------------------------------------------------------------------------- /test/create_table.sql: -------------------------------------------------------------------------------- 1 | create table db1.table1 (id number(10));create table db1.table1 (id number(10), name varchar2(255)); 2 | 3 | CREATE TABLE "TEST"."T1" 4 | ( 5 | "ID" NUMBER(*,0) 6 | ) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING 7 | STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 8 | PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 9 | TABLESPACE "SYSTEM"; 10 | 11 | create table db1.table1 (id number(10) primary key); 12 | 13 | create table db1.table1 (id number(10), unique (id) enable); 14 | 15 | create table db1.table1 (id number(10), primary key (id) enable); 16 | 17 | create table db1.table1 (id number(10), CONSTRAINT pk primary key (id) enable); 18 | 19 | create table db1.table1 (id number(10), primary key (id) using index enable); 20 | 21 | create table db1.table1 (id number(10,3) primary key); 22 | 23 | CREATE TABLE test."persons" ( NUMERIC_NAME NUMERIC ( 15, 2 ), Decimal_NAME DECIMAL ( 15, 2 ), Dec_NAME DEC ( 15, 2 ), INTEGER_NAME INTEGER ); 24 | 25 | create table TEST.T21 (t CHAR(255)); 26 | 27 | create table TEST.T21 (t character(255)); 28 | 29 | CREATE TABLE TEST.INTERVAL_YEAR_COLUMNS(ID INT, C_INTERVAL_YEAR INTERVAL YEAR TO MONTH); 30 | 31 | CREATE TABLE TEST.INTERVAL_YEAR_COLUMNS(ID INT, C_INTERVAL_YEAR INTERVAL YEAR(3) TO MONTH); 32 | 33 | create table db1.table1 (primary varchar(255)); 34 | 35 | create table db1.table1 (id int, xml_data XMLTYPE); 36 | 37 | create table db1.table1 (id int unique not deferrable not null); 38 | 39 | create table db1.table1 (id int) organization heap no inmemory; 40 | 41 | create table db1.table1 (id int) organization heap inmemory no memcompress no duplicate; 42 | 43 | create table db1.table1 (id number(10), CONSTRAINT pk primary key (id) not deferrable initially deferred); 44 | 45 | create table db1.table1 (id number(10), CONSTRAINT pk primary key (id) initially deferred not deferrable); 46 | 47 | create table db1.table1 (id number(10) not null); 48 | 49 | create table db1.table1 (id number(10) not null unique); 50 | 51 | create table db1.table1 (id number(10) unique not null); 52 | 53 | create table db1.table1 (id number(10) unique not deferrable not null); 54 | 55 | create table db1.table1 (id number(10) unique not 56 | deferrable not null); 57 | 58 | create table db1.table1 (id number(10) unique not 59 | deferrable not null); 60 | 61 | create table db1.table1 (start_time timestamp(5)); 62 | 63 | CREATE TABLE sbtest1 ( 64 | id INTEGER NOT NULL, 65 | k INTEGER, 66 | c CHAR(120) DEFAULT '' NOT NULL, 67 | pad CHAR(60) DEFAULT '' NOT NULL, 68 | PRIMARY KEY (id) 69 | ); 70 | 71 | create table db1.table_1 (id_1 int); 72 | create table db1.table#1 (id#1 int); 73 | create table db1.table$1 (id$1 int); 74 | create table db1.table$#_1 (id$1_ int); 75 | 76 | create table db1.table1 (ts TIMESTAMP); 77 | create table db1.table1 (ts TIMESTAMP(6)); 78 | create table db1.table1 (ts TIMESTAMP WITH TIME ZONE); 79 | create table db1.table1 (ts TIMESTAMP WITH LOCAL TIME ZONE); 80 | create table db1.table1 (ts TIMESTAMP(6) WITH TIME ZONE); 81 | create table db1.table1 (ts TIMESTAMP(6) WITH LOCAL TIME ZONE); -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/hashtable/linhash.go: -------------------------------------------------------------------------------- 1 | package hashtable 2 | 3 | import ( 4 | "github.com/timtadh/data-structures/tree/avl" 5 | . "github.com/timtadh/data-structures/types" 6 | ) 7 | 8 | const ( 9 | UTILIZATION = .75 10 | RECORDS_PER_BLOCK = 16 11 | ) 12 | 13 | type bst struct { 14 | hash int 15 | key Hashable 16 | value interface{} 17 | left *bst 18 | right *bst 19 | } 20 | 21 | type LinearHash struct { 22 | table []*avl.AvlNode 23 | n uint 24 | r uint 25 | i uint 26 | } 27 | 28 | func NewLinearHash() *LinearHash { 29 | N := uint(32) 30 | I := uint(5) 31 | return &LinearHash{ 32 | table: make([]*avl.AvlNode, N), 33 | n: N, 34 | r: 0, 35 | i: I, 36 | } 37 | } 38 | 39 | func (self *LinearHash) bucket(key Hashable) uint { 40 | m := uint(key.Hash() & ((1 << self.i) - 1)) 41 | if m < self.n { 42 | return m 43 | } else { 44 | return m ^ (1 << (self.i - 1)) 45 | } 46 | } 47 | 48 | func (self *LinearHash) Size() int { 49 | return int(self.r) 50 | } 51 | 52 | func (self *LinearHash) Put(key Hashable, value interface{}) (err error) { 53 | var updated bool 54 | bkt_idx := self.bucket(key) 55 | self.table[bkt_idx], updated = self.table[bkt_idx].Put(key, value) 56 | if !updated { 57 | self.r += 1 58 | } 59 | if float64(self.r) > UTILIZATION*float64(self.n)*float64(RECORDS_PER_BLOCK) { 60 | return self.split() 61 | } 62 | return nil 63 | } 64 | 65 | func (self *LinearHash) Get(key Hashable) (value interface{}, err error) { 66 | bkt_idx := self.bucket(key) 67 | return self.table[bkt_idx].Get(key) 68 | } 69 | 70 | func (self *LinearHash) Has(key Hashable) bool { 71 | bkt_idx := self.bucket(key) 72 | return self.table[bkt_idx].Has(key) 73 | } 74 | 75 | func (self *LinearHash) Remove(key Hashable) (value interface{}, err error) { 76 | bkt_idx := self.bucket(key) 77 | self.table[bkt_idx], value, err = self.table[bkt_idx].Remove(key) 78 | if err == nil { 79 | self.r -= 1 80 | } 81 | return 82 | } 83 | 84 | func (self *LinearHash) split() (err error) { 85 | bkt_idx := self.n % (1 << (self.i - 1)) 86 | old_bkt := self.table[bkt_idx] 87 | var bkt_a, bkt_b *avl.AvlNode 88 | self.n += 1 89 | if self.n > (1 << self.i) { 90 | self.i += 1 91 | } 92 | for key, value, next := old_bkt.Iterate()(); next != nil; key, value, next = next() { 93 | if self.bucket(key.(Hashable)) == bkt_idx { 94 | bkt_a, _ = bkt_a.Put(key.(Hashable), value) 95 | } else { 96 | bkt_b, _ = bkt_b.Put(key.(Hashable), value) 97 | } 98 | } 99 | self.table[bkt_idx] = bkt_a 100 | self.table = append(self.table, bkt_b) 101 | return nil 102 | } 103 | 104 | func (self *LinearHash) Iterate() KVIterator { 105 | table := self.table 106 | i := 0 107 | iter := table[i].Iterate() 108 | var kv_iterator KVIterator 109 | kv_iterator = func() (key Hashable, val interface{}, next KVIterator) { 110 | key, val, iter = iter() 111 | for iter == nil { 112 | i++ 113 | if i >= len(table) { 114 | return nil, nil, nil 115 | } 116 | key, val, iter = table[i].Iterate()() 117 | } 118 | return key, val, kv_iterator 119 | } 120 | return kv_iterator 121 | } 122 | 123 | func (self *LinearHash) Items() (vi KIterator) { 124 | return MakeItemsIterator(self) 125 | } 126 | 127 | func (self *LinearHash) Keys() KIterator { 128 | return MakeKeysIterator(self) 129 | } 130 | 131 | func (self *LinearHash) Values() Iterator { 132 | return MakeValuesIterator(self) 133 | } 134 | -------------------------------------------------------------------------------- /ast/ddl.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import ( 4 | "github.com/sjjian/oracle-sql-parser/ast/element" 5 | ) 6 | 7 | /* 8 | Alter Table Statement 9 | see: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/ALTER-TABLE.html#GUID-552E7373-BF93-477D-9DA3-B2C9386F2877 10 | */ 11 | 12 | type AlterTableStmt struct { 13 | node 14 | TableName *TableName 15 | AlterTableClauses []AlterTableClause 16 | } 17 | 18 | type AlterTableClause interface { 19 | IsAlterTableClause() 20 | } 21 | 22 | type alterTableClause struct{} 23 | 24 | func (c *alterTableClause) IsAlterTableClause() {} 25 | 26 | type AddColumnClause struct { 27 | alterTableClause 28 | Columns []*ColumnDef 29 | } 30 | 31 | type ModifyColumnClause struct { 32 | alterTableClause 33 | Columns []*ColumnDef 34 | } 35 | 36 | type DropColumnClause struct { 37 | alterTableClause 38 | Type DropColumnType 39 | Columns []*element.Identifier 40 | Props []DropColumnProp 41 | CheckPoint *int 42 | } 43 | 44 | type RenameColumnClause struct { 45 | alterTableClause 46 | OldName *element.Identifier 47 | NewName *element.Identifier 48 | } 49 | 50 | type AddConstraintClause struct { 51 | alterTableClause 52 | Constraints []*OutOfLineConstraint 53 | } 54 | 55 | type ModifyConstraintClause struct { 56 | alterTableClause 57 | Constraint *OutOfLineConstraint 58 | } 59 | 60 | type RenameConstraintClause struct { 61 | alterTableClause 62 | OldName *element.Identifier 63 | NewName *element.Identifier 64 | } 65 | 66 | type DropConstraintClause struct { 67 | alterTableClause 68 | Constraint *OutOfLineConstraint 69 | } 70 | 71 | /* 72 | Create Table Statement 73 | see: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-TABLE.html#GUID-F9CE0CC3-13AE-4744-A43C-EAC7A71AAAB6 74 | */ 75 | 76 | type CreateTableStmt struct { 77 | node 78 | TableName *TableName 79 | RelTable *RelTableDef 80 | } 81 | 82 | type RelTableDef struct { 83 | TableStructs []TableStructDef 84 | } 85 | 86 | type TableStructDef interface { 87 | IsTableStructDef() 88 | } 89 | 90 | type tableStructDef struct{} 91 | 92 | func (c *tableStructDef) IsTableStructDef() {} 93 | 94 | type ColumnDef struct { 95 | tableStructDef 96 | ColumnName *element.Identifier 97 | Datatype element.Datatype 98 | Collation *Collation 99 | Props []ColumnProp 100 | Default *ColumnDefault 101 | Constraints []*InlineConstraint 102 | } 103 | 104 | type InlineConstraint struct { 105 | Name *element.Identifier 106 | Type ConstraintType 107 | } 108 | 109 | type OutOfLineConstraint struct { 110 | tableStructDef 111 | InlineConstraint 112 | Columns []*element.Identifier 113 | } 114 | 115 | /* 116 | Create Index Statement 117 | see: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-INDEX.html#GUID-1F89BBC0-825F-4215-AF71-7588E31D8BFE 118 | */ 119 | 120 | type CreateIndexStmt struct { 121 | node 122 | } 123 | 124 | /* 125 | Drop Table Statement 126 | see: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-INDEX.html#GUID-1F89BBC0-825F-4215-AF71-7588E31D8BFE 127 | */ 128 | type DropTableStmt struct { 129 | node 130 | TableName *TableName 131 | } 132 | 133 | /* 134 | Drop Index Statement 135 | see: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/DROP-INDEX.html#GUID-F60F75DF-2866-4F93-BB7F-8FCE64BF67B6 136 | */ 137 | type DropIndexStmt struct { 138 | node 139 | IndexName *IndexName 140 | } 141 | -------------------------------------------------------------------------------- /ast/element/datatype.go: -------------------------------------------------------------------------------- 1 | package element 2 | 3 | type Datatype interface { 4 | DataDef() DataDef 5 | } 6 | 7 | type DataDef int 8 | 9 | const ( 10 | DataDefChar DataDef = iota 11 | DataDefVarchar2 12 | DataDefNChar 13 | DataDefNVarChar2 14 | DataDefNumber 15 | DataDefFloat 16 | DataDefBinaryFloat 17 | DataDefBinaryDouble 18 | DataDefLong 19 | DataDefLongRaw 20 | DataDefRaw 21 | DataDefDate 22 | DataDefTimestamp 23 | DataDefIntervalYear 24 | DataDefIntervalDay 25 | DataDefBlob 26 | DataDefClob 27 | DataDefNClob 28 | DataDefBFile 29 | DataDefRowId 30 | DataDefURowId 31 | DataDefCharacter 32 | DataDefCharacterVarying 33 | DataDefCharVarying 34 | DataDefNCharVarying 35 | DataDefVarchar 36 | DataDefNationalCharacter 37 | DataDefNationalCharacterVarying 38 | DataDefNationalChar 39 | DataDefNationalCharVarying 40 | DataDefNumeric 41 | DataDefDecimal 42 | DataDefDec 43 | DataDefInteger 44 | DataDefInt 45 | DataDefSmallInt 46 | DataDefDoublePrecision 47 | DataDefReal 48 | DataDefXMLType 49 | ) 50 | 51 | type datatype struct { 52 | typ DataDef 53 | } 54 | 55 | func (d *datatype) DataDef () DataDef { 56 | return d.typ 57 | } 58 | 59 | func (d *datatype) SetDataDef(typ DataDef) { 60 | d.typ = typ 61 | } 62 | 63 | // Char is "Char" and "Character" 64 | type Char struct { 65 | datatype 66 | Size *int 67 | IsByteSize bool 68 | IsCharSize bool 69 | } 70 | 71 | // Varchar2 include: "Varchar2", "Char Varying", "Character Varying", "Varchar" 72 | type Varchar2 struct { 73 | Char 74 | } 75 | 76 | // NChar include: "Nchar", "National Character", "National Char". 77 | type NChar struct { 78 | datatype 79 | Size *int 80 | } 81 | 82 | // NVarchar2 include: "NVarchar2", "National Character Varying", "National Char Varying", "NChar Varying" 83 | type NVarchar2 struct { 84 | NChar 85 | } 86 | 87 | type Raw struct { 88 | datatype 89 | Size *int 90 | } 91 | 92 | type RowId struct { 93 | datatype 94 | } 95 | 96 | type URowId struct { 97 | datatype 98 | Size *int 99 | } 100 | 101 | type Date struct { 102 | datatype 103 | } 104 | 105 | type Timestamp struct { 106 | datatype 107 | FractionalSecondsPrecision *int 108 | WithTimeZone bool 109 | WithLocalTimeZone bool 110 | } 111 | 112 | type IntervalYear struct { 113 | datatype 114 | Precision *int 115 | } 116 | 117 | type IntervalDay struct { 118 | datatype 119 | Precision *int 120 | FractionalSecondsPrecision *int 121 | } 122 | 123 | // Number include: "Number", "Numeric", "Decimal", "Dec", "Integer", "Int", "Smallint"; 124 | // Integer is a alias of Number(38); 125 | // Int is a alias of Number(38); 126 | // Smallint is a alias of Number(38) 127 | type Number struct { 128 | datatype 129 | Precision *NumberOrAsterisk 130 | Scale *int 131 | } 132 | 133 | // Float is a subtype of Number, include: "Float", "", "DoublePrecision", "Real"; 134 | // DoublePrecision is a alias of FLOAT(126); 135 | // Real is a alias of FLOAT(63). 136 | type Float struct { 137 | datatype 138 | Precision *NumberOrAsterisk 139 | } 140 | 141 | type BinaryFloat struct { 142 | datatype 143 | } 144 | 145 | type BinaryDouble struct { 146 | datatype 147 | } 148 | 149 | type Long struct { 150 | datatype 151 | } 152 | 153 | type LongRaw struct { 154 | datatype 155 | } 156 | 157 | type Blob struct { 158 | datatype 159 | } 160 | 161 | type Clob struct { 162 | datatype 163 | } 164 | 165 | type NClob struct { 166 | datatype 167 | } 168 | 169 | type BFile struct { 170 | datatype 171 | } 172 | 173 | type XMLType struct { 174 | datatype 175 | } -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/frontend/gen.go: -------------------------------------------------------------------------------- 1 | package frontend 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | import ( 8 | "github.com/timtadh/lexmachine/inst" 9 | ) 10 | 11 | type generator struct { 12 | program inst.Slice 13 | } 14 | 15 | // Generate an NFA program from the AST for a regular expression. 16 | func Generate(ast AST) (inst.Slice, error) { 17 | g := &generator{ 18 | program: make([]*inst.Inst, 0, 100), 19 | } 20 | fill := g.gen(ast) 21 | if len(fill) != 0 { 22 | return nil, fmt.Errorf("unconnected instructions") 23 | } 24 | return g.program, nil 25 | } 26 | 27 | func (g *generator) gen(ast AST) (fill []*uint32) { 28 | switch n := ast.(type) { 29 | case *AltMatch: 30 | fill = g.altMatch(n) 31 | case *Match: 32 | fill = g.match(n) 33 | case *Alternation: 34 | fill = g.alt(n) 35 | case *Star: 36 | fill = g.star(n) 37 | case *Plus: 38 | fill = g.plus(n) 39 | case *Maybe: 40 | fill = g.maybe(n) 41 | case *Concat: 42 | fill = g.concat(n) 43 | case *Character: 44 | fill = g.character(n) 45 | case *Range: 46 | fill = g.rangeGen(n) 47 | } 48 | return fill 49 | } 50 | 51 | func (g *generator) dofill(fill []*uint32) { 52 | for _, jmp := range fill { 53 | *jmp = uint32(len(g.program)) 54 | } 55 | } 56 | 57 | func (g *generator) altMatch(a *AltMatch) []*uint32 { 58 | split := inst.New(inst.SPLIT, 0, 0) 59 | g.program = append(g.program, split) 60 | split.X = uint32(len(g.program)) 61 | g.gen(a.A) 62 | split.Y = uint32(len(g.program)) 63 | g.gen(a.B) 64 | return nil 65 | } 66 | 67 | func (g *generator) match(m *Match) []*uint32 { 68 | g.dofill(g.gen(m.AST)) 69 | g.program = append( 70 | g.program, inst.New(inst.MATCH, 0, 0)) 71 | return nil 72 | } 73 | 74 | func (g *generator) alt(a *Alternation) (fill []*uint32) { 75 | split := inst.New(inst.SPLIT, 0, 0) 76 | g.program = append(g.program, split) 77 | split.X = uint32(len(g.program)) 78 | g.dofill(g.gen(a.A)) 79 | jmp := inst.New(inst.JMP, 0, 0) 80 | g.program = append(g.program, jmp) 81 | split.Y = uint32(len(g.program)) 82 | fill = g.gen(a.B) 83 | fill = append(fill, &jmp.X) 84 | return fill 85 | } 86 | 87 | func (g *generator) repeat(ast AST) (fill []*uint32) { 88 | split := inst.New(inst.SPLIT, 0, 0) 89 | splitPos := uint32(len(g.program)) 90 | g.program = append(g.program, split) 91 | split.X = uint32(len(g.program)) 92 | g.dofill(g.gen(ast)) 93 | jmp := inst.New(inst.JMP, splitPos, 0) 94 | g.program = append(g.program, jmp) 95 | return []*uint32{&split.Y} 96 | } 97 | 98 | func (g *generator) star(s *Star) (fill []*uint32) { 99 | return g.repeat(s.AST) 100 | } 101 | 102 | func (g *generator) plus(p *Plus) (fill []*uint32) { 103 | g.dofill(g.gen(p.AST)) 104 | return g.repeat(p.AST) 105 | } 106 | 107 | func (g *generator) maybe(m *Maybe) (fill []*uint32) { 108 | split := inst.New(inst.SPLIT, 0, 0) 109 | g.program = append(g.program, split) 110 | split.X = uint32(len(g.program)) 111 | fill = g.gen(m.AST) 112 | fill = append(fill, &split.Y) 113 | return fill 114 | } 115 | 116 | func (g *generator) concat(c *Concat) (fill []*uint32) { 117 | for _, ast := range c.Items { 118 | g.dofill(fill) 119 | fill = g.gen(ast) 120 | } 121 | return fill 122 | } 123 | 124 | func (g *generator) character(ch *Character) []*uint32 { 125 | g.program = append( 126 | g.program, 127 | inst.New(inst.CHAR, uint32(ch.Char), uint32(ch.Char))) 128 | return nil 129 | } 130 | 131 | func (g *generator) rangeGen(r *Range) []*uint32 { 132 | g.program = append( 133 | g.program, 134 | inst.New(inst.CHAR, uint32(r.From), uint32(r.To))) 135 | return nil 136 | } 137 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/hashtable/hashtable.go: -------------------------------------------------------------------------------- 1 | package hashtable 2 | 3 | import . "github.com/timtadh/data-structures/types" 4 | import . "github.com/timtadh/data-structures/errors" 5 | 6 | type entry struct { 7 | key Hashable 8 | value interface{} 9 | next *entry 10 | } 11 | 12 | type Hash struct { 13 | table []*entry 14 | size int 15 | } 16 | 17 | func (self *entry) Put(key Hashable, value interface{}) (e *entry, appended bool) { 18 | if self == nil { 19 | return &entry{key, value, nil}, true 20 | } 21 | if self.key.Equals(key) { 22 | self.value = value 23 | return self, false 24 | } else { 25 | self.next, appended = self.next.Put(key, value) 26 | return self, appended 27 | } 28 | } 29 | 30 | func (self *entry) Get(key Hashable) (has bool, value interface{}) { 31 | if self == nil { 32 | return false, nil 33 | } else if self.key.Equals(key) { 34 | return true, self.value 35 | } else { 36 | return self.next.Get(key) 37 | } 38 | } 39 | 40 | func (self *entry) Remove(key Hashable) *entry { 41 | if self == nil { 42 | panic(Errors["not-found-in-bucket"](key)) 43 | } 44 | if self.key.Equals(key) { 45 | return self.next 46 | } else { 47 | self.next = self.next.Remove(key) 48 | return self 49 | } 50 | } 51 | 52 | func NewHashTable(initial_size int) *Hash { 53 | return &Hash{ 54 | table: make([]*entry, initial_size), 55 | size: 0, 56 | } 57 | } 58 | 59 | func (self *Hash) bucket(key Hashable) int { 60 | return key.Hash() % len(self.table) 61 | } 62 | 63 | func (self *Hash) Size() int { return self.size } 64 | 65 | func (self *Hash) Put(key Hashable, value interface{}) (err error) { 66 | bucket := self.bucket(key) 67 | var appended bool 68 | self.table[bucket], appended = self.table[bucket].Put(key, value) 69 | if appended { 70 | self.size += 1 71 | } 72 | if self.size*2 > len(self.table) { 73 | return self.expand() 74 | } 75 | return nil 76 | } 77 | 78 | func (self *Hash) expand() error { 79 | table := self.table 80 | self.table = make([]*entry, len(table)*2) 81 | self.size = 0 82 | for _, E := range table { 83 | for e := E; e != nil; e = e.next { 84 | if err := self.Put(e.key, e.value); err != nil { 85 | return err 86 | } 87 | } 88 | } 89 | return nil 90 | } 91 | 92 | func (self *Hash) Get(key Hashable) (value interface{}, err error) { 93 | bucket := self.bucket(key) 94 | if has, value := self.table[bucket].Get(key); has { 95 | return value, nil 96 | } else { 97 | return nil, Errors["not-found"](key) 98 | } 99 | } 100 | 101 | func (self *Hash) Has(key Hashable) (has bool) { 102 | has, _ = self.table[self.bucket(key)].Get(key) 103 | return 104 | } 105 | 106 | func (self *Hash) Remove(key Hashable) (value interface{}, err error) { 107 | bucket := self.bucket(key) 108 | has, value := self.table[bucket].Get(key) 109 | if !has { 110 | return nil, Errors["not-found"](key) 111 | } 112 | self.table[bucket] = self.table[bucket].Remove(key) 113 | self.size -= 1 114 | return value, nil 115 | } 116 | 117 | func (self *Hash) Iterate() KVIterator { 118 | table := self.table 119 | i := -1 120 | var e *entry 121 | var kv_iterator KVIterator 122 | kv_iterator = func() (key Hashable, val interface{}, next KVIterator) { 123 | for e == nil { 124 | i++ 125 | if i >= len(table) { 126 | return nil, nil, nil 127 | } 128 | e = table[i] 129 | } 130 | key = e.key 131 | val = e.value 132 | e = e.next 133 | return key, val, kv_iterator 134 | } 135 | return kv_iterator 136 | } 137 | 138 | func (self *Hash) Items() (vi KIterator) { 139 | return MakeItemsIterator(self) 140 | } 141 | 142 | func (self *Hash) Keys() KIterator { 143 | return MakeKeysIterator(self) 144 | } 145 | 146 | func (self *Hash) Values() Iterator { 147 | return MakeValuesIterator(self) 148 | } 149 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/sorter.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011-2019 Canonical Ltd 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package yaml 17 | 18 | import ( 19 | "reflect" 20 | "unicode" 21 | ) 22 | 23 | type keyList []reflect.Value 24 | 25 | func (l keyList) Len() int { return len(l) } 26 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 27 | func (l keyList) Less(i, j int) bool { 28 | a := l[i] 29 | b := l[j] 30 | ak := a.Kind() 31 | bk := b.Kind() 32 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 33 | a = a.Elem() 34 | ak = a.Kind() 35 | } 36 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 37 | b = b.Elem() 38 | bk = b.Kind() 39 | } 40 | af, aok := keyFloat(a) 41 | bf, bok := keyFloat(b) 42 | if aok && bok { 43 | if af != bf { 44 | return af < bf 45 | } 46 | if ak != bk { 47 | return ak < bk 48 | } 49 | return numLess(a, b) 50 | } 51 | if ak != reflect.String || bk != reflect.String { 52 | return ak < bk 53 | } 54 | ar, br := []rune(a.String()), []rune(b.String()) 55 | digits := false 56 | for i := 0; i < len(ar) && i < len(br); i++ { 57 | if ar[i] == br[i] { 58 | digits = unicode.IsDigit(ar[i]) 59 | continue 60 | } 61 | al := unicode.IsLetter(ar[i]) 62 | bl := unicode.IsLetter(br[i]) 63 | if al && bl { 64 | return ar[i] < br[i] 65 | } 66 | if al || bl { 67 | if digits { 68 | return al 69 | } else { 70 | return bl 71 | } 72 | } 73 | var ai, bi int 74 | var an, bn int64 75 | if ar[i] == '0' || br[i] == '0' { 76 | for j := i - 1; j >= 0 && unicode.IsDigit(ar[j]); j-- { 77 | if ar[j] != '0' { 78 | an = 1 79 | bn = 1 80 | break 81 | } 82 | } 83 | } 84 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 85 | an = an*10 + int64(ar[ai]-'0') 86 | } 87 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 88 | bn = bn*10 + int64(br[bi]-'0') 89 | } 90 | if an != bn { 91 | return an < bn 92 | } 93 | if ai != bi { 94 | return ai < bi 95 | } 96 | return ar[i] < br[i] 97 | } 98 | return len(ar) < len(br) 99 | } 100 | 101 | // keyFloat returns a float value for v if it is a number/bool 102 | // and whether it is a number/bool or not. 103 | func keyFloat(v reflect.Value) (f float64, ok bool) { 104 | switch v.Kind() { 105 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 106 | return float64(v.Int()), true 107 | case reflect.Float32, reflect.Float64: 108 | return v.Float(), true 109 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 110 | return float64(v.Uint()), true 111 | case reflect.Bool: 112 | if v.Bool() { 113 | return 1, true 114 | } 115 | return 0, true 116 | } 117 | return 0, false 118 | } 119 | 120 | // numLess returns whether a < b. 121 | // a and b must necessarily have the same kind. 122 | func numLess(a, b reflect.Value) bool { 123 | switch a.Kind() { 124 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 125 | return a.Int() < b.Int() 126 | case reflect.Float32, reflect.Float64: 127 | return a.Float() < b.Float() 128 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 129 | return a.Uint() < b.Uint() 130 | case reflect.Bool: 131 | return !a.Bool() && b.Bool() 132 | } 133 | panic("not a number") 134 | } 135 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/README.md: -------------------------------------------------------------------------------- 1 | # YAML support for the Go language 2 | 3 | Introduction 4 | ------------ 5 | 6 | The yaml package enables Go programs to comfortably encode and decode YAML 7 | values. It was developed within [Canonical](https://www.canonical.com) as 8 | part of the [juju](https://juju.ubuntu.com) project, and is based on a 9 | pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) 10 | C library to parse and generate YAML data quickly and reliably. 11 | 12 | Compatibility 13 | ------------- 14 | 15 | The yaml package supports most of YAML 1.2, but preserves some behavior 16 | from 1.1 for backwards compatibility. 17 | 18 | Specifically, as of v3 of the yaml package: 19 | 20 | - YAML 1.1 bools (_yes/no, on/off_) are supported as long as they are being 21 | decoded into a typed bool value. Otherwise they behave as a string. Booleans 22 | in YAML 1.2 are _true/false_ only. 23 | - Octals encode and decode as _0777_ per YAML 1.1, rather than _0o777_ 24 | as specified in YAML 1.2, because most parsers still use the old format. 25 | Octals in the _0o777_ format are supported though, so new files work. 26 | - Does not support base-60 floats. These are gone from YAML 1.2, and were 27 | actually never supported by this package as it's clearly a poor choice. 28 | 29 | and offers backwards 30 | compatibility with YAML 1.1 in some cases. 31 | 1.2, including support for 32 | anchors, tags, map merging, etc. Multi-document unmarshalling is not yet 33 | implemented, and base-60 floats from YAML 1.1 are purposefully not 34 | supported since they're a poor design and are gone in YAML 1.2. 35 | 36 | Installation and usage 37 | ---------------------- 38 | 39 | The import path for the package is *gopkg.in/yaml.v3*. 40 | 41 | To install it, run: 42 | 43 | go get gopkg.in/yaml.v3 44 | 45 | API documentation 46 | ----------------- 47 | 48 | If opened in a browser, the import path itself leads to the API documentation: 49 | 50 | - [https://gopkg.in/yaml.v3](https://gopkg.in/yaml.v3) 51 | 52 | API stability 53 | ------------- 54 | 55 | The package API for yaml v3 will remain stable as described in [gopkg.in](https://gopkg.in). 56 | 57 | 58 | License 59 | ------- 60 | 61 | The yaml package is licensed under the MIT and Apache License 2.0 licenses. 62 | Please see the LICENSE file for details. 63 | 64 | 65 | Example 66 | ------- 67 | 68 | ```Go 69 | package main 70 | 71 | import ( 72 | "fmt" 73 | "log" 74 | 75 | "gopkg.in/yaml.v3" 76 | ) 77 | 78 | var data = ` 79 | a: Easy! 80 | b: 81 | c: 2 82 | d: [3, 4] 83 | ` 84 | 85 | // Note: struct fields must be public in order for unmarshal to 86 | // correctly populate the data. 87 | type T struct { 88 | A string 89 | B struct { 90 | RenamedC int `yaml:"c"` 91 | D []int `yaml:",flow"` 92 | } 93 | } 94 | 95 | func main() { 96 | t := T{} 97 | 98 | err := yaml.Unmarshal([]byte(data), &t) 99 | if err != nil { 100 | log.Fatalf("error: %v", err) 101 | } 102 | fmt.Printf("--- t:\n%v\n\n", t) 103 | 104 | d, err := yaml.Marshal(&t) 105 | if err != nil { 106 | log.Fatalf("error: %v", err) 107 | } 108 | fmt.Printf("--- t dump:\n%s\n\n", string(d)) 109 | 110 | m := make(map[interface{}]interface{}) 111 | 112 | err = yaml.Unmarshal([]byte(data), &m) 113 | if err != nil { 114 | log.Fatalf("error: %v", err) 115 | } 116 | fmt.Printf("--- m:\n%v\n\n", m) 117 | 118 | d, err = yaml.Marshal(&m) 119 | if err != nil { 120 | log.Fatalf("error: %v", err) 121 | } 122 | fmt.Printf("--- m dump:\n%s\n\n", string(d)) 123 | } 124 | ``` 125 | 126 | This example will generate the following output: 127 | 128 | ``` 129 | --- t: 130 | {Easy! {2 [3 4]}} 131 | 132 | --- t dump: 133 | a: Easy! 134 | b: 135 | c: 2 136 | d: [3, 4] 137 | 138 | 139 | --- m: 140 | map[a:Easy! b:map[c:2 d:[3 4]]] 141 | 142 | --- m dump: 143 | a: Easy! 144 | b: 145 | c: 2 146 | d: 147 | - 3 148 | - 4 149 | ``` 150 | 151 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/set/mapset.go: -------------------------------------------------------------------------------- 1 | package set 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | import ( 8 | "github.com/timtadh/data-structures/errors" 9 | "github.com/timtadh/data-structures/types" 10 | ) 11 | 12 | type MapSet struct { 13 | Set types.Set 14 | } 15 | 16 | func mapEntry(item types.Hashable) (*types.MapEntry, error) { 17 | if me, ok := item.(*types.MapEntry); ok { 18 | return me, nil 19 | } else { 20 | return nil, errors.Errorf("Must pass a *types.MapEntry, got %T", item) 21 | } 22 | } 23 | 24 | func asMapEntry(item types.Hashable) *types.MapEntry { 25 | if me, ok := item.(*types.MapEntry); ok { 26 | return me 27 | } else { 28 | return &types.MapEntry{item, nil} 29 | } 30 | } 31 | 32 | func NewMapSet(set types.Set) *MapSet { 33 | return &MapSet{set} 34 | } 35 | 36 | func (m *MapSet) Equals(b types.Equatable) bool { 37 | if o, ok := b.(*MapSet); ok { 38 | return m.Set.Equals(o.Set) 39 | } else { 40 | return false 41 | } 42 | } 43 | 44 | func (m *MapSet) Size() int { 45 | return m.Set.Size() 46 | } 47 | 48 | func (m *MapSet) Keys() types.KIterator { 49 | return types.MakeKeysIterator(m) 50 | } 51 | 52 | func (m *MapSet) Values() types.Iterator { 53 | return types.MakeValuesIterator(m) 54 | } 55 | 56 | func (m *MapSet) Iterate() (kvit types.KVIterator) { 57 | items := m.Items() 58 | kvit = func() (key types.Hashable, value interface{}, _ types.KVIterator) { 59 | var item types.Hashable 60 | item, items = items() 61 | if items == nil { 62 | return nil, nil, nil 63 | } 64 | me := item.(*types.MapEntry) 65 | return me.Key, me.Value, kvit 66 | } 67 | return kvit 68 | } 69 | 70 | func (m *MapSet) Items() types.KIterator { 71 | return m.Set.Items() 72 | } 73 | 74 | func (m *MapSet) Has(key types.Hashable) bool { 75 | return m.Set.Has(asMapEntry(key)) 76 | } 77 | 78 | func (m *MapSet) Add(item types.Hashable) (err error) { 79 | me, err := mapEntry(item) 80 | if err != nil { 81 | return err 82 | } 83 | return m.Set.Add(me) 84 | } 85 | 86 | func (m *MapSet) Put(key types.Hashable, value interface{}) (err error) { 87 | return m.Add(&types.MapEntry{key, value}) 88 | } 89 | 90 | func (m *MapSet) Get(key types.Hashable) (value interface{}, err error) { 91 | item, err := m.Set.Item(asMapEntry(key)) 92 | if err != nil { 93 | return nil, err 94 | } 95 | me, err := mapEntry(item) 96 | if err != nil { 97 | return nil, err 98 | } 99 | return me.Value, nil 100 | } 101 | 102 | func (m *MapSet) Item(key types.Hashable) (me types.Hashable, err error) { 103 | item, err := m.Set.Item(asMapEntry(key)) 104 | if err != nil { 105 | return nil, err 106 | } 107 | me, err = mapEntry(item) 108 | if err != nil { 109 | return nil, err 110 | } 111 | return me, nil 112 | } 113 | 114 | func (m *MapSet) Remove(key types.Hashable) (value interface{}, err error) { 115 | item, err := m.Get(asMapEntry(key)) 116 | if err != nil { 117 | return nil, err 118 | } 119 | err = m.Delete(key) 120 | if err != nil { 121 | return nil, err 122 | } 123 | return item, nil 124 | } 125 | 126 | func (m *MapSet) Delete(item types.Hashable) (err error) { 127 | return m.Set.Delete(asMapEntry(item)) 128 | } 129 | 130 | func (m *MapSet) Extend(items types.KIterator) (err error) { 131 | for item, items := items(); items != nil; item, items = items() { 132 | err := m.Add(item) 133 | if err != nil { 134 | return err 135 | } 136 | } 137 | return nil 138 | } 139 | 140 | func (m *MapSet) Union(b types.Set) (types.Set, error) { 141 | return Union(m, b) 142 | } 143 | 144 | func (m *MapSet) Intersect(b types.Set) (types.Set, error) { 145 | return Intersect(m, b) 146 | } 147 | 148 | func (m *MapSet) Subtract(b types.Set) (types.Set, error) { 149 | return Subtract(m, b) 150 | } 151 | 152 | func (m *MapSet) Subset(b types.Set) bool { 153 | return Subset(m, b) 154 | } 155 | 156 | func (m *MapSet) Superset(b types.Set) bool { 157 | return Superset(m, b) 158 | } 159 | 160 | func (m *MapSet) ProperSubset(b types.Set) bool { 161 | return ProperSubset(m, b) 162 | } 163 | 164 | func (m *MapSet) ProperSuperset(b types.Set) bool { 165 | return ProperSuperset(m, b) 166 | } 167 | 168 | func (m *MapSet) String() string { 169 | return fmt.Sprintf("%v", m.Set) 170 | } 171 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/machines/dfa_machine.go: -------------------------------------------------------------------------------- 1 | package machines 2 | 3 | // DFATrans represents a Deterministic Finite Automatons state transition table 4 | type DFATrans [][256]int 5 | 6 | // DFAAccepting represents maps from accepting DFA states to match identifiers. 7 | // These both identify which states are accepting states and which matches they 8 | // belong to from the AST. 9 | type DFAAccepting map[int]int 10 | 11 | type lineCol struct { 12 | line, col int 13 | } 14 | 15 | // Compute the line and column of a particular index inside of a byte slice. 16 | func mapLineCols(text []byte) []lineCol { 17 | m := make([]lineCol, len(text)) 18 | line := 1 19 | col := 0 20 | for i := 0; i < len(text); i++ { 21 | if text[i] == '\n' { 22 | col = 0 23 | line++ 24 | } else { 25 | col++ 26 | } 27 | m[i] = lineCol{line: line, col: col} 28 | } 29 | return m 30 | } 31 | 32 | // DFALexerEngine does the actual tokenization of the byte slice text using the 33 | // DFA state machine. If the lexing process fails the Scanner will return 34 | // an UnconsumedInput error. 35 | func DFALexerEngine(startState, errorState int, trans DFATrans, accepting DFAAccepting, text []byte) Scanner { 36 | lineCols := mapLineCols(text) 37 | done := false 38 | matchID := -1 39 | matchTC := -1 40 | 41 | var scan Scanner 42 | scan = func(tc int) (int, *Match, error, Scanner) { 43 | if done && tc == len(text) { 44 | return tc, nil, nil, nil 45 | } 46 | startTC := tc 47 | if tc < matchTC { 48 | // we back-tracked so reset the last matchTC 49 | matchTC = -1 50 | } else if tc == matchTC { 51 | // the caller did not reset the tc, we are where we left 52 | } else if matchTC != -1 && tc > matchTC { 53 | // we skipped text 54 | matchTC = tc 55 | } 56 | state := startState 57 | for ; tc < len(text) && state != errorState; tc++ { 58 | if match, has := accepting[state]; has { 59 | matchID = match 60 | matchTC = tc 61 | } 62 | state = trans[state][text[tc]] 63 | if state == errorState && matchID > -1 { 64 | startLC := lineCols[startTC] 65 | endLC := lineCols[matchTC-1] 66 | match := &Match{ 67 | PC: matchID, 68 | TC: startTC, 69 | StartLine: startLC.line, 70 | StartColumn: startLC.col, 71 | EndLine: endLC.line, 72 | EndColumn: endLC.col, 73 | Bytes: text[startTC:matchTC], 74 | } 75 | if matchTC == startTC { 76 | err := &EmptyMatchError{ 77 | MatchID: matchID, 78 | TC: tc, 79 | Line: startLC.line, 80 | Column: startLC.col, 81 | } 82 | return startTC, nil, err, scan 83 | } 84 | matchID = -1 85 | return matchTC, match, nil, scan 86 | } 87 | } 88 | if match, has := accepting[state]; has { 89 | matchID = match 90 | matchTC = tc 91 | } 92 | if startTC <= len(text) && matchID > -1 && matchTC == startTC { 93 | var startLC lineCol 94 | if startTC < len(text) { 95 | startLC = lineCols[startTC] 96 | } 97 | err := &EmptyMatchError{ 98 | MatchID: matchID, 99 | TC: tc, 100 | Line: startLC.line, 101 | Column: startLC.col, 102 | } 103 | matchID = -1 104 | return startTC, nil, err, scan 105 | } 106 | if startTC < len(text) && matchTC <= len(text) && matchID > -1 { 107 | startLC := lineCols[startTC] 108 | endLC := lineCols[matchTC-1] 109 | match := &Match{ 110 | PC: matchID, 111 | TC: startTC, 112 | StartLine: startLC.line, 113 | StartColumn: startLC.col, 114 | EndLine: endLC.line, 115 | EndColumn: endLC.col, 116 | Bytes: text[startTC:matchTC], 117 | } 118 | matchID = -1 119 | return matchTC, match, nil, scan 120 | } 121 | if matchTC != len(text) && startTC >= len(text) { 122 | // the user has moved us farther than the text. Assume that was 123 | // the intent and return EOF. 124 | return tc, nil, nil, nil 125 | } else if matchTC != len(text) { 126 | done = true 127 | if matchTC == -1 { 128 | matchTC = 0 129 | } 130 | startLC := lineCols[startTC] 131 | etc := tc 132 | var endLC lineCol 133 | if etc >= len(lineCols) { 134 | endLC = lineCols[len(lineCols)-1] 135 | } else { 136 | endLC = lineCols[etc] 137 | } 138 | err := &UnconsumedInput{ 139 | StartTC: startTC, 140 | FailTC: etc, 141 | StartLine: startLC.line, 142 | StartColumn: startLC.col, 143 | FailLine: endLC.line, 144 | FailColumn: endLC.col, 145 | Text: text, 146 | } 147 | return tc, nil, err, scan 148 | } else { 149 | return tc, nil, nil, nil 150 | } 151 | } 152 | return scan 153 | } 154 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/data-structures/set/sortedset.go: -------------------------------------------------------------------------------- 1 | package set 2 | 3 | import ( 4 | crand "crypto/rand" 5 | "encoding/binary" 6 | "log" 7 | mrand "math/rand" 8 | ) 9 | 10 | import ( 11 | "github.com/timtadh/data-structures/errors" 12 | "github.com/timtadh/data-structures/list" 13 | trand "github.com/timtadh/data-structures/rand" 14 | "github.com/timtadh/data-structures/types" 15 | ) 16 | 17 | var rand *mrand.Rand 18 | 19 | func init() { 20 | seed := make([]byte, 8) 21 | if _, err := crand.Read(seed); err == nil { 22 | rand = trand.ThreadSafeRand(int64(binary.BigEndian.Uint64(seed))) 23 | } else { 24 | panic(err) 25 | } 26 | } 27 | 28 | type MSortedSet struct { 29 | list.MSorted 30 | } 31 | 32 | func NewMSortedSet(s *SortedSet, marshal types.ItemMarshal, unmarshal types.ItemUnmarshal) *MSortedSet { 33 | return &MSortedSet{ 34 | MSorted: *list.NewMSorted(&s.Sorted, marshal, unmarshal), 35 | } 36 | } 37 | 38 | func (m *MSortedSet) SortedSet() *SortedSet { 39 | return &SortedSet{*m.MSorted.Sorted()} 40 | } 41 | 42 | // SortedSet is a list.Sorted and therefore has all of the methods 43 | // that list.Sorted has. So although they do not show up in the generated 44 | // docs you can just do this: 45 | // 46 | // s := NewSortedSet(10) 47 | // s.Add(types.Int(5)) 48 | // s2 = s.Union(FromSlice([]types.Hashable{types.Int(7)})) 49 | // fmt.Println(s2.Has(types.Int(7))) 50 | // fmt.Println(s.Has(types.Int(7))) 51 | // 52 | type SortedSet struct { 53 | list.Sorted 54 | } 55 | 56 | func NewSortedSet(initialSize int) *SortedSet { 57 | return &SortedSet{*list.NewSorted(initialSize, false)} 58 | } 59 | 60 | func FromSlice(items []types.Hashable) *SortedSet { 61 | s := NewSortedSet(len(items)) 62 | for _, item := range items { 63 | err := s.Add(item) 64 | if err != nil { 65 | log.Panic(err) 66 | } 67 | } 68 | return s 69 | } 70 | 71 | func SortedFromSet(s types.Set) *SortedSet { 72 | if s == nil || s.Size() == 0 { 73 | return NewSortedSet(0) 74 | } 75 | n := NewSortedSet(s.Size()) 76 | for i, next := s.Items()(); next != nil; i, next = next() { 77 | n.Add(i) 78 | } 79 | return n 80 | } 81 | 82 | func (s *SortedSet) Copy() *SortedSet { 83 | return &SortedSet{*s.Sorted.Copy()} 84 | } 85 | 86 | func (s *SortedSet) Random() (item types.Hashable, err error) { 87 | if s.Size() <= 0 { 88 | return nil, errors.Errorf("Set is empty") 89 | } else if s.Size() <= 1 { 90 | return s.Get(0) 91 | } 92 | i := rand.Intn(s.Size()) 93 | return s.Get(i) 94 | } 95 | 96 | // Unions s with o and returns a new Sorted Set 97 | func (s *SortedSet) Union(other types.Set) (types.Set, error) { 98 | if o, ok := other.(*SortedSet); ok { 99 | return s.union(o) 100 | } else { 101 | return Union(s, other) 102 | } 103 | } 104 | 105 | func (s *SortedSet) union(o *SortedSet) (n *SortedSet, err error) { 106 | n = NewSortedSet(s.Size() + o.Size() + 10) 107 | cs, si := s.Items()() 108 | co, oi := o.Items()() 109 | for si != nil || oi != nil { 110 | var err error 111 | if si == nil { 112 | err = n.Add(co) 113 | co, oi = oi() 114 | } else if oi == nil { 115 | err = n.Add(cs) 116 | cs, si = si() 117 | } else if cs.Less(co) { 118 | err = n.Add(cs) 119 | cs, si = si() 120 | } else { 121 | err = n.Add(co) 122 | co, oi = oi() 123 | } 124 | if err != nil { 125 | return nil, err 126 | } 127 | } 128 | return n, nil 129 | } 130 | 131 | // Unions s with o and returns a new Sorted Set 132 | func (s *SortedSet) Intersect(other types.Set) (types.Set, error) { 133 | return Intersect(s, other) 134 | } 135 | 136 | // Unions s with o and returns a new Sorted Set 137 | func (s *SortedSet) Subtract(other types.Set) (types.Set, error) { 138 | return Subtract(s, other) 139 | } 140 | 141 | // Are there any overlapping elements? 142 | func (s *SortedSet) Overlap(o *SortedSet) bool { 143 | cs, si := s.Items()() 144 | co, oi := o.Items()() 145 | for si != nil && oi != nil { 146 | s := cs.(types.Hashable) 147 | o := co.(types.Hashable) 148 | if s.Equals(o) { 149 | return true 150 | } else if s.Less(o) { 151 | cs, si = si() 152 | } else { 153 | co, oi = oi() 154 | } 155 | } 156 | return false 157 | } 158 | 159 | // Is s a subset of o? 160 | func (s *SortedSet) Subset(o types.Set) bool { 161 | return Subset(s, o) 162 | } 163 | 164 | // Is s a proper subset of o? 165 | func (s *SortedSet) ProperSubset(o types.Set) bool { 166 | return ProperSubset(s, o) 167 | } 168 | 169 | // Is s a superset of o? 170 | func (s *SortedSet) Superset(o types.Set) bool { 171 | return Superset(s, o) 172 | } 173 | 174 | // Is s a proper superset of o? 175 | func (s *SortedSet) ProperSuperset(o types.Set) bool { 176 | return ProperSuperset(s, o) 177 | } 178 | -------------------------------------------------------------------------------- /vendor/github.com/timtadh/lexmachine/doc.go: -------------------------------------------------------------------------------- 1 | // Package lexmachine is a full lexical analysis framework for the Go 2 | // programming language. It supports a restricted but usable set of regular 3 | // expressions appropriate for writing lexers for complex programming 4 | // languages. The framework also supports sub-lexers and non-regular lexing 5 | // through an "escape hatch" which allows the users to consume any number of 6 | // further bytes after a match. So if you want to support nested C-style 7 | // comments or other paired structures you can do so at the lexical analysis 8 | // stage. 9 | // 10 | // For a tutorial see 11 | // http://hackthology.com/writing-a-lexer-in-go-with-lexmachine.html 12 | // 13 | // Example of defining a lexer 14 | // 15 | // // CreateLexer defines a lexer for the graphviz dot language. 16 | // func CreateLexer() (*lexmachine.Lexer, error) { 17 | // lexer := lexmachine.NewLexer() 18 | // 19 | // for _, lit := range Literals { 20 | // r := "\\" + strings.Join(strings.Split(lit, ""), "\\") 21 | // lexer.Add([]byte(r), token(lit)) 22 | // } 23 | // for _, name := range Keywords { 24 | // lexer.Add([]byte(strings.ToLower(name)), token(name)) 25 | // } 26 | // 27 | // lexer.Add([]byte(`//[^\n]*\n?`), token("COMMENT")) 28 | // lexer.Add([]byte(`/\*([^*]|\r|\n|(\*+([^*/]|\r|\n)))*\*+/`), token("COMMENT")) 29 | // lexer.Add([]byte(`([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|_)*`), token("ID")) 30 | // lexer.Add([]byte(`"([^\\"]|(\\.))*"`), token("ID")) 31 | // lexer.Add([]byte("( |\t|\n|\r)+"), skip) 32 | // lexer.Add([]byte(`\<`), 33 | // func(scan *lexmachine.Scanner, match *machines.Match) (interface{}, error) { 34 | // str := make([]byte, 0, 10) 35 | // str = append(str, match.Bytes...) 36 | // brackets := 1 37 | // match.EndLine = match.StartLine 38 | // match.EndColumn = match.StartColumn 39 | // for tc := scan.TC; tc < len(scan.Text); tc++ { 40 | // str = append(str, scan.Text[tc]) 41 | // match.EndColumn += 1 42 | // if scan.Text[tc] == '\n' { 43 | // match.EndLine += 1 44 | // } 45 | // if scan.Text[tc] == '<' { 46 | // brackets += 1 47 | // } else if scan.Text[tc] == '>' { 48 | // brackets -= 1 49 | // } 50 | // if brackets == 0 { 51 | // match.TC = scan.TC 52 | // scan.TC = tc + 1 53 | // match.Bytes = str 54 | // return token("ID")(scan, match) 55 | // } 56 | // } 57 | // return nil, 58 | // fmt.Errorf("unclosed HTML literal starting at %d, (%d, %d)", 59 | // match.TC, match.StartLine, match.StartColumn) 60 | // }, 61 | // ) 62 | // 63 | // err := lexer.Compile() 64 | // if err != nil { 65 | // return nil, err 66 | // } 67 | // return lexer, nil 68 | // } 69 | // 70 | // func token(name string) lex.Action { 71 | // return func(s *lex.Scanner, m *machines.Match) (interface{}, error) { 72 | // return s.Token(TokenIds[name], string(m.Bytes), m), nil 73 | // } 74 | // } 75 | // 76 | // Example of using a lexer 77 | // 78 | // func ExampleLex() error { 79 | // lexer, err := CreateLexer() 80 | // if err != nil { 81 | // return err 82 | // } 83 | // scanner, err := lexer.Scanner([]byte(`digraph { 84 | // rankdir=LR; 85 | // a [label="a" shape=box]; 86 | // c [