parse

package
v0.0.0-...-093a1a0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Overview

Package parse parses an assembly program into an AST.

Index

Examples

Constants

View Source
const (
	Keyword = iota
	Operand
	String
	Lbrace
	Rbrace
	Endl
	Semi
)

asm8 token types.

Variables

View Source
var Types = func() *lexing.Types {
	ret := lexing.NewTypes()
	o := func(t int, name string) {
		ret.Register(t, name)
	}

	o(Keyword, "keyword")
	o(Operand, "operand")
	o(Lbrace, "'{'")
	o(Rbrace, "'}'")
	o(String, "string")
	o(Semi, "';'")
	o(Endl, "end-line")

	return ret
}()

Types provides a type name querier

Functions

func BareFunc

func BareFunc(f string, rc io.ReadCloser) (*ast.Func, []*lexing.Error)

BareFunc parses a file as a bare function.

func File

func File(f string, rc io.ReadCloser) (*ast.File, []*lexing.Error)

File function parses a file into an AST.

func IsIdent

func IsIdent(id string) bool

IsIdent checks if a string is a valid identifier

func Tokens

func Tokens(f string, r io.Reader) ([]*lexing.Token, []*lexing.Error)

Tokens parses a file in a token array

Example (Badcomment)
o(`/*some comment`)
Output:

t.s8:1: unexpected eof in block comment
1 error(s)
Example (Badstr1)
o(`"some string`)
Output:

t.s8:1: unexpected eof in string
1 error(s)
Example (Badstr2)
o("\"some string\n")
Output:

t.s8:1: unexpected endl in string
1 error(s)
Example (Case1)
o("\n")
Output:

t.s8:1: endl
t.s8:1: eof
Example (Case2)
o("")
Output:

t.s8:1: eof
Example (Case3)
o("func a { // comment \n\tsyscall\n}")
Output:

t.s8:1: kw - "func"
t.s8:1: op - "a"
t.s8:1: lb
t.s8:1: cm - "// comment "
t.s8:1: endl
t.s8:2: op - "syscall"
t.s8:2: endl
t.s8:3: rb
t.s8:3: eof
Example (Case4)
o("func a{}")
// Output
// t.s8:1: kw - "func"
// t.s8:1: op - "a"
// t.s8:1: lb
// t.s8:1: rb
Output:

Example (Comments)
o("// line comment \n /* block comment */")
Output:

t.s8:1: cm - "// line comment "
t.s8:1: endl
t.s8:2: cm - "/* block comment */"
t.s8:2: eof
Example (Keywords)
o("func var const import")
Output:

t.s8:1: kw - "func"
t.s8:1: kw - "var"
t.s8:1: kw - "const"
t.s8:1: kw - "import"
t.s8:1: eof
Example (String)
o("\"some string \\\"\\\\ here\"")
Output:

t.s8:1: str - "\"some string \\\"\\\\ here\""
t.s8:1: eof

func TypeStr

func TypeStr(t int) string

TypeStr returns the name of a token type.

Types

type Result

type Result struct {
	File   *ast.File
	Tokens []*lexing.Token
}

Result is a file parsing result

func FileResult

func FileResult(f string, rc io.ReadCloser) (*Result, []*lexing.Error)

FileResult returns a parsing result.

Jump to

Keyboard shortcuts

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