patterns

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2021 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ESCAPED_NL = `\n`

	HASH       = "#"
	BOOL_TRUE  = "true"
	BOOL_FALSE = "false"
	NULL       = "null"

	PERIOD    = "."
	COLON     = ":"
	COMMA     = ","
	SEMICOLON = ";"
	EQUAL     = "="
	DOLLAR    = "$"

	SPLAT       = "..."
	DCOLON      = "::"
	COLON_EQUAL = ":="
	PLUS_PLUS   = "++"
	MINUS_MINUS = "--"
	ARROW       = "=>"
	PLUS_EQUAL  = "+="
	MINUS_EQUAL = "-="
	MUL_EQUAL   = "*="

	BRACES_START   = `{`
	BRACES_STOP    = `}`
	BRACKETS_START = `[`
	BRACKETS_STOP  = `]`
	PARENS_START   = `(`
	PARENS_STOP    = `)`
	ANGLED_START   = `<`
	ANGLED_STOP    = `>`
	ANGLED_STOP2   = `>>`
	ANGLED_STOP3   = `>>>`

	TAG_START            = `<`
	TAG_STOP_SELFCLOSING = `/>`

	NAMESPACE_SEPARATOR = `.`

	SQ_STRING_START  = `'`
	SQ_STRING_STOP   = SQ_STRING_START
	DQ_STRING_START  = `"`
	DQ_STRING_STOP   = DQ_STRING_START
	BT_FORMULA_START = "`"
	BT_FORMULA_STOP  = BT_FORMULA_START

	SL_COMMENT_START  = `//`
	ML_COMMENT_START  = `/*`
	ML_COMMENT_STOP   = `*/`
	XML_COMMENT_START = `<!--`
	XML_COMMENT_STOP  = `-->`

	HTML_SCRIPT_START = `<[\s]*script`
	HTML_SCRIPT_STOP  = `</[\s]*script[\s]*>`
	HTML_STYLE_START  = `<[\s]*style`
	HTML_STYLE_STOP   = `</[\s]*style[\s]*>`
)
View Source
const (
	COMPACT_LETTER = "abcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
var (
	COMPACT_NAMING = false
	NL             = "\n"
	TAB            = "  "
	LAST_SEMICOLON = ";"
)
View Source
var (
	XML_STRING_OR_COMMENT_REGEXP = compileRegexp(SQ_STRING_START,
		DQ_STRING_START, SL_COMMENT_START,
		ML_COMMENT_START, ML_COMMENT_STOP,
		XML_COMMENT_START, XML_COMMENT_STOP, BT_FORMULA_START)
	XML_STRING_REGEXP                = compileRegexp(SQ_STRING_START, DQ_STRING_START)
	FORMULA_STRING_OR_COMMENT_REGEXP = XML_STRING_OR_COMMENT_REGEXP
	JS_STRING_OR_COMMENT_REGEXP      = compileRegexp(SQ_STRING_START,
		DQ_STRING_START, SL_COMMENT_START,
		ML_COMMENT_START, ML_COMMENT_STOP, BT_FORMULA_START)
	GLSL_STRING_OR_COMMENT_REGEXP     = JS_STRING_OR_COMMENT_REGEXP
	MATH_STRING_OR_COMMENT_REGEXP     = compileRegexp(SL_COMMENT_START, ML_COMMENT_START, ML_COMMENT_STOP)
	TEMPLATE_STRING_OR_COMMENT_REGEXP = compileRegexp(SQ_STRING_START,
		DQ_STRING_START, BT_FORMULA_START, SL_COMMENT_START,
		ML_COMMENT_START, ML_COMMENT_STOP)
	CSS_STRING_REGEXP = compileRegexp(SQ_STRING_START, DQ_STRING_START)

	BRACES_GROUP       = NewGroup(BRACES_START, BRACES_STOP)
	BRACKETS_GROUP     = NewGroup(BRACKETS_START, BRACKETS_STOP)
	PARENS_GROUP       = NewGroup(PARENS_START, PARENS_STOP)
	PARENS_OPEN_REGEXP = compileRegexp(PARENS_START)

	SQ_STRING_GROUP   = NewGroup(SQ_STRING_START, SQ_STRING_STOP)
	DQ_STRING_GROUP   = NewGroup(DQ_STRING_START, DQ_STRING_STOP)
	BT_FORMULA_GROUP  = NewGroup(BT_FORMULA_START, BT_FORMULA_STOP)
	SL_COMMENT_GROUP  = NewGroup(SL_COMMENT_START, "\n")
	ML_COMMENT_GROUP  = NewGroup(ML_COMMENT_START, ML_COMMENT_STOP)
	XML_COMMENT_GROUP = NewGroup(XML_COMMENT_START, XML_COMMENT_STOP)
	HTML_SCRIPT_GROUP = NewGroup(HTML_SCRIPT_START, HTML_SCRIPT_STOP)
	HTML_STYLE_GROUP  = NewGroup(HTML_STYLE_START, HTML_STYLE_STOP)

	ALPHABET_REGEXP       = regexp.MustCompile(`\b[a-zA-Z]*\b`)
	SIMPLE_WORD_REGEXP    = regexp.MustCompile(`^[a-zA-Z]*$`)
	SVGPATH_LETTER_REGEXP = regexp.MustCompile(`[aAcClhHLmMqQsStTvVzZ]`)
	NL_REGEXP             = regexp.MustCompile(ESCAPED_NL)
	PERIOD_REGEXP         = compileRegexp(PERIOD)
	SVGPATH_MINUS_REGEXP  = regexp.MustCompile(`([^e])([\-])`)
	COMMA_REGEXP          = regexp.MustCompile(`[,]`)
	SQ_REGEXP             = compileRegexp(SQ_STRING_START)
	DQ_REGEXP             = compileRegexp(DQ_STRING_START)

	DIGIT_REGEXP = regexp.MustCompile(`[0-9]`)
	INT_REGEXP   = regexp.MustCompile(`^[\-]?[0-9]+$`)
	HEX_REGEXP   = regexp.MustCompile(`0x[0-9a-fA-F]+$`)
	FLOAT_REGEXP = regexp.MustCompile(`^[\-]?[0-9]+(\.[0-9]+)?(e[\-+]?[0-9]+)?([a-zA-Z%]*)?$`) // includes units
	FLOAT_UNITS  = []string{"s", "Q", "%", "cm", "mm", "in", "pc", "pt", "px", "em", "ch",
		"fr", "lh", "vw", "vh", "rem", "vmin", "vmax", "n"}
	PLAIN_FLOAT_REGEXP = regexp.MustCompile(`^[\-]?[0-9]+(\.[0-9]+)?(e[\-+]?[0-9]+)?$`) // doesnt include units

	TAG_START_REGEXP        = compileRegexp(TAG_START)
	TAG_NAME_REGEXP         = regexp.MustCompile(`(!\-\-)|([!?]?[#_a-zA-Z][0-9A-Za-z_\.]*)`)
	TAG_STOP_REGEXP         = regexp.MustCompile(`[/]?>`)
	XML_HEADER_STOP_REGEXP  = regexp.MustCompile(`[?]>`)
	XML_COMMENT_STOP_REGEXP = regexp.MustCompile(`-->`)
	DUMMY_TAG_NAME_REGEXP   = regexp.MustCompile(`^[\s]*>`)

	NAMESPACE_SEPARATOR_REGEXP = compileRegexp(NAMESPACE_SEPARATOR)
	XML_SYMBOLS_REGEXP         = regexp.MustCompile(`[=]`)
	//FORMULA_SYMBOLS_REGEXP     = regexp.MustCompile(`([=][=][=])|([<>=!:][=])|([&][&])|([|][|])|([!][!])|([?][?])|([!<>=:,;{}()[\]+*/\-?])`)
	JS_SYMBOLS_REGEXP       = regexp.MustCompile(`([>][>][>][=])|([=!][=][=])|([*][*][=])|([<][<][=])|([>][>][=])|([>][>][>])|([<>=!:+\-*/%&|^][=])|([*][*])|([&][&])|([<][<])|([>=][>])|([|][|])|([+][+])|([:][:])|([\-][\-])|([!<>=:,;{}()[\]+*/\-?%\.&|^~])`)
	MATH_SYMBOLS_REGEXP     = regexp.MustCompile(`([>][>])|([<][<])|([/][/])|([-=][>])|([!<>=~]?[=])|([{}()[\]+\-<>*/\.^_=,])`)
	GLSL_SYMBOLS_REGEXP     = regexp.MustCompile(`([+][+])|([-][-])|([&][&])|([|][|])|([<>!=*+\-][=])|([#:!<>;{}()[\]/\-\.+*=,])`)
	TEMPLATE_SYMBOLS_REGEXP = regexp.MustCompile(`([=][=][=])|([|*~<>=!:^][=])|([&][&])|([|][|])|([!][!])|([?][?])|([!<>=:,;{}()[\]+*/\-?$@\.#])`)
	//CSS_SYMBOLS_REGEXP        = regexp.MustCompile(`([:][:])|([^$][=])|([:+>~()[\]*,=])`)
	CSS_SYMBOLS_REGEXP = regexp.MustCompile(`([:][:])|([*|$~^][=])|([:+>~()[\]*,=])`)

	XML_WORD_REGEXP                 = regexp.MustCompile(`[a-zA-Z_][0-9A-Za-z_\-.:]*\b`)
	MATH_WORD_REGEXP                = regexp.MustCompile(`[a-zA-Z_][0-9A-Za-z_\-.:]*\b`)
	TEMPLATE_WORD_REGEXP            = regexp.MustCompile(`[a-zA-Z_][0-9A-Za-z_\-.]*\b`)
	JS_WORD_REGEXP                  = regexp.MustCompile(`^[a-zA-Z_][0-9A-Za-z_]*$`)
	XML_WORD_OR_LITERAL_REGEXP      = regexp.MustCompile(`[!]?[A-Za-z_]+[0-9A-Za-z_\-.:]*`)
	TEMPLATE_WORD_OR_LITERAL_REGEXP = regexp.MustCompile(`([#][0-9a-fA-F]{8})|([#][0-9a-fA-F]{6})|([#][0-9a-fA-F]{4})|([#][0-9a-fA-F]{3})|([0-9A-Za-z_]+[0-9A-Za-z_\-%\.]*)`)
	//FORMULA_WORD_OR_LITERAL_REGEXP = regexp.MustCompile(`[!#$]?[0-9A-Za-z_]+[0-9A-Za-z_\-.%]*`)
	GLSL_WORD_REGEXP           = JS_WORD_REGEXP
	CSS_WORD_REGEXP            = regexp.MustCompile(`[a-zA-Z0-9\-#\._]+\b`)
	CSS_WORD_OR_LITERAL_REGEXP = CSS_WORD_REGEXP

	// must match hex before number (because otherwise the '0' before the 'x' becomes a token by itself)
	JS_WORD_OR_LITERAL_REGEXP   = regexp.MustCompile(`([A-Za-z_$]+[0-9A-Za-z_]*)|(0x[0-9a-fA-F]+)|([0-9]+(\.[0-9]+)?(e[\-+]?[0-9]+)?)`)
	GLSL_WORD_OR_LITERAL_REGEXP = JS_WORD_OR_LITERAL_REGEXP

	MATH_WORD_OR_LITERAL_REGEXP = regexp.MustCompile(`([A-Za-z]+[A-Za-z]*)|([0-9]+[0-9\-.]*[a-zA-Z]*)`)

	JS_STRING_TEMPLATE_START_REGEXP = regexp.MustCompile(`([$][{])`)
	JS_STRING_TEMPLATE_STOP_REGEXP  = regexp.MustCompile(`([}])`)
	// user variables can't contain namespace separators (i.e. dots)
	VALID_VAR_NAME_REGEXP = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_\-]*$`)

	JS_UNIVERSAL_CLASS_NAME_REGEXP = regexp.MustCompile(`^[A-Z][a-zA-Z]*$`)

	TEMPLATE_SUPER_REGEXP            = regexp.MustCompile(`\bsuper[\s]*[(]`)
	TEMPLATE_NAME_REGEXP             = regexp.MustCompile(`\b[a-zA-Z_][a-zA-Z0-9_]*\b`)
	TEMPLATE_EXTENDS_TO_SUPER_REGEXP = regexp.MustCompile(`\b(extends[\s]*[=].*)super`)

	CSS_PLAIN_CLASS_REGEXP = regexp.MustCompile(`^[\.][a-zA-Z_\-0-9]*$`)
)

Functions

func EndsWithDigit

func EndsWithDigit(s string) bool

func ExtractUnit

func ExtractUnit(s string) (string, bool)

func IsBool

func IsBool(s string) bool

func IsCSSWord added in v0.4.0

func IsCSSWord(s string) bool

func IsColor

func IsColor(s string) bool

func IsCompactSelfClosing

func IsCompactSelfClosing(name string) bool

func IsFloat

func IsFloat(s string) bool

includes units

func IsGLSLWord

func IsGLSLWord(s string) bool

func IsHex

func IsHex(s string) bool

func IsInt

func IsInt(s string) bool

func IsJSWord

func IsJSWord(s string) bool

func IsMathWord added in v0.3.0

func IsMathWord(s string) bool

func IsNull

func IsNull(s string) bool

func IsPlainFloat

func IsPlainFloat(s string) bool

func IsSelfClosing

func IsSelfClosing(name string, close string) bool

func IsSimpleWord

func IsSimpleWord(s string) bool

func IsTemplateWord added in v0.3.0

func IsTemplateWord(s string) bool

func IsValidFun

func IsValidFun(s string) bool

func IsValidVar

func IsValidVar(s string) bool

func IsXMLWord added in v0.3.0

func IsXMLWord(s string) bool

func NewGroup

func NewGroup(start, stop string) *groupData

func NewScriptTagGroup added in v0.5.0

func NewScriptTagGroup(name string) *scriptTagGroup

func NewTagGroup

func NewTagGroup(name string) *tagGroup

func StartsWithDigit

func StartsWithDigit(s string) bool

Types

type Group

type Group interface {
	Start() string
	Stop() string
	MatchStart(s string) bool
	MatchStop(s string) bool
	StartStopRegexp() *regexp.Regexp // XXX: don't allow access to this
	IsTagGroup() bool
}

type NameGenerator

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

func NewCustomStartNameGenerator

func NewCustomStartNameGenerator(allowCompactNaming bool, start int, name string) *NameGenerator

func NewNameGenerator

func NewNameGenerator(allowCompactNaming bool, name string) *NameGenerator

func (*NameGenerator) GenName

func (ng *NameGenerator) GenName() string

Jump to

Keyboard shortcuts

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