token

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2019 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Overview

Package token defines a complete set of all lexical tokens for any kind of language! It is based on the alecthomas/chroma / pygments lexical tokens plus all the more detailed tokens needed for actually parsing languages

Index

Constants

This section is empty.

Variables

View Source
var CatMap map[Tokens]Tokens

CatMap is the map into the category level for each token

Categories

View Source
var KeyTokenZero = KeyToken{}
View Source
var KiT_Tokens = kit.Enums.AddEnum(TokensN, false, nil)
View Source
var Names = map[Tokens]string{}/* 125 elements not displayed */

Names are the short tag names for each token, used e.g., for syntax highlighting These are based on alecthomas/chroma / pygments

View Source
var OpPunctMap = map[string]Tokens{
	"+": OpMathAdd,
	"-": OpMathSub,
	"*": OpMathMul,
	"/": OpMathDiv,
	"%": OpMathRem,

	"&":  OpBitAnd,
	"|":  OpBitOr,
	"~":  OpBitNot,
	"^":  OpBitXor,
	"<<": OpBitShiftLeft,
	">>": OpBitShiftRight,
	"&^": OpBitAndNot,

	"=":  OpAsgnAssign,
	"++": OpAsgnInc,
	"--": OpAsgnDec,
	"<-": OpAsgnArrow,
	":=": OpAsgnDefine,

	"+=": OpMathAsgnAdd,
	"-=": OpMathAsgnSub,
	"*=": OpMathAsgnMul,
	"/=": OpMathAsgnDiv,
	"%=": OpMathAsgnRem,

	"&=":  OpBitAsgnAnd,
	"|=":  OpBitAsgnOr,
	"^=":  OpBitAsgnXor,
	"<<=": OpBitAsgnShiftLeft,
	">>=": OpBitAsgnShiftRight,
	"&^=": OpBitAsgnAndNot,

	"&&": OpLogAnd,
	"||": OpLogOr,
	"!":  OpLogNot,

	"==": OpRelEqual,
	"!=": OpRelNotEqual,
	"<":  OpRelLess,
	">":  OpRelGreater,
	"<=": OpRelLtEq,
	">=": OpRelGtEq,

	"...": OpListEllipsis,

	"(": PunctGpLParen,
	")": PunctGpRParen,
	"[": PunctGpLBrack,
	"]": PunctGpRBrack,
	"{": PunctGpLBrace,
	"}": PunctGpRBrace,

	",": PunctSepComma,
	".": PunctSepPeriod,
	";": PunctSepSemicolon,
	":": PunctSepColon,

	"\"": PunctStrDblQuote,
	"'":  PunctStrQuote,
	"`":  PunctStrBacktick,
	"\\": PunctStrEsc,
}

OpPunctMap provides a lookup of operators and punctuation tokens by their usual string representation

View Source
var SubCatMap map[Tokens]Tokens

SubCatMap is the map into the sub-category level for each token

Sub-Categories

Functions

func InitCatMap

func InitCatMap()

InitCatMap initializes the CatMap

func InitSubCatMap

func InitSubCatMap()

InitSubCatMap initializes the SubCatMap

Types

type KeyToken

type KeyToken struct {
	Tok   Tokens
	Key   string
	Depth int
}

KeyToken combines a token and an optional keyword name for Keyword token types if Tok is in Keyword category, then Key string can be used to check for same keyword. Also has a Depth for matching against a particular nesting depth

func (KeyToken) Equal

func (kt KeyToken) Equal(okt KeyToken) bool

Equal compares equality of two tokens including keywords if token is in Keyword category. See also Match for version that uses category / subcategory matching

func (KeyToken) Match

func (kt KeyToken) Match(okt KeyToken) bool

Match compares equality of two tokens including keywords if token is in Keyword category. returns true if the two tokens match, in a category / subcategory sensitive manner: if receiver token is a category, then it matches other token if it is the same category and likewise for subcategory

func (KeyToken) MatchDepth

func (kt KeyToken) MatchDepth(okt KeyToken) bool

MatchDepth compares equality of two tokens including depth -- see Match for other matching criteria

func (KeyToken) String

func (kt KeyToken) String() string

func (KeyToken) StringKey added in v0.5.5

func (kt KeyToken) StringKey() string

StringKey encodes token into a string for optimized string-based map key lookup

type KeyTokenList

type KeyTokenList []KeyToken

KeyTokenList is a list (slice) of KeyTokens

func (KeyTokenList) Match

func (kl KeyTokenList) Match(okt KeyToken) bool

Match returns true if given keytoken matches any of the items on the list

type Tokens

type Tokens int

Tokens is a complete set of lexical tokens that encompasses all programming and text markup languages. It includes everything in alecthomas/chroma (pygments) and everything needed for Go, C, C++, Python, etc.

There are categories and sub-categories, and methods to get those from a given element. The first category is 'None'.

See http://pygments.org/docs/tokens/ for more docs on the different categories

