lex

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MulanPSL-2.0 Imports: 3 Imported by: 11

Documentation

Index

Constants

View Source
const (
	ItemBacktick       = byte('`')
	ItemTilde          = byte('~')
	ItemBang           = byte('!')
	ItemCrosshatch     = byte('#')
	ItemAsterisk       = byte('*')
	ItemOpenParen      = byte('(')
	ItemCloseParen     = byte(')')
	ItemHyphen         = byte('-')
	ItemUnderscore     = byte('_')
	ItemPlus           = byte('+')
	ItemEqual          = byte('=')
	ItemTab            = byte('\t')
	ItemOpenBracket    = byte('[')
	ItemCloseBracket   = byte(']')
	ItemDoublequote    = byte('"')
	ItemSinglequote    = byte('\'')
	ItemLess           = byte('<')
	ItemGreater        = byte('>')
	ItemSpace          = byte(' ')
	ItemNewline        = byte('\n')
	ItemCarriageReturn = byte('\r')
	ItemBackslash      = byte('\\')
	ItemSlash          = byte('/')
	ItemDot            = byte('.')
	ItemColon          = byte(':')
	ItemQuestion       = byte('?')
	ItemAmpersand      = byte('&')
	ItemSemicolon      = byte(';')
	ItemPipe           = byte('|')
	ItemDollar         = byte('$')
	ItemCaret          = byte('^')
	ItemOpenBrace      = byte('{')
	ItemCloseBrace     = byte('}')
)

Variables

This section is empty.

Functions

func Accept

func Accept(tokens []byte, token byte) (pos int)

func AcceptTokens

func AcceptTokens(remains, someTokens []byte) (pos int)

func AcceptTokenss

func AcceptTokenss(tokens []byte, someTokenss [][]byte) (pos int)

func BytesShowLength

func BytesShowLength(bytes []byte) int

BytesShowLength 获取字节数组展示为 UTF8 字符串时的长度。

func EscapeMarkers added in v1.7.5

func EscapeMarkers(tokens []byte) []byte

func EscapeProtyleMarkers added in v1.7.6

func EscapeProtyleMarkers(tokens []byte) []byte

func IsASCIILetter

func IsASCIILetter(token byte) bool

IsASCIILetter 判断 token 是否是一个 ASCII 字母。

func IsASCIILetterNum

func IsASCIILetterNum(token byte) bool

IsASCIILetterNum 判断 token 是否是一个 ASCII 字母或数字。

func IsASCIILetterNumHyphen

func IsASCIILetterNumHyphen(token byte) bool

IsASCIILetterNumHyphen 判断 token 是否是一个 ASCII 字母、数字或者横线 -。

func IsASCIILetterNums added in v1.7.5

func IsASCIILetterNums(tokens []byte) bool

IsASCIILetterNums 判断 tokens 是否是 ASCII 字母或数字组成。

func IsASCIIPunct

func IsASCIIPunct(token byte) bool

IsASCIIPunct 判断 token 是否是一个 ASCII 标点符号。

func IsBackslashEscapePunct

func IsBackslashEscapePunct(tokens []byte, pos int) bool

IsBackslashEscapePunct 判断 Tokens 中 pos 所指的值是否是由反斜杠 \ 转义的 ASCII 标点符号。

func IsBlank

func IsBlank(tokens []byte) bool

IsBlank 判断 Tokens 是否都为空格。

func IsBlankLine

func IsBlankLine(tokens []byte) bool

func IsCommonInlineMarker added in v1.7.5

func IsCommonInlineMarker(token byte) bool

func IsControl

func IsControl(token byte) bool

IsControl 判断 token 是否是一个控制字符。

func IsDigit

func IsDigit(token byte) bool

IsDigit 判断 token 是否为数字 0-9。

func IsHexDigit

func IsHexDigit(token byte) bool

IsHexDigit 判断 token 是否是十六进制数字。

func IsMarker added in v1.7.5

func IsMarker(token byte) bool

func IsProtyleInlineMarker added in v1.7.6

func IsProtyleInlineMarker(token byte) bool

func IsUnicodeWhitespace

func IsUnicodeWhitespace(r rune) bool

IsUnicodeWhitespace 判断 token 是否是 Unicode 空白。

func IsWhitespace

func IsWhitespace(token byte) bool

IsWhitespace 判断 token 是否是空白。

func Peek

func Peek(tokens []byte, pos int) byte

func RepeatBackslashBeforePipe added in v1.7.6

func RepeatBackslashBeforePipe(content string) string

func ReplaceAll

func ReplaceAll(tokens []byte, old, new byte) []byte

ReplaceAll 会将 Tokens 中的所有 old 使用 new 替换。

func ReplaceNewlineSpace

func ReplaceNewlineSpace(tokens []byte) []byte

ReplaceNewlineSpace 会将 Tokens 中的所有 "\n " 替换为 "\n"。

func Split

func Split(tokens []byte, separator byte) (ret [][]byte)

func SplitWhitespace

func SplitWhitespace(tokens []byte) (ret [][]byte)

func SplitWithoutBackslashEscape

func SplitWithoutBackslashEscape(tokens []byte, separator byte) (ret [][]byte)

SplitWithoutBackslashEscape 使用 separator 作为分隔符将 Tokens 切分为多个子串,被反斜杠 \ 转义的字符不会计入切分。

func Spnl

func Spnl(tokens []byte) (ret bool, passed, remains []byte)

func StatWhitespace

func StatWhitespace(tokens []byte) (newlines, spaces, tabs int)

func TokenToUpper

func TokenToUpper(token byte) byte

TokenToUpper 将 token 转为大写。

func Trim

func Trim(tokens []byte) (leftWhitespaces, rightWhitespaces, remains []byte)

func TrimLeft

func TrimLeft(tokens []byte) (whitespaces, remains []byte)

func TrimRight

func TrimRight(tokens []byte) (whitespaces, remains []byte)

func TrimWhitespace

func TrimWhitespace(tokens []byte) (ret []byte)

Types

type Lexer

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

Lexer 描述了词法分析器结构。

func NewLexer

func NewLexer(input []byte) (ret *Lexer)

NewLexer 创建一个词法分析器。

func (*Lexer) NextLine

func (l *Lexer) NextLine() (ret []byte)

NextLine 返回下一行。

Jump to

Keyboard shortcuts

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