...

Package parser

import "github.com/noirbizarre/gonja/parser"
Overview
Index

Overview ▾

Index ▾

func BinOp(token *tokens.Token) *nodes.BinOperator
func Parse(input string) (*nodes.Template, error)
type Parser
    func NewParser(name string, cfg *config.Config, stream *tokens.Stream) *Parser
    func (p *Parser) Consume()
    func (p *Parser) Current() *tokens.Token
    func (p *Parser) End() bool
    func (p *Parser) Error(msg string, token *tokens.Token) error
    func (p *Parser) Match(types ...tokens.Type) *tokens.Token
    func (p *Parser) MatchName(names ...string) *tokens.Token
    func (p *Parser) Next() *tokens.Token
    func (p *Parser) Parse() (*nodes.Template, error)
    func (p *Parser) ParseComment() (*nodes.Comment, error)
    func (p *Parser) ParseExpression() (nodes.Expression, error)
    func (p *Parser) ParseExpressionNode() (nodes.Node, error)
    func (p *Parser) ParseFilter() (*nodes.FilterCall, error)
    func (p *Parser) ParseFilterExpression(expr nodes.Expression) (nodes.Expression, error)
    func (p *Parser) ParseLogicalExpression() (nodes.Expression, error)
    func (p *Parser) ParseMath() (nodes.Expression, error)
    func (p *Parser) ParseMathPrioritary() (nodes.Expression, error)
    func (p *Parser) ParsePower() (nodes.Expression, error)
    func (p *Parser) ParseStatement() (nodes.Statement, error)
    func (p *Parser) ParseStatementBlock() (*nodes.StatementBlock, error)
    func (p *Parser) ParseTemplate() (*nodes.Template, error)
    func (p *Parser) ParseTest(expr nodes.Expression) (nodes.Expression, error)
    func (p *Parser) ParseVariable() (nodes.Expression, error)
    func (p *Parser) ParseVariableOrLiteral() (nodes.Expression, error)
    func (p *Parser) Peek(types ...tokens.Type) *tokens.Token
    func (p *Parser) PeekName(names ...string) *tokens.Token
    func (p *Parser) Pop() *tokens.Token
    func (p *Parser) SkipUntil(names ...string) error
    func (p *Parser) WrapUntil(names ...string) (*nodes.Wrapper, *Parser, error)
type StatementParser
type TemplateParser

Package files

comment.go error.go expression.go filters.go logic.go math.go parser.go statement.go template.go tests.go variable.go

func BinOp

func BinOp(token *tokens.Token) *nodes.BinOperator

func Parse

func Parse(input string) (*nodes.Template, error)

type Parser

The parser provides you a comprehensive and easy tool to work with the template document and arguments provided by the user for your custom tag.

The parser works on a token list which will be provided by gonja. A token is a unit you can work with. Tokens are either of type identifier, string, number, keyword, HTML or symbol.

(See Token's documentation for more about tokens)

type Parser struct {
    Name   string
    Stream *tokens.Stream
    Config *config.Config

    Template       *nodes.Template
    Statements     map[string]StatementParser
    Level          int8
    TemplateParser TemplateParser
}

func NewParser

func NewParser(name string, cfg *config.Config, stream *tokens.Stream) *Parser

func (*Parser) Consume

func (p *Parser) Consume()

Consume one token. It will be gone forever.

func (*Parser) Current

func (p *Parser) Current() *tokens.Token

Current returns the current token.

func (*Parser) End

func (p *Parser) End() bool

func (*Parser) Error

func (p *Parser) Error(msg string, token *tokens.Token) error

Error produces a nice error message and returns an error-object. The 'token'-argument is optional. If provided, it will take the token's position information. If not provided, it will automatically use the CURRENT token's position information.

func (*Parser) Match

func (p *Parser) Match(types ...tokens.Type) *tokens.Token

Match returns the CURRENT token if the given type matches. Consumes this token on success.

func (*Parser) MatchName

func (p *Parser) MatchName(names ...string) *tokens.Token

func (*Parser) Next

func (p *Parser) Next() *tokens.Token

Next returns and consume the current token

func (*Parser) Parse

func (p *Parser) Parse() (*nodes.Template, error)

func (*Parser) ParseComment

func (p *Parser) ParseComment() (*nodes.Comment, error)

func (*Parser) ParseExpression

func (p *Parser) ParseExpression() (nodes.Expression, error)

ParseExpression parses an expression with optionnal filters Nested expression shoulds call this method

func (*Parser) ParseExpressionNode

func (p *Parser) ParseExpressionNode() (nodes.Node, error)

func (*Parser) ParseFilter

func (p *Parser) ParseFilter() (*nodes.FilterCall, error)

Filter = IDENT | IDENT ":" FilterArg | IDENT "|" Filter

func (*Parser) ParseFilterExpression

func (p *Parser) ParseFilterExpression(expr nodes.Expression) (nodes.Expression, error)

ParseFilterExpression parses an optionnal filter chain for a node

func (*Parser) ParseLogicalExpression

func (p *Parser) ParseLogicalExpression() (nodes.Expression, error)

func (*Parser) ParseMath

func (p *Parser) ParseMath() (nodes.Expression, error)

func (*Parser) ParseMathPrioritary

func (p *Parser) ParseMathPrioritary() (nodes.Expression, error)

func (*Parser) ParsePower

func (p *Parser) ParsePower() (nodes.Expression, error)

func (*Parser) ParseStatement

func (p *Parser) ParseStatement() (nodes.Statement, error)

Tag = "{%" IDENT ARGS "%}"

func (*Parser) ParseStatementBlock

func (p *Parser) ParseStatementBlock() (*nodes.StatementBlock, error)

func (*Parser) ParseTemplate

func (p *Parser) ParseTemplate() (*nodes.Template, error)

func (*Parser) ParseTest

func (p *Parser) ParseTest(expr nodes.Expression) (nodes.Expression, error)

func (*Parser) ParseVariable

func (p *Parser) ParseVariable() (nodes.Expression, error)

func (*Parser) ParseVariableOrLiteral

func (p *Parser) ParseVariableOrLiteral() (nodes.Expression, error)

IDENT | IDENT.(IDENT|NUMBER)...

func (*Parser) Peek

func (p *Parser) Peek(types ...tokens.Type) *tokens.Token

Peek returns the next token without consuming the current if it matches one of the given types

func (*Parser) PeekName

func (p *Parser) PeekName(names ...string) *tokens.Token

func (*Parser) Pop

func (p *Parser) Pop() *tokens.Token

Pop returns the current token and advance to the next

func (*Parser) SkipUntil

func (p *Parser) SkipUntil(names ...string) error

Skips all nodes between starting tag and "{% endtag %}"

func (*Parser) WrapUntil

func (p *Parser) WrapUntil(names ...string) (*nodes.Wrapper, *Parser, error)

WrapUntil wraps all nodes between starting tag and "{% endtag %}" and provides one simple interface to execute the wrapped nodes. It returns a parser to process provided arguments to the tag.

type StatementParser

type StatementParser func(parser *Parser, args *Parser) (nodes.Statement, error)

type TemplateParser

type TemplateParser func(string) (*nodes.Template, error)