深入理解Hugo: Action Lexer

package main
import (
    "fmt"
    "github.com/sunwei/gobyexample/modules/lexer"
    "github.com/sunwei/gobyexample/modules/lexer/action"
)

Action example

func main() {
    lex, err := action.New(
        "<p><!-- HTML comment -->abc</p>\n{{.Content}}")
    if err != nil {
        fmt.Println(err)
        return
    }

lexer iterate

    var tokens []lexer.Token
    for {

reach end, analyzing done

        token := lex.Next()
        tokens = append(tokens, token)
        if token.Type() == action.TokenEOF {
            break
        }
    }

output tokens detail

    for i, t := range tokens {
        fmt.Println(i + 1)
        fmt.Println(t.Value())
    }
    return
}

5 tokens generated

EOF State
1
<p><!-- HTML comment -->abc</p>
2
{{
3
.Content
4
}}
5
Program exited.

Next example: Template Parser.