services

package module
v0.0.0-...-ea87bdc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 6 Imported by: 1

README

stoplist

Generates stoplist from YAML-format

Supports:

  1. Regexp patterns
  2. AND/OR conditions
  3. References

Installation

go get 'github.com/webtor-io/stoplist'

Sample usage

package main

import (
	"log"
	"github.com/webtor-io/stoplist"
)

var rules = `
main:
- abra
- cadabra
`

func main() error {
    r, err := stoplist.NewRuleFromYaml([]byte(rules))
    if err != nil {
        return err
    }
    res := r.Check("abra cadabra")
    log.Println(res)
    return nil
}

Rules

  1. YAML must have main key - it is starting point
  2. Every key must have an array of rules and all these rules will be used with OR condition, like:
main:
- rule1
- rule2
- ...
  1. All keys can be referenced with curly brackets, like:
rule:
- something
main:
- {rule}
  1. Regular expression must be enclosed with slashes, like:
main:
- /\d+/
  1. OR condition is represented with pipe |, like:
main:
- aaa|bbb|ccc
  1. AND condition is represented with plus +, like:
main:
- aaa+bbb+ccc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseLine

func ParseLine(ll string) []lexeme

func SplitByLexeme

func SplitByLexeme(lms []lexeme, lt LexemeType) [][]lexeme

Types

type CheckResult

type CheckResult struct {
	Found bool
	Stack []string
}

func (CheckResult) String

func (s CheckResult) String() string

type Checker

type Checker interface {
	Check(val string) *CheckResult
}

func NewLineRule

func NewLineRule(rr *rootRule, lines []string) (Checker, error)

func NewPipeRule

func NewPipeRule(rr *rootRule, lms []lexeme) (Checker, error)

func NewPlusRule

func NewPlusRule(rr *rootRule, lms []lexeme) (Checker, error)

func NewReferenceRule

func NewReferenceRule(rr *rootRule, value string) (Checker, error)

func NewRegexpRule

func NewRegexpRule(value string) (Checker, error)

func NewRule

func NewRule(m map[string][]string) (Checker, error)

func NewRuleFromYaml

func NewRuleFromYaml(data []byte) (Checker, error)

func NewRuleFromYamlFile

func NewRuleFromYamlFile(path string) (Checker, error)

type LexemeType

type LexemeType string
const (
	Plus      LexemeType = "plus"
	Pipe      LexemeType = "pipe"
	Regexp    LexemeType = "regexp"
	Reference LexemeType = "reference"
	Text      LexemeType = "text"
)

type ReferenceRule

type ReferenceRule struct {
	// contains filtered or unexported fields
}

func (*ReferenceRule) Check

func (s *ReferenceRule) Check(val string) *CheckResult

type RegexpRule

type RegexpRule struct {
	Regexp *regexp.Regexp
}

func (*RegexpRule) Check

func (s *RegexpRule) Check(val string) *CheckResult

type Rule

type Rule struct {
	// contains filtered or unexported fields
}

type TextRule

type TextRule struct {
	Text string
}

func NewTextRule

func NewTextRule(text string) (*TextRule, error)

func (*TextRule) Check

func (s *TextRule) Check(val string) *CheckResult

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL