token

package
Version: v0.0.0-...-952fa56 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2015 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TokenList []string
View Source
var TokenMap = map[string]Token{}/* 133 elements not displayed */

TokenMap maps source code string tokens to types when strings can be represented directly. Not all types will be represented here.

Functions

func NewList

func NewList(t ...Item) *itemList

NewList initializes a new ItemList

Types

type Item

type Item struct {
	Typ        Token
	Begin, End Position
	Val        string
}

Item represents a lexed item.

func Keyword

func Keyword(t Token) Item

func NewItem

func NewItem(t Token, v string) Item

func (Item) Position

func (i Item) Position() Position

func (Item) String

func (i Item) String() string

String renders a string representation of the item.

type Position

type Position struct {
	Line, Column int // The position relative to other characters in the file
	Position     int // The position in bytes in the file
	File         string
}

type Stream

type Stream interface {
	// Next consumes and returns the next item in the stream. If there is no next
	// item, the zero value is returned.
	Next() Item

	// Previous consumes and returns the previous item in the stream. i.e.
	//
	// 	a := s.Next()
	//	b := s.Previous()
	//	c := s.Next()
	//	a == b == c // true
	//
	// If there is no previous item, the zero value is returned.
	Previous() Item
}

Stream is an ordered set of tokens

func Subset

func Subset(s Stream, t Type) Stream

Subset returns a stream that emits only tokens from s that are of Type t. If s is already a subset, it is re-expanded before the new subset is created.

type Token

type Token int
const (
	EOF Token = iota
	HTML
	PHPBegin
	PHPEnd
	PHPToken
	Error
	Space
	Function
	Static
	Self
	Parent
	Final
	FunctionName
	TypeHint
	VariableOperator
	BlockBegin
	BlockEnd
	Global

	Namespace
	Use

	CommentLine
	CommentBlock

	IgnoreErrorOperator

	Return
	Comma
	StatementEnd
	Echo
	Print

	If
	Else
	ElseIf
	For
	Foreach
	EndIf
	EndFor
	EndForeach
	EndWhile
	EndSwitch
	AsOperator
	While
	Continue
	Break
	Do
	OpenParen
	CloseParen
	Switch
	Case
	Default

	Try
	Catch
	Finally
	Throw

	Class
	Abstract
	Private
	Public
	Protected
	Interface
	Implements
	Extends
	NewOperator
	Const

	Null
	StringLiteral
	NumberLiteral
	BooleanLiteral

	ShellCommand

	Identifier

	AssignmentOperator
	NegationOperator
	AdditionOperator
	SubtractionOperator
	MultOperator
	ConcatenationOperator
	UnaryOperator
	ComparisonOperator
	InstanceofOperator

	AndOperator
	OrOperator
	WrittenAndOperator
	WrittenXorOperator
	WrittenOrOperator

	ObjectOperator
	ScopeResolutionOperator

	CastOperator

	Var
	Array
	ArrayKeyOperator
	ArrayLookupOperatorLeft
	ArrayLookupOperatorRight
	List
	BitwiseShiftOperator
	StrongEqualityOperator
	StrongNotEqualityOperator
	EqualityOperator
	NotEqualityOperator
	AmpersandOperator
	BitwiseXorOperator
	BitwiseOrOperator
	BitwiseNotOperator
	TernaryOperator1
	TernaryOperator2

	Declare

	Include
	Exit
)

func (Token) String

func (i Token) String() string

func (Token) Type

func (t Token) Type() Type

Type returns the type of t.

type Type

type Type int

Type is a bitmask representing the type of a token

const (
	InvalidType Type = 1 << iota

	KeywordType    // keyword, e.g. "static", "function"
	LiteralType    // literal, e.g. 234, "a string", false
	MarkerType     // marker for code blocks and groupings, e.g. {, (
	OperatorType   // operator, e.g. +, ===, $
	IdentifierType // identifier, e.g. StdClass

	CommentType
	WhitespaceType

	Significant = KeywordType | LiteralType | MarkerType | OperatorType | IdentifierType
)

func (Type) Is

func (t Type) Is(ty Type) bool

Is returns true if ty is equal to or contained by t.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL