Documentation
¶
Index ¶
- Constants
- Variables
- func Ast(g *ogdl.Graph)
- func Precedence(s string) int
- type Parser
- func (p *Parser) ArgList() bool
- func (p *Parser) Args(dot bool) (bool, error)
- func (p *Parser) Break() bool
- func (p *Parser) Byte() (byte, bool)
- func (p *Parser) Dec()
- func (p *Parser) Emit(s string)
- func (p *Parser) End() bool
- func (p *Parser) Expression() bool
- func (p *Parser) Inc()
- func (p *Parser) Index() bool
- func (p *Parser) Level() int
- func (p *Parser) Line() string
- func (p *Parser) Number() (string, bool)
- func (p *Parser) Operator() string
- func (p *Parser) Path() bool
- func (p *Parser) PeekByte() byte
- func (p *Parser) PeekRune() (rune, bool)
- func (p *Parser) QToken(isTokenChar func(rune) bool) string
- func (p *Parser) Quoted(ind int) string
- func (p *Parser) Reset()
- func (p *Parser) Rune() (rune, bool)
- func (p *Parser) Selector() bool
- func (p *Parser) SetLevel(i int)
- func (p *Parser) Space() (int, byte)
- func (p *Parser) String() string
- func (p *Parser) Token(isTokenChar func(rune) bool) string
- func (p *Parser) TokenList(isTokenChar func(rune) bool) []string
- func (p *Parser) TokenListEv(isTokenChar func(rune) bool) bool
- func (p *Parser) UnaryExpression() bool
- func (p *Parser) UnreadByte() bool
- func (p *Parser) UnreadRune(r rune) bool
- func (p *Parser) WhiteSpace() bool
Constants ¶
const ( TypeExpression = "!e" TypePath = "!p" TypeVariable = "!v" TypeSelector = "!s" TypeIndex = "!i" TypeGroup = "!g" TypeArguments = "!a" TypeTemplate = "!t" TypeString = "!string" TypeIf = "!if" TypeEnd = "!end" TypeElse = "!else" TypeFor = "!for" TypeBreak = "!break" )
Nodes containing these strings are special
Variables ¶
var ( // ErrInvalidUnread reports an unsuccessful UnreadByte or UnreadRune ErrInvalidUnread = errors.New("invalid use of UnreadByte or UnreadRune") // ErrEOS indicates the end of the stream ErrEOS = errors.New("EOS") // ErrSpaceNotUniform indicates mixed use of spaces and tabs for indentation ErrSpaceNotUniform = errors.New("space has both tabs and spaces") // ErrUnterminatedQuotedString is obvious. ErrUnterminatedQuotedString = errors.New("quoted string not terminated") ErrNotANumber = errors.New("not a number") ErrNotFound = errors.New("not found") ErrIncompatibleType = errors.New("incompatible type") ErrNilReceiver = errors.New("nil function receiver") ErrInvalidIndex = errors.New("invalid index") ErrFunctionNoGraph = errors.New("functions doesn't return *Graph") ErrInvalidArgs = errors.New("invalid arguments or nil receiver") )
Functions ¶
func Precedence ¶
Precedence is same as in Go, except for the missing operators (| << >> & ^ &^)
Assignment operators are given the lowest precedence.
Types ¶
type Parser ¶
Parser exposes Ix and Buf making it easier to use it outside of this package.
func New ¶
New creates a Parser. An event handler needs to be supplied if productions that emit events are used.
func (*Parser) ArgList ¶
ArgList ::= space? expression space? [, space? expression]* space?
arglist < stream > events
arglist can be empty, then returning false (this fact is not represented in the BNF definition).
func (*Parser) Byte ¶
Byte reads and returns a single byte. If no byte is available, returns 0 and an error.
func (*Parser) Emit ¶
Emit outputs a string event at the current level. This will show up in the graph
func (*Parser) Expression ¶
Expression := expr1 (op2 expr1)*
expression := expr1 (op2 expr1)* expr1 := path | constant | op1 path | op1 constant | '(' expr ')' | op1 '(' expr ')' constant ::= quoted | number
func (*Parser) Number ¶
Number returns true if it finds a number at the current parser position. It returns also the number found. TODO recognize exp notation ?
func (*Parser) Operator ¶
Operator returns the operator at the current parser position, if any; an empty string if not.
func (*Parser) Path ¶
Path parses an OGDL path, or an extended path as used in templates.
path ::= element ('.' element)* element ::= token | integer | quoted | group | index | selector (Dot optional before Group, Index, Selector) group := '(' Expression [[,] Expression]* ')' index := '[' Expression ']' selector := '{' Expression '}'
The OGDL parser doesn't need to know about Unicode. The character classification relies on values < 127, thus in the ASCII range, which is also part of Unicode.
Note: On the other hand it would be stupid not to recognize for example Unicode quotation marks if we know that we have UTF-8. But when do we know for sure?
func (*Parser) Quoted ¶
Quoted string. Can have newlines in it. It returns the string and a possible error.
func (*Parser) Rune ¶
Rune reads a single UTF-8 encoded Unicode character and returns the rune. If the encoded rune is invalid, it consumes one byte and returns unicode.ReplacementChar (U+FFFD) with a size of 1.
func (*Parser) Space ¶
Space is (0x20|0x09)+. It return the number of spaces found (whether tabs or spaces), and a byte than can have the values 0, ' ' and '\t' indicating mixed, all spaces or all tabs
func (*Parser) UnaryExpression ¶
UnaryExpression := cpath | constant | op1 cpath | op1 constant | '(' expr ')' | op1 '(' expr ')'
func (*Parser) UnreadByte ¶
UnreadByte unreads the last byte. It can unread all buffered bytes.
func (*Parser) UnreadRune ¶
UnreadRune unreads the last rune (should be supplied)
func (*Parser) WhiteSpace ¶
WhiteSpace is equivalent to Space | Break. It consumes all white space, whether spaces, tabs or newlines