Anything missing should be added via a pull request etc

const (
	// None is the nil token value -- for non-terminal cases or TBD
	None Tokens = iota

	// Error is an input that could not be tokenized due to syntax error etc
	Error

	// EOF is end of file
	EOF

	// EOL is end of line (typically implicit -- used for rule matching)
	EOL

	// EOS is end of statement -- a key meta-token -- in C it is ;, in Go it is either ; or EOL
	EOS

	// Background is for syntax highlight styles based on these tokens
	Background

	// Cat: Keywords (actual keyword is just the string)
	Keyword
	KeywordConstant
	KeywordDeclaration
	KeywordNamespace // incl package, import
	KeywordPseudo
	KeywordReserved
	KeywordType

	// Cat: Names.
	Name
	NameBuiltin       // e.g., true, false -- builtin values..
	NameBuiltinPseudo // e.g., this, self
	NameOther
	NamePseudo

	// SubCat: Type names
	NameType
	NameClass
	NameStruct
	NameField
	NameInterface
	NameConstant
	NameEnum
	NameEnumMember
	NameArray // includes slice etc
	NameMap
	NameObject
	NameTypeParam // for generics, templates

	// SubCat: Function names
	NameFunction
	NameDecorator     // function-like wrappers in python
	NameFunctionMagic // e.g., __init__ in python
	NameMethod
	NameOperator
	NameConstructor // includes destructor..
	NameException
	NameLabel // e.g., goto label
	NameEvent // for LSP -- not really sure what it is..

	// SubCat: Scoping names
	NameScope
	NameNamespace
	NameModule
	NamePackage
	NameLibrary

	// SubCat: NameVar -- variable names
	NameVar
	NameVarAnonymous
	NameVarClass
	NameVarGlobal
	NameVarInstance
	NameVarMagic
	NameVarParam

	// SubCat: Value -- data-like elements
	NameValue
	NameTag // e.g., HTML tag
	NameProperty
	NameAttribute // e.g., HTML attr
	NameEntity    // special entities. (e.g. &nbsp; in HTML).  seems like other..

	// Cat: Literals.
	Literal
	LiteralDate
	LiteralOther
	LiteralBool

	// SubCat: Literal Strings.
	LitStr
	LitStrAffix // unicode specifiers etc
	LitStrAtom
	LitStrBacktick
	LitStrBoolean
	LitStrChar
	LitStrDelimiter
	LitStrDoc // doc-specific strings where syntactically noted
	LitStrDouble
	LitStrEscape   // esc sequences within strings
	LitStrHeredoc  // in ruby, perl
	LitStrInterpol // interpolated parts of strings in #{foo} in Ruby
	LitStrName
	LitStrOther
	LitStrRegex
	LitStrSingle
	LitStrSymbol
	LitStrFile // filename

	// SubCat: Literal Numbers.
	LitNum
	LitNumBin
	LitNumFloat
	LitNumHex
	LitNumInteger
	LitNumIntegerLong
	LitNumOct
	LitNumImag

	// Cat: Operators.
	Operator
	OperatorWord

	// SubCat: Math operators
	OpMath
	OpMathAdd // +
	OpMathSub // -
	OpMathMul // *
	OpMathDiv // /
	OpMathRem // %

	// SubCat: Bitwise operators
	OpBit
	OpBitAnd        // &
	OpBitOr         // |
	OpBitNot        // ~
	OpBitXor        // ^
	OpBitShiftLeft  // <<
	OpBitShiftRight // >>
	OpBitAndNot     // &^

	// SubCat: Assign operators
	OpAsgn
	OpAsgnAssign // =
	OpAsgnInc    // ++
	OpAsgnDec    // --
	OpAsgnArrow  // <-
	OpAsgnDefine // :=

	// SubCat: Math Assign operators
	OpMathAsgn
	OpMathAsgnAdd // +=
	OpMathAsgnSub // -=
	OpMathAsgnMul // *=
	OpMathAsgnDiv // /=
	OpMathAsgnRem // %=

	// SubCat: Bitwise Assign operators
	OpBitAsgn
	OpBitAsgnAnd        // &=
	OpBitAsgnOr         // |=
	OpBitAsgnXor        // ^=
	OpBitAsgnShiftLeft  // <<=
	OpBitAsgnShiftRight // >>=
	OpBitAsgnAndNot     // &^=

	// SubCat: Logical operators
	OpLog
	OpLogAnd // &&
	OpLogOr  // ||
	OpLogNot // !

	// SubCat: Relational operators
	OpRel
	OpRelEqual    // ==
	OpRelNotEqual // !=
	OpRelLess     // <
	OpRelGreater  // >
	OpRelLtEq     // <=
	OpRelGtEq     // >=

	// SubCat: List operators
	OpList
	OpListEllipsis // ...

	// Cat: Punctuation.
	Punctuation

	// SubCat: Grouping punctuation
	PunctGp
	PunctGpLParen // (
	PunctGpRParen // )
	PunctGpLBrack // [
	PunctGpRBrack // ]
	PunctGpLBrace // {
	PunctGpRBrace // }

	// SubCat: Separator punctuation
	PunctSep
	PunctSepComma     // ,
	PunctSepPeriod    // .
	PunctSepSemicolon // ;
	PunctSepColon     // :

	// SubCat: String punctuation
	PunctStr
	PunctStrDblQuote // "
	PunctStrQuote    // '
	PunctStrBacktick // `
	PunctStrEsc      // \

	// Cat: Comments.
	Comment
	CommentHashbang
	CommentMultiline
	CommentSingle
	CommentSpecial

	// SubCat: Preprocessor "comments".
	CommentPreproc
	CommentPreprocFile

	// Cat: Text.
	Text
	TextWhitespace
	TextSymbol
	TextPunctuation
	TextSpellErr

	// SubCat: TextStyle (corresponds to Generic in chroma / pygments) todo: look in font deco for more
	TextStyle
	TextStyleDeleted // strike-through
	TextStyleEmph    // italics
	TextStyleError
	TextStyleHeading
	TextStyleInserted
	TextStyleOutput
	TextStylePrompt
	TextStyleStrong // bold
	TextStyleSubheading
	TextStyleTraceback
	TextStyleUnderline
	TextStyleLink

	TokensN
)

