scanner

package
v0.0.0-...-1bfbc23 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TEXT = iota + 1
	HASH
	EQUALS
	UNDERSCORE
	TILDE
	STAR
	NEWLINE
	DASH
	DOLLAR
	STRAIGHTBRACEOPEN
	STRAIGHTBRACECLOSE
	PARENOPEN
	PARENCLOSE
	BACKTICK
	GREATERTHAN
	BANG
	EMPTYLINE
	EOF
)

TODO: add tabs

Variables

View Source
var TOKEN_LOOKUP_MAP = map[uint]string{
	DOLLAR:             "DOLLAR",
	EQUALS:             "EQUALS",
	TILDE:              "TILDE",
	HASH:               "HASH",
	UNDERSCORE:         "UNDERSCORE",
	STAR:               "STAR",
	NEWLINE:            "NEWLINE",
	DASH:               "DASH",
	STRAIGHTBRACEOPEN:  "STRAIGHTBRACEOPEN",
	STRAIGHTBRACECLOSE: "STRAIGHTBRACECLOSE",
	PARENOPEN:          "PARENOPEN",
	PARENCLOSE:         "PARENCLOSE",
	GREATERTHAN:        "GREATERTHAN",
	BACKTICK:           "BACKTICK",
	TEXT:               "TEXT",
	BANG:               "BANG",
	EMPTYLINE:          "EMPTYLINE",
	EOF:                "EOF",
}
View Source
var TOKEN_SYMBOL_MAP = map[uint]rune{
	HASH:               '#',
	EQUALS:             '=',
	TILDE:              '~',
	DOLLAR:             '$',
	UNDERSCORE:         '_',
	STAR:               '*',
	NEWLINE:            '\n',
	DASH:               '-',
	STRAIGHTBRACEOPEN:  '[',
	STRAIGHTBRACECLOSE: ']',
	PARENOPEN:          '(',
	PARENCLOSE:         ')',
	GREATERTHAN:        '>',
	BACKTICK:           '`',
	BANG:               '!',
	EMPTYLINE:          '\n',
	EOF:                0,
}

Functions

func PrintToken

func PrintToken(token Token)

performs a lookup for the token.Kind and prints the token data

Types

type Scanner

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

func New

func New(fileName string) Scanner

Returns a new instance of scanner.Scanner. To do so, it opens the file, creates a bufio.Scanner with it, scans the first line and assigns all values in the scanner.Scanner struct accordingly

func (*Scanner) Lex

func (s *Scanner) Lex() []Token

parses the file given to the Scanner line by line

func (*Scanner) PrintTokens

func (s *Scanner) PrintTokens()

prints all tokens currently scanned

type Token

type Token struct {
	Pos   uint
	Kind  uint
	Line  uint
	Value string
}

Jump to

Keyboard shortcuts

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