agora: github.com/PuerkitoBio/agora/compiler/parser Index | Files

package parser

import "github.com/PuerkitoBio/agora/compiler/parser"

Package parser provides the agora source code parser. It is a top-down operator precedence parser, based on this article from Douglas Crockford.

http://javascript.crockford.com/tdop/tdop.html

Index

Package Files

grammar.go parser.go scope.go symbol.go

type Arity Uses

type Arity int

An Arity is loosely used to indicate the components of a parsed Symbol.

const (
    // Initial possible arities, until we know more about the context
    ArName Arity = iota
    ArLiteral
    ArOperator

    // Then it can be set to something more precise
    ArUnary
    ArBinary
    ArTernary
    ArStatement
    ArThis
    ArFunction
    ArImport
)

func (Arity) String Uses

func (ar Arity) String() string

String returns the literal representation of an Arity.

type Parser Uses

type Parser struct {

    // Exported fields
    Debug bool
    // contains filtered or unexported fields
}

A Parser is an agora source code parser.

func New Uses

func New() *Parser

New returns a new parser, initialized with its scanner.Scanner.

func (*Parser) Parse Uses

func (p *Parser) Parse(filename string, src []byte) ([]*Symbol, *Scope, error)

Parse the provided source code and returns the AST along with the various scopes and an error (corresponding to the scanner.ErrorList).

type Scope Uses

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

A Scope holds the valid identifiers. In agora, the only scopes are the functions, so each function starts a new scope, and the top-level code is in an implicit top-level function (and thus scope).

type Symbol Uses

type Symbol struct {
    Id   string
    Val  interface{}
    Name string
    Key  interface{}

    Ar  Arity

    First  interface{} // May all be []*Symbol or *Symbol
    Second interface{}
    Third  interface{}
    // contains filtered or unexported fields
}

A Symbol represents a node in the abstract syntax tree generated by the parser. It holds the required information - operands, children, etc. - to generate the bytecode instructions.

func (*Symbol) String Uses

func (s *Symbol) String() string

String returns a literal string representation of the Symbol.

Package parser imports 5 packages (graph) and is imported by 26 packages. Updated 2016-07-21. Refresh now. Tools for package owners.