You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.2 KiB

// ------------------------------------------------------------------------
// Project atila
// Active Thing (activething.com) git.activething.com/go
//
// File name topic.go
// Created by DEV
// Modified 18/02/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 {
kind TokenKind
source []byte
tokens []Token
}
)
func NewTopic(builder *Tokenizer, topic []byte, allows TokenKind) *Topic {
tp := &Topic{ source: topic }
tp.tokens, tp.kind = builder.Tokenize(topic, allows)
return tp
}
func (t Topic) Len() int {
return len(t.tokens) }
func (t Topic) Kind() TokenKind {
return t.kind }
func (t Topic) Source() []byte {
return t.source }
func (t Topic) Tokens() []Token {
return t.tokens }
func (t Topic) String() string {
return string(t.source) }
func (t Topic) Match(subject [][]byte) bool {
if t.kind.HasInvalid() {
return false
}
ln := len(t.tokens)
ls := len(subject)
if ln != ls {
if ln > ls {
return false
}
if !t.kind.HasRelative() {
return false
}
}
for i := 0; i < ln; i++ {
if t.tokens[i].Kind()&TokenKindMatchable != 0 {
if !t.tokens[i].Match(subject[i]) {
return false
}
}
}
return true
}
/*
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I HAVE NO DESIRE TO WALK ON WATER," SAID SIDDHARTA.
"LET THE OLD SHRAMANAS SATISFY THEMSELVES WITH SUCH SKILLS.
SIDDHARTA
- HERMANN HESSE -
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*/

Powered by TurnKey Linux.