mirror of
https://github.com/semihalev/twig.git
synced 2026-03-14 13:55:46 +01:00
- Implement a compiled template format using gob encoding - Add methods to compile templates and load from compiled templates - Create dedicated CompiledLoader for managing compiled templates - Enable auto-reload support for compiled templates - Add comprehensive tests including benchmarks - Create example application for template compilation workflow - Update documentation with compilation features and examples 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
93 lines
1.5 KiB
Go
93 lines
1.5 KiB
Go
// Code generated by lexgen; DO NOT EDIT.
|
|
package twig
|
|
|
|
import "fmt"
|
|
|
|
// TokenType represents a token type
|
|
type TokenType int
|
|
|
|
// Token types
|
|
const (
|
|
T_EOF TokenType = iota
|
|
T_TEXT
|
|
T_VAR_START
|
|
T_VAR_END
|
|
T_BLOCK_START
|
|
T_BLOCK_END
|
|
T_IDENT
|
|
T_STRING
|
|
T_NUMBER
|
|
T_OPERATOR
|
|
T_PUNCTUATION
|
|
|
|
// Special keywords
|
|
T_MACRO
|
|
T_ENDMACRO
|
|
T_IMPORT
|
|
T_FROM
|
|
T_AS
|
|
T_WITH
|
|
T_ONLY
|
|
T_IGNORE
|
|
T_MISSING
|
|
T_IN
|
|
)
|
|
|
|
// Token represents a token in the lexer
|
|
type Token struct {
|
|
Type TokenType
|
|
Value string
|
|
Line int
|
|
Col int
|
|
}
|
|
|
|
func (t Token) String() string {
|
|
var typeName string
|
|
switch t.Type {
|
|
case T_EOF:
|
|
typeName = "EOF"
|
|
case T_TEXT:
|
|
typeName = "TEXT"
|
|
case T_VAR_START:
|
|
typeName = "VAR_START"
|
|
case T_VAR_END:
|
|
typeName = "VAR_END"
|
|
case T_BLOCK_START:
|
|
typeName = "BLOCK_START"
|
|
case T_BLOCK_END:
|
|
typeName = "BLOCK_END"
|
|
case T_IDENT:
|
|
typeName = "IDENT"
|
|
case T_STRING:
|
|
typeName = "STRING"
|
|
case T_NUMBER:
|
|
typeName = "NUMBER"
|
|
case T_OPERATOR:
|
|
typeName = "OPERATOR"
|
|
case T_PUNCTUATION:
|
|
typeName = "PUNCTUATION"
|
|
case T_MACRO:
|
|
typeName = "MACRO"
|
|
case T_ENDMACRO:
|
|
typeName = "ENDMACRO"
|
|
case T_IMPORT:
|
|
typeName = "IMPORT"
|
|
case T_FROM:
|
|
typeName = "FROM"
|
|
case T_AS:
|
|
typeName = "AS"
|
|
case T_WITH:
|
|
typeName = "WITH"
|
|
case T_ONLY:
|
|
typeName = "ONLY"
|
|
case T_IGNORE:
|
|
typeName = "IGNORE"
|
|
case T_MISSING:
|
|
typeName = "MISSING"
|
|
case T_IN:
|
|
typeName = "IN"
|
|
default:
|
|
typeName = fmt.Sprintf("UNKNOWN(%d)", t.Type)
|
|
}
|
|
return fmt.Sprintf("%s(%q)", typeName, t.Value)
|
|
}
|