cpp

package
v0.0.0-...-cfd4396 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Single char tokens are themselves.
	ADD       = '+'
	SUB       = '-'
	MUL       = '*'
	QUO       = '/'
	REM       = '%'
	AND       = '&'
	OR        = '|'
	XOR       = '^'
	QUESTION  = '?'
	HASH      = '#'
	LSS       = '<'
	GTR       = '>'
	ASSIGN    = '='
	NOT       = '!'
	BNOT      = '~'
	LPAREN    = '('
	LBRACK    = '['
	LBRACE    = '{'
	COMMA     = ','
	PERIOD    = '.'
	RPAREN    = ')'
	RBRACK    = ']'
	RBRACE    = '}'
	SEMICOLON = ';'
	COLON     = ':'

	ERROR = 10000 + iota
	EOF
	//some cpp only tokens
	FUNCLIKE_DEFINE //Occurs after ident before paren #define ident(
	DIRECTIVE       //#if #include etc
	END_DIRECTIVE   //New line at the end of a directive
	HEADER
	// Identifiers and basic type literals
	// (these tokens stand for classes of literals)
	IDENT          // main
	INT_CONSTANT   // 12345
	FLOAT_CONSTANT // 123.45
	CHAR_CONSTANT  // 'a'
	STRING         // "abc"

	SHL        // <<
	SHR        // >>
	ADD_ASSIGN // +=
	SUB_ASSIGN // -=
	MUL_ASSIGN // *=
	QUO_ASSIGN // /=
	REM_ASSIGN // %=
	AND_ASSIGN // &=
	OR_ASSIGN  // |=
	XOR_ASSIGN // ^=
	SHL_ASSIGN // <<=
	SHR_ASSIGN // >>=
	LAND       // &&
	LOR        // ||
	ARROW      // ->
	INC        // ++
	DEC        // --
	EQL        // ==
	NEQ        // !=
	LEQ        // <=
	GEQ        // >=
	ELLIPSIS   // ...

	// Keywords
	REGISTER
	EXTERN
	STATIC
	SHORT
	BREAK
	CASE
	DO
	CONST
	CONTINUE
	DEFAULT
	ELSE
	FOR
	WHILE
	GOTO
	IF
	RETURN
	STRUCT
	UNION
	VOLATILE
	SWITCH
	TYPEDEF
	SIZEOF
	VOID
	CHAR
	INT
	FLOAT
	DOUBLE
	SIGNED
	UNSIGNED
	LONG
)

The list of tokens.

Variables

This section is empty.

Functions

func ErrWithLoc

func ErrWithLoc(e error, pos FilePos) error

Types

type ErrorLoc

type ErrorLoc struct {
	Err error
	Pos FilePos
}

func (ErrorLoc) Error

func (e ErrorLoc) Error() string

type FilePos

type FilePos struct {
	File string
	Line int
	Col  int
}

func (FilePos) String

func (pos FilePos) String() string

type IncludeSearcher

type IncludeSearcher interface {
	//IncludeQuote is invoked when the preprocessor
	//encounters an include of the form #include "foo.h".
	//returns the full path of the file, a reader of the contents or an error.
	IncludeQuote(requestingFile, headerPath string) (string, io.Reader, error)
	//IncludeAngled is invoked when the preprocessor
	//encounters an include of the form #include <foo.h>.
	//returns the full path of the file, a reader of the contents or an error.
	IncludeAngled(requestingFile, headerPath string) (string, io.Reader, error)
}

func NewStandardIncludeSearcher

func NewStandardIncludeSearcher(includePaths string) IncludeSearcher

A ; seperated list of paths

type Lexer

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

func Lex

func Lex(fname string, r io.Reader) *Lexer

Lex starts a goroutine which lexes the contents of the reader. fname is used for error messages when showing the source location. No preprocessing is done, this is just pure reading of the unprocessed source file. The goroutine will not stop until all tokens are read

func (*Lexer) Error

func (lx *Lexer) Error(e string)

func (*Lexer) Next

func (lx *Lexer) Next() (*Token, error)

type Preprocessor

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

func New

func New(l *Lexer, is IncludeSearcher) *Preprocessor

func (*Preprocessor) Next

func (pp *Preprocessor) Next() (t *Token, err error)

type StandardIncludeSearcher

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

func (*StandardIncludeSearcher) IncludeAngled

func (is *StandardIncludeSearcher) IncludeAngled(requestingFile, headerPath string) (string, io.Reader, error)

func (*StandardIncludeSearcher) IncludeQuote

func (is *StandardIncludeSearcher) IncludeQuote(requestingFile, headerPath string) (string, io.Reader, error)

type Token

type Token struct {
	Kind TokenKind
	Val  string
	Pos  FilePos
	// contains filtered or unexported fields
}

Token represents a grouping of characters that provide semantic meaning in a C program.

func (Token) String

func (t Token) String() string

type TokenKind

type TokenKind uint32

func (TokenKind) String

func (tk TokenKind) String() string

Jump to

Keyboard shortcuts

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