43 lines
945 B
Go
43 lines
945 B
Go
package parser
|
|
|
|
// Token types for PML parsing
|
|
type TokenType int
|
|
|
|
const (
|
|
TokenError TokenType = iota
|
|
TokenOpenTag
|
|
TokenCloseTag
|
|
TokenSelfCloseTag
|
|
TokenText
|
|
TokenComment
|
|
TokenEOF
|
|
)
|
|
|
|
// Represents a parsed token with string ranges instead of copies
|
|
type Token struct {
|
|
Type TokenType
|
|
TagStart int // Start index in input for tag name
|
|
TagEnd int // End index in input for tag name
|
|
TextStart int // Start index for text content
|
|
TextEnd int // End index for text content
|
|
Attributes map[string]string
|
|
Line int
|
|
Col int
|
|
}
|
|
|
|
// Gets tag name from input (avoids allocation until needed)
|
|
func (t *Token) Tag(input string) string {
|
|
if t.TagStart >= 0 && t.TagEnd > t.TagStart {
|
|
return input[t.TagStart:t.TagEnd]
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// Gets text content from input
|
|
func (t *Token) Text(input string) string {
|
|
if t.TextStart >= 0 && t.TextEnd > t.TextStart {
|
|
return input[t.TextStart:t.TextEnd]
|
|
}
|
|
return ""
|
|
}
|