parser

package
v3.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package parser is a parser for MiGo (mini-go calculus) types.

A MiGo type can be obtained from an io.Reader by calling the Parse function.

p := parser.Parse(strings.NewReader("   def main(): send ch;   "))

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(r io.Reader) (*migo.Program, error)

Parse is the entry point to the migo type parser

Example

This example demonstrates the use of the Parser. The output should be exactly the same as input (but pretty printed).

s := `def main.main(): let ch = newchan ch, 0; spawn main.sndr(ch); recv ch;
	def main.sndr(ch): send ch;`
r := strings.NewReader(s)
parsed, err := Parse(r)
if err != nil {
	log.Fatal(err)
}
fmt.Println(parsed.String())
Output:

def main.main():
    let ch = newchan ch, 0;
    spawn main.sndr(ch);
    recv ch;
def main.sndr(ch):
    send ch;

Types

type ConstToken

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

ConstToken is a normal constant token.

func (*ConstToken) EndPos

func (t *ConstToken) EndPos() TokenPos

EndPos returns ending position of token.

func (*ConstToken) StartPos

func (t *ConstToken) StartPos() TokenPos

StartPos returns starting position of token.

func (*ConstToken) Tok

func (t *ConstToken) Tok() Tok

Tok returns the token id.

type DigitsToken

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

DigitsToken is a token with numeric value (Digits).

func (*DigitsToken) EndPos

func (t *DigitsToken) EndPos() TokenPos

EndPos returns ending position of token.

func (*DigitsToken) StartPos

func (t *DigitsToken) StartPos() TokenPos

StartPos returns starting position of token.

func (*DigitsToken) Tok

func (t *DigitsToken) Tok() Tok

Tok returns tDIGITS.

type ErrParse

type ErrParse struct {
	Pos TokenPos
	Err string // Error string returned from parser.
}

ErrParse is a parse error.

func (*ErrParse) Error

func (e *ErrParse) Error() string

type IdentToken

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

IdentToken is a token with string value (Ident).

func (*IdentToken) EndPos

func (t *IdentToken) EndPos() TokenPos

EndPos returns ending position of token.

func (*IdentToken) StartPos

func (t *IdentToken) StartPos() TokenPos

StartPos returns starting position of token.

func (*IdentToken) Tok

func (*IdentToken) Tok() Tok

Tok returns tIDENT.

type Lexer

type Lexer struct {
	Errors chan error
	// contains filtered or unexported fields
}

Lexer for migo.

func NewLexer

func NewLexer(r io.Reader) *Lexer

NewLexer returns a new yacc-compatible lexer.

func (*Lexer) Error

func (l *Lexer) Error(err string)

Error handles error.

func (*Lexer) Lex

func (l *Lexer) Lex(yylval *migoSymType) int

Lex is provided for yacc-compatible parser.

type Scanner

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

Scanner is a lexical scanner.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

func (s *Scanner) Scan() Token

Scan returns the next token and parsed value.

type Tok

type Tok int

Tok is a lexical token.

type Token

type Token interface {
	Tok() Tok
	StartPos() TokenPos
	EndPos() TokenPos
}

Token is a token with metadata.

type TokenPos

type TokenPos struct {
	Char  int
	Lines []int
}

TokenPos is a pair of coordinate to identify start of token.

func (TokenPos) String

func (p TokenPos) String() string

Jump to

Keyboard shortcuts

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