parent
e283bc5e1d
commit
078ac86110
@ -0,0 +1,39 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name active.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package matchs
|
||||
|
||||
|
||||
var (
|
||||
|
||||
G = struct {
|
||||
ErrInvalidMatcher ErrMatchs
|
||||
ErrMatcherNotFound ErrMatchs
|
||||
ErrInvalidBuilder ErrMatchs
|
||||
}{
|
||||
ErrInvalidMatcher : ErrMatchs{ ErrCode("invalid-matcher")},
|
||||
ErrMatcherNotFound: ErrMatchs{ ErrCode("matcher-not-found")},
|
||||
ErrInvalidBuilder : ErrMatchs{ ErrCode("invalid-builder")},
|
||||
}
|
||||
|
||||
)
|
||||
@ -0,0 +1,33 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name err_matchs.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package matchs
|
||||
|
||||
import "errs"
|
||||
|
||||
type (
|
||||
|
||||
ErrMatchs { errs.ErrCode }
|
||||
)
|
||||
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name matcher.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package matchs
|
||||
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name active.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
import "errs"
|
||||
|
||||
var (
|
||||
|
||||
G = struct {
|
||||
ErrInvalidTopic ErrTokens
|
||||
ErrInvalidTopicLen ErrTokens
|
||||
ErrInvalidToken ErrTokens
|
||||
ErrInvalidTokenLen ErrTokens
|
||||
} {
|
||||
ErrInvalidTopic : ErrTokens{errs.ErrCode("invalid-topic")},
|
||||
ErrInvalidTopicLen : ErrTokens{errs.ErrCode("invalid-topic-len")},
|
||||
ErrInvalidToken : ErrTokens{errs.ErrCode("invalid-token")},
|
||||
ErrInvalidTokenLen : ErrTokens{errs.ErrCode("invalid-token-len")},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@ -0,0 +1,276 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name atokenizer.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const (
|
||||
|
||||
topicMinLen int = 1
|
||||
topicMaxLen int = 255
|
||||
topicMaxTokens int = 32
|
||||
topicMinTokens int = 1
|
||||
|
||||
tokenMinLen int = 1
|
||||
tokenMaxLen int = 256
|
||||
|
||||
//
|
||||
// Token chars
|
||||
//
|
||||
tokenSep byte = '.'
|
||||
tokenWildcard byte = '*'
|
||||
tokenRelative byte = '+'
|
||||
tokenMatchini byte = '{'
|
||||
tokenMatchend byte = '}'
|
||||
|
||||
)
|
||||
|
||||
|
||||
type (
|
||||
|
||||
|
||||
|
||||
|
||||
// TokenizerCore
|
||||
// Struct type
|
||||
// Implements -> Tokenizer
|
||||
//
|
||||
TokenizerCore struct {
|
||||
TokenSep byte
|
||||
TokenWildcard byte
|
||||
TokenRelative byte
|
||||
TokenMathcIni byte
|
||||
TokenMatchEnd byte
|
||||
MinLenToken int
|
||||
MaxLenToken int
|
||||
MinLenTopic int
|
||||
MaxLenTopic int
|
||||
MinTokens int
|
||||
MaxTokens int
|
||||
|
||||
MatchBuilder mchs.Matchers
|
||||
}
|
||||
|
||||
|
||||
// TokenizerCoreFnc
|
||||
// Function type
|
||||
//
|
||||
//
|
||||
TokenizerCoreFnc func (tkz *TokenizerCore)
|
||||
|
||||
)
|
||||
|
||||
|
||||
// NewTokenizerCore
|
||||
// Function constructor -> TokenizerCore
|
||||
//
|
||||
//
|
||||
func NewTokenizerCore(ops ...TokenizerCoreFnc)(*TokenizerCore){
|
||||
tk := &TokenizerCore{
|
||||
TokenSep : tokenSep,
|
||||
TokenWildcard : tokenWildcard,
|
||||
TokenRelative : tokenRelative,
|
||||
TokenMathcIni : tokenMatchini,
|
||||
TokenMatchEnd : tokenMatchend,
|
||||
MinLenToken : tokenMinLen,
|
||||
MaxLenToken : tokenMaxLen,
|
||||
MinLenTopic : topicMinLen,
|
||||
MaxLenTopic : topicMaxLen,
|
||||
MinTokens : topicMinTokens,
|
||||
MaxTokens : topicMaxTokens,
|
||||
}
|
||||
|
||||
for _,o := range ops {
|
||||
o(tk) }
|
||||
|
||||
if tk.MaxTokens > topicMaxTokens {
|
||||
tk.MaxTokens = topicMaxTokens
|
||||
}
|
||||
|
||||
if tk.MatchBuilder == nil {
|
||||
tk.MatchBuilder = mchs.MatchersNoop{} }
|
||||
|
||||
return tk
|
||||
}
|
||||
|
||||
|
||||
// NewTopic
|
||||
// Function member -> TokenizerCore
|
||||
//
|
||||
//
|
||||
func (t TokenizerCore) NewTopic (tpc []byte, alw Kind) *Topic { return NewTopic(t,tpc,alw) }
|
||||
|
||||
|
||||
// Tokenize
|
||||
// Function member -> TokenizerCore
|
||||
// Implements -> Tokenizer
|
||||
//
|
||||
//
|
||||
func (t TokenizerCore) Tokenize(tpc []byte, alw Kind) (Tokens, Kind){
|
||||
ln := len(tpc)
|
||||
if ln < t.MinLenTopic || ln > t.MaxLenTopic {
|
||||
return []Token{*(NewInvalidToken(G.ErrInvalidTopicLen,tpc)) }, TokenKindInvalid
|
||||
}
|
||||
|
||||
tl := [topicMaxTokens]Token{}
|
||||
tt := TokenKindNone
|
||||
m,c,x := 0,0,0
|
||||
|
||||
for i:=0; i<ln; i++ {
|
||||
switch tpc[i] {
|
||||
case t.TokenMathcIni : m++
|
||||
case t.TokenMatchEnd : m--
|
||||
case t.TokenSep:
|
||||
if m != 0 {
|
||||
continue }
|
||||
if c >= t.MaxTokens {
|
||||
tl[c] = *(NewInvalidToken(G.ErrInvalidTopicLen,tpc[x:]))
|
||||
return tl[:c+1], tt | TokenKindInvalid
|
||||
}
|
||||
tl[c] = t.NewToken(tpc[x:i])
|
||||
tk := tl[c].Kind()
|
||||
if tk == TokenKindRelative {
|
||||
tl[c]= NewInvalidToken(G.ErrInvalidToken,tpc[x:i])
|
||||
} else if tk & alw == 0 {
|
||||
tt |= TokenKindInvalid
|
||||
}
|
||||
tt |= tl[c].Kind()
|
||||
x = i + 1
|
||||
c++
|
||||
}
|
||||
}
|
||||
|
||||
if m != 0 {
|
||||
tl[c] = *(NewInvalidToken(G.ErrInvalidTopic,tpc[x:]))
|
||||
} else {
|
||||
tl[c] = t.NewToken(tpc[x:])
|
||||
}
|
||||
|
||||
return tl[:c+1], tt | tl[c].Kind()
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Split
|
||||
// Function member -> TokenizerCore
|
||||
//
|
||||
//
|
||||
func (t TokenizerCore) Split (tpc []byte, alw Kind)([][]byte, Kind){
|
||||
var ms, ps,x int
|
||||
var tk, pk Kind
|
||||
ln := len(tpc)
|
||||
ar := [topicMaxTokens][]byte{}
|
||||
|
||||
for i:=0; i< ln; i++ {
|
||||
switch tpc[i] {
|
||||
case t.TokenMathcIni : ms++
|
||||
case t.TokenMatchEnd : ms--
|
||||
case t.TokenSep:
|
||||
if ms == 0 {
|
||||
ar[ps] = tpc[x:i]
|
||||
if pk = t.Kind(ar[ps]); pk & alw == 0 {
|
||||
return nil, TokenKindInvalid
|
||||
}
|
||||
tk|= pk
|
||||
x = i + 1
|
||||
ps++
|
||||
}
|
||||
}
|
||||
}
|
||||
ar[ps] = tpc[x:]
|
||||
if pk = t.Kind(ar[ps]); pk& alw == 0 {
|
||||
return nil, TokenKindInvalid
|
||||
}
|
||||
tk |= pk
|
||||
|
||||
return ar[:ps+1],tk
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// NewToken
|
||||
// Function member -> TokenizerCore
|
||||
//
|
||||
//
|
||||
func (t TokenizerCore) NewToken(Token []byte)(Token){
|
||||
ln := len(Token)
|
||||
if ln < t.MinLenToken || ln > t.MaxLenToken {
|
||||
return InvalidToken{ error: nil, source: Token } }
|
||||
|
||||
if ln == 1 {
|
||||
switch Token[0] {
|
||||
case t.TokenWildcard : return WildcardToken{}
|
||||
case t.TokenRelative : return RelativeToken{}
|
||||
case t.TokenMathcIni,
|
||||
t.TokenMatchEnd : return *(NewInvalidToken(G.ErrInvalidTopicLen,Token)) }
|
||||
}
|
||||
|
||||
if Token[0] != t.TokenMathcIni {
|
||||
return LiteralToken(Token) }
|
||||
|
||||
if Token[ln-1] == t.TokenMatchEnd && ln > t.MinLenToken+ 2 {
|
||||
m,e := t.MatchBuilder.Build(Token)
|
||||
if e == nil {
|
||||
return *(NewMatcherToken(m.Match,Token)) }
|
||||
return *(NewInvalidToken(e,Token))
|
||||
}
|
||||
|
||||
return *(NewInvalidToken(mchs.Errs.ErrInvalidMatcher,Token))
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Kind
|
||||
// Function member -> TokenizerCore
|
||||
//
|
||||
func (t TokenizerCore) Kind (Token []byte)(Kind){
|
||||
ln := len(Token)
|
||||
if ln < t.MinLenToken || ln > t.MaxLenToken {
|
||||
return TokenKindInvalid
|
||||
}
|
||||
|
||||
if ln == 1 {
|
||||
switch Token[0] {
|
||||
case t.TokenWildcard : return TokenWildcard
|
||||
case t.TokenRelative : return TokenRelative
|
||||
case t.TokenMathcIni,
|
||||
t.TokenMatchEnd : return TokenKindInvalid
|
||||
}
|
||||
}
|
||||
|
||||
if Token[0] == t.TokenMathcIni {
|
||||
if Token[ln-1] == t.TokenMatchEnd {
|
||||
return TokenMatcher }
|
||||
return TokenKindInvalid
|
||||
}
|
||||
return TokenLiteral
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name err_token.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
import "errs"
|
||||
|
||||
type (
|
||||
|
||||
ErrTokens struct { errs.ErrCode }
|
||||
|
||||
)
|
||||
|
||||
|
||||
@ -0,0 +1,77 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name kind.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
const (
|
||||
|
||||
// Kind enum values
|
||||
//
|
||||
TokenKindNone Kind = 0
|
||||
TokenKindLiteral Kind = 1
|
||||
TokenKindWildcard Kind = 2
|
||||
TokenKindMatcher Kind = 4
|
||||
TokenKindRelative Kind = 8
|
||||
TokenKindInvalid Kind = 128
|
||||
//
|
||||
// Kind compund values
|
||||
//
|
||||
TokenKindAny = TokenKindRelative | TokenKindWildcard
|
||||
TokenKindTopic = TokenKindLiteral | TokenKindMatcher | TokenKindAny
|
||||
TokenKindMatchable= TokenKindLiteral | TokenKindMatcher
|
||||
TokenKindAll = TokenKindInvalid | TokenKindTopic
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Kind uint8
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
func (t Kind) HasLiteral () bool {
|
||||
return t &TokenKindLiteral != 0 }
|
||||
|
||||
func (t Kind) HasRelative () bool {
|
||||
return t &TokenKindRelative != 0 }
|
||||
|
||||
func (t Kind) HasWildcard () bool {
|
||||
return t &TokenKindWildcard != 0 }
|
||||
|
||||
func (t Kind) HasMatcher () bool {
|
||||
return t &TokenKindMatcher != 0 }
|
||||
|
||||
func (t Kind) HasInvalid () bool {
|
||||
return t &TokenKindInvalid != 0 }
|
||||
|
||||
func (t Kind) HasAny () bool {
|
||||
return t &TokenKindAny != 0 }
|
||||
|
||||
func (t Kind) HasMatchable() bool {
|
||||
return t &TokenKindMatchable != 0 }
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Token interface {
|
||||
Kind () Kind
|
||||
Source() []byte
|
||||
|
||||
Match (val []byte) bool
|
||||
}
|
||||
|
||||
)
|
||||
@ -0,0 +1,49 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token_invalid.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
type (
|
||||
|
||||
InvalidToken struct {
|
||||
error
|
||||
source []byte
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
|
||||
func NewInvalidToken(err error, src []byte) *InvalidToken {
|
||||
return &InvalidToken{ error : err, source: src }}
|
||||
|
||||
|
||||
func (_ InvalidToken) Kind () Kind {
|
||||
return TokenKindInvalid
|
||||
}
|
||||
|
||||
func (_ InvalidToken) Match (_ []byte) bool {
|
||||
return false }
|
||||
|
||||
func (t InvalidToken) Source()[]byte {
|
||||
return t.source }
|
||||
@ -0,0 +1,46 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token_literal.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
import "bytes"
|
||||
|
||||
type (
|
||||
|
||||
|
||||
// LiteralToken
|
||||
// Implements -> Token
|
||||
LiteralToken []byte
|
||||
|
||||
)
|
||||
|
||||
|
||||
func (_ LiteralToken) Kind () Kind {
|
||||
return TokenKindLiteral
|
||||
}
|
||||
|
||||
func (t LiteralToken) Match (val []byte) bool {
|
||||
return bytes.Equal(t, val) }
|
||||
|
||||
func (t LiteralToken) Source()[]byte {
|
||||
return t }
|
||||
@ -0,0 +1,50 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token_matcher.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
type (
|
||||
|
||||
MatcherToken struct {
|
||||
source []byte
|
||||
matchFn MatchFnc
|
||||
}
|
||||
|
||||
MatchFnc func (target []byte) bool
|
||||
)
|
||||
|
||||
|
||||
func NewMatcherToken (mfn MatchFnc, src []byte) *MatcherToken {
|
||||
return &MatcherToken{ matchFn: mfn, source: src } }
|
||||
|
||||
|
||||
func (_ MatcherToken) Kind () Kind {
|
||||
return TokenKindMatcher
|
||||
}
|
||||
|
||||
func (t MatcherToken) Match(val []byte) bool {
|
||||
return t.matchFn(val) }
|
||||
|
||||
func (t MatcherToken) Source()[]byte {
|
||||
return t.source }
|
||||
@ -0,0 +1,43 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token_relative.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
RelativeToken struct {}
|
||||
)
|
||||
|
||||
|
||||
func (_ RelativeToken) Kind () Kind {
|
||||
return TokenKindRelative
|
||||
}
|
||||
|
||||
func (_ RelativeToken) Match(_ []byte) bool {
|
||||
return true }
|
||||
|
||||
func (_ RelativeToken) Source()[]byte {
|
||||
return nil }
|
||||
@ -0,0 +1,41 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name token_wildcard.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
type (
|
||||
|
||||
WildcardToken struct {}
|
||||
)
|
||||
|
||||
|
||||
func (_ WildcardToken) Kind () Kind {
|
||||
return TokenKindWildcard
|
||||
}
|
||||
|
||||
func (_ WildcardToken) Match(_ []byte) bool {
|
||||
return true }
|
||||
|
||||
func (_ WildcardToken) Source()[]byte {
|
||||
return nil }
|
||||
@ -0,0 +1,41 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name tokenizer.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Tokenizer interface {
|
||||
|
||||
NewToken (Token []byte) Token
|
||||
|
||||
TokenKind (Token []byte) Kind
|
||||
|
||||
Split (subject []byte, allow Kind) ([][]byte , Kind)
|
||||
Tokenize (topic []byte, allow Kind) (Tokens, Kind)
|
||||
}
|
||||
|
||||
)
|
||||
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name tokens.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
Tokens []Token
|
||||
)
|
||||
@ -0,0 +1,64 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name topic.go
|
||||
// Created by DEV
|
||||
// Modified 24/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package tokens
|
||||
|
||||
|
||||
|
||||
type (
|
||||
|
||||
|
||||
// Topic
|
||||
// Struct type
|
||||
//
|
||||
//
|
||||
Topic struct {
|
||||
kind Kind
|
||||
source []byte
|
||||
tokens Tokens
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TopicList
|
||||
// Slice type
|
||||
// Implements -> sort.Interface
|
||||
//
|
||||
//
|
||||
TopicList []Topic
|
||||
|
||||
)
|
||||
|
||||
|
||||
// NewTopic
|
||||
// Function constructor -> Topic
|
||||
//
|
||||
//
|
||||
func NewTopic (tkz Tokenizer, tpc []byte, alw Kind)(*Topic){
|
||||
tp := &Topic{
|
||||
source : tpc }
|
||||
tp.tokens,
|
||||
tp.kind = tkz.Tokenize(tpc,alw)
|
||||
return tp
|
||||
}
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
module btypes
|
||||
|
||||
go 1.22
|
||||
@ -1,3 +0,0 @@
|
||||
module cdcs
|
||||
|
||||
go 1.22
|
||||
@ -0,0 +1,70 @@
|
||||
// ------------------------------------------------------------------------
|
||||
// Project active2
|
||||
// Active Thing (activething.com) git.activething.com/go
|
||||
//
|
||||
// File name writer.go
|
||||
// Created by DEV
|
||||
// Modified 23/04/2024
|
||||
//
|
||||
// Copyright 2024 activething.com
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
package base32
|
||||
|
||||
import (
|
||||
"bins/mems"
|
||||
"encoding/base32"
|
||||
)
|
||||
|
||||
func Write(b *mems.ABuffer, value, null, empty []byte, isQuoted bool, quote byte) (er error) {
|
||||
if value == nil {
|
||||
_,_ = b.Write(null)
|
||||
return nil
|
||||
}
|
||||
if len(value) == 0 {
|
||||
_,_ = b.Write(empty)
|
||||
return nil
|
||||
}
|
||||
|
||||
p := b.Len()
|
||||
if isQuoted {
|
||||
b.WriteByte(quote)
|
||||
}
|
||||
|
||||
var t [64]byte
|
||||
ln := base32.StdEncoding.EncodedLen(len(value))
|
||||
if ln <= len(t) {
|
||||
dst := t[:ln]
|
||||
base32.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if ln <= 1024 {
|
||||
dst := make([]byte, ln)
|
||||
base32.StdEncoding.Encode(dst, value)
|
||||
_,er = b.Write(dst)
|
||||
} else if er == nil {
|
||||
ec := base32.NewEncoder(base32.StdEncoding, b)
|
||||
_,_ = ec.Write(value)
|
||||
return ec.Close()
|
||||
}
|
||||
|
||||
if er == nil {
|
||||
if isQuoted {
|
||||
b.WriteByte(quote)
|
||||
}
|
||||
} else {
|
||||
b.Truncate(p)
|
||||
}
|
||||
return er
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
module codecs
|
||||
|
||||
go 1.22
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue