rule

package
v2.0.0-...-6ef3e87 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package rule contains rule-based heuristic implementations. It is used in the generated code in content.go for disambiguation of languages with colliding extensions, based on regexps from Linguist data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchingLanguages

func MatchingLanguages(langs ...string) languages

MatchingLanguages is a helper to create new languages.

Types

type Heuristic

type Heuristic interface {
	Matcher
	Languages() []string
}

Heuristic consist of (a number of) rules where each, if matches, identifies content as belonging to a programming language(s).

func Always

func Always(l languages) Heuristic

Always rule always matches. Often is used as a default fallback.

func And

func And(l languages, m ...Matcher) Heuristic

And rule matches, if each of the patterns does match.

func Not

func Not(l languages, r ...Matcher) Heuristic

Not rule matches if none of the patterns match.

func Or

func Or(l languages, r Matcher) Heuristic

Or rule matches, if a single matching pattern exists. It receives only one pattern as it relies on compile-time optimization that represtes union with | inside a single regexp.

type Matcher

type Matcher interface {
	Match(data []byte) bool
}

Matcher checks if the data matches (number of) pattern. Every heuristic rule below implements this interface. A regexp.Regexp satisfies this interface and can be used instead.

Jump to

Keyboard shortcuts

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