Documentation ¶
Overview ¶
Package scan implements a scanner for the SubC language. It takes an interface that can return bytes and transforms it into tokens.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( NoSpan = Span{} // A zero value for span, considered to be invalid span. NoPos = scanner.Position{} // A zero value for position, considered to be an invalid position. )
var DefaultConfig = Config{ ApplyPreprocessor: true, Loader: fileLoader{}, MaxIncludes: 16, Macros: [][2]string{ {"__SUBC__", ""}, {"__" + runtime.GOOS + "__", ""}, {"__DATE__", "\"" + time.Now().Format("Jan 2 2006") + "\""}, {"__TIME__", "\"" + time.Now().Format("15:04:05") + "\""}, }, ScanComments: false, }
DefaultConfig specifies a reasonable default for the scanner. It is intended to be extended by making a copy of this struct and then customizing some of the fields.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ApplyPreprocessor bool // applies the preprocessor upon encountering macros Loader Loader // the loader interface is used for loading include files MaxIncludes int // max number of nested includes during macro expansion before aborting IncludePaths []string // paths to look for include files Macros [][2]string // macro definitions in the form of (macro, text expansion) ScanComments bool // scan comments as tokens when turned on, otherwise it is ignored // contains filtered or unexported fields }
Config specifies the behavior of the scanner.
type ErrorList ¶
type ErrorList struct { Messages []ErrorMessage NumWarnings int NumErrors int }
ErrorList keeps a list of error messages
func (*ErrorList) Add ¶
func (l *ErrorList) Add(msg ErrorMessage)
type ErrorMessage ¶
ErrorMessage is a struct that contains the error message and whether or not if it is critical.
func (ErrorMessage) Error ¶
func (e ErrorMessage) Error() string
type Reader ¶
Reader is an interface that provides input to the scanner.
type Scanner ¶
type Scanner struct { Tokens chan Token // channel used for returning tokens. // contains filtered or unexported fields }
Scanner is the scanner structure for scanning tokens.
func New ¶
New returns a scanner for reading tokens using name as the filename identifier and r as a reader. It starts a goroutine and runs concurrently to get the next token which must be drained by user.
type Token ¶
func (Token) Precedence ¶
Precedence returns the operator precedence of a given operator. The operators covered are not the full set, because some of them need more context like whether or not it is prefix/postfix/unary, If op is not an arithmetic or logical operator, it returns the lowest precedence.
type Type ¶
type Type int
Type is a token type.
const ( EOF Type = iota Error Warning Comment Preprocessor Pragma Div Mul Mod Plus Minus Lsh Rsh Gt Geq Lt Leq Eq Neq And Xor Or Land Lor Arrow AndEq XorEq LshEq MinusEq ModEq OrEq PlusEq RshEq DivEq MulEq Assign Auto Break Case Char Colon Comma Const Continue Dec Default Do Dot Double Ellipsis Else Enum Extern Float For Goto Ident If Inc Inline Int Lbrace Lbrack Long Lparen Not Qmark Rbrace Rbrack Register Restrict Return Rparen Semi Short Signed Sizeof Static Struct Switch Typedef Negate Union Unsigned Void Volatile While Alignas Alignof Atomic Bool Complex Generic Imaginary Noreturn Static_assert Thread_local Number Rune String )
All of the token types.