Documentation ¶
Overview ¶
Package ewwet parses Emmet-like abbreviations and expands them into XML.
Limitations ¶
- No implicit tag names (`ul>.cls` causes an error)
- Generates always empty-element tags (yes: <a />, no: <a></a>)
- (internal) each TEXT {...}, QTEXT "..." is a token, unlike attr-list [, ..., ]
Example ¶
package main import ( "fmt" "github.com/shu-go/ewwet" ) func main() { expanded, _ := ewwet.Expand("ul>li.item-${ITEM$}*3") fmt.Println(expanded) }
Output: <ul><li class="item-1">ITEM1</li><li class="item-2">ITEM2</li><li class="item-3">ITEM3</li></ul>
Index ¶
- Constants
- func Expand(s string) (string, error)
- func Parse(in io.Reader, listener Listener) (parseError error)
- type Lexer
- type LexerTx
- type Listener
- type Node
- type NodeListener
- func (nl *NodeListener) Attribute(name, value string) error
- func (nl *NodeListener) Class(name string) error
- func (nl *NodeListener) Element(name string) error
- func (nl *NodeListener) GroupBegin() error
- func (nl *NodeListener) GroupEnd() error
- func (nl *NodeListener) ID(name string) error
- func (nl *NodeListener) Mul(count int) error
- func (nl *NodeListener) OpChild() error
- func (nl *NodeListener) OpClimbup(count int) error
- func (nl *NodeListener) OpSibling() error
- func (nl *NodeListener) Text(text string) error
- type NodeType
- type Parser
- type Token
- type TokenType
Examples ¶
Constants ¶
View Source
const ( Root = NodeType("ROOT") WIP = NodeType("WIP") Element = NodeType("element") Text = NodeType("text") Group = NodeType("group") )
View Source
const ( EOF = TokenType("eof") ERR = TokenType("err") CHILD = TokenType(">") SIBLING = TokenType("+") CLIMBUP = TokenType("^") MULT = TokenType("*") GROUPBEGIN = TokenType("(") GROUPEND = TokenType(")") ID = TokenType("#") CLASS = TokenType(".") ATTRBEGIN = TokenType("[") ATTREND = TokenType("]") EQ = TokenType("=") STRING = TokenType("string") TEXT = TokenType(`{}`) QTEXT = TokenType(`""`) )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
func (*Lexer) Transaction ¶
type LexerTx ¶
type LexerTx struct {
// contains filtered or unexported fields
}
LexerTx can not be used in pallarel
func (*LexerTx) Transaction ¶
type Node ¶
type Node struct { Type NodeType Data string Attribute map[string]string Mul int Parent, FirstChild, LastChild, NextSibling, PrevSibling *Node }
func (*Node) AppendChild ¶
type NodeListener ¶
type NodeListener struct { Root *Node // contains filtered or unexported fields }
func NewNodeListener ¶
func NewNodeListener() NodeListener
func (*NodeListener) Attribute ¶
func (nl *NodeListener) Attribute(name, value string) error
func (*NodeListener) Class ¶
func (nl *NodeListener) Class(name string) error
func (*NodeListener) Element ¶
func (nl *NodeListener) Element(name string) error
func (*NodeListener) GroupBegin ¶
func (nl *NodeListener) GroupBegin() error
func (*NodeListener) GroupEnd ¶
func (nl *NodeListener) GroupEnd() error
func (*NodeListener) ID ¶
func (nl *NodeListener) ID(name string) error
func (*NodeListener) Mul ¶
func (nl *NodeListener) Mul(count int) error
func (*NodeListener) OpChild ¶
func (nl *NodeListener) OpChild() error
func (*NodeListener) OpClimbup ¶
func (nl *NodeListener) OpClimbup(count int) error
func (*NodeListener) OpSibling ¶
func (nl *NodeListener) OpSibling() error
func (*NodeListener) Text ¶
func (nl *NodeListener) Text(text string) error
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
EBNF:
attr-list = "[", attr, { attr }, "]"; attr = STRING, ["=", (QTEXT | STRING)]; id = "#", STRING; class = ".", STRING; tag-element = STRING, { id | class | attr-list }, [ TEXT ]; multiplication = "*", NUMBER; element = ( tag-element | TEXT ), [multiplication]; group = "(", abbreviation, ")", [multiplication]; operator = CHILD | SIBLING | repeatable-operator; repeatable-operator = CLIMBUP, {CLIMBUP} abbreviation = (group | element), [operator, abbreviation]
Click to show internal directories.
Click to hide internal directories.