The list of tokens

func (Tokens) Cat

func (tk Tokens) Cat() Tokens

Cat returns the category that a given token lives in, using CatMap

func (Tokens) ClassName

func (tk Tokens) ClassName() string

ClassName returns the . prefixed CSS classname of the tag style for styling, a CSS property should exist with this name

func (Tokens) CombineRepeats

func (tk Tokens) CombineRepeats() bool

CombineRepeats are token types where repeated tokens of the same type should be combined together -- literals, comments, text

func (*Tokens) FromString

func (i *Tokens) FromString(s string) error

func (Tokens) IconName added in v0.5.5

func (tk Tokens) IconName() string

IconName returns the appropriate icon name for the type of lexical item this is

func (Tokens) InCat

func (tk Tokens) InCat(other Tokens) bool

func (Tokens) InSubCat

func (tk Tokens) InSubCat(other Tokens) bool

func (Tokens) IsAmbigUnaryOp

func (tk Tokens) IsAmbigUnaryOp() bool

IsAmbigUnaryOp returns true if this token is an operator that could either be a Unary or Binary operator -- need special matching for this. includes * and & which are used for address operations in C-like languages

func (Tokens) IsCat

func (tk Tokens) IsCat() bool

IsCat returns true if this is a category-level token

func (Tokens) IsKeyword

func (tk Tokens) IsKeyword() bool

IsKeyword returns true if this in the Keyword category

func (Tokens) IsPunctGpLeft

func (tk Tokens) IsPunctGpLeft() bool

IsPunctGpLeft returns true if token is a PunctGpL token -- left paren, brace, bracket

func (Tokens) IsPunctGpRight

func (tk Tokens) IsPunctGpRight() bool

IsPunctGpRight returns true if token is a PunctGpR token -- right paren, brace, bracket

func (Tokens) IsSubCat

func (tk Tokens) IsSubCat() bool

IsSubCat returns true if this is a sub-category-level token

func (Tokens) IsUnaryOp added in v0.5.5

func (tk Tokens) IsUnaryOp() bool

IsUnaryOp returns true if this token is an operator that is typically used as a Unary operator: - + & * ! ^ ! <-

func (Tokens) MarshalJSON

func (ev Tokens) MarshalJSON() ([]byte, error)

func (Tokens) MarshalText

func (ev Tokens) MarshalText() ([]byte, error)

map keys require text marshaling:

func (Tokens) Match

func (tk Tokens) Match(otk Tokens) bool

Match returns true if the two tokens match, in a category / subcategory sensitive manner: if receiver token is a category, then it matches other token if it is the same category and likewise for subcategory

func (Tokens) Parent

func (tk Tokens) Parent() Tokens

Parent returns the closest parent-level of this token (subcat or cat)

func (Tokens) PunctGpMatch

func (tk Tokens) PunctGpMatch() Tokens

PunctGpMatch returns the matching token for given PunctGp token

func (Tokens) String

func (i Tokens) String() string

func (Tokens) StyleName

func (tk Tokens) StyleName() string

StyleName returns the abbreviated 2-3 letter style name of the tag

func (Tokens) SubCat

func (tk Tokens) SubCat() Tokens

SubCat returns the sub-category that a given token lives in, using SubCatMap

func (*Tokens) UnmarshalJSON

func (ev *Tokens) UnmarshalJSON(b []byte) error

func (*Tokens) UnmarshalText

func (ev *Tokens) UnmarshalText(b []byte) error

Jump to

Keyboard shortcuts

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