Documentation
¶
Overview ¶
Package lexer turns Ant source into tokens, applying the line-ending rule of section 2.
Index ¶
- func IsMarkupSpace(c byte) bool
- func KeepsWhiteSpace(name string) bool
- func Lex(src string) ([]token.Token, error)
- func LexLayout(src string, shebang bool) ([]token.Token, []token.Comment, error)
- func LexWith(src string, regex bool) (toks []token.Token, err error)
- func NormalizeBreaks(s string) string
- func Operand(t token.Token) bool
- type Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMarkupSpace ¶
IsMarkupSpace reports whether c is white space in markup (section 5, White space).
func KeepsWhiteSpace ¶
KeepsWhiteSpace reports whether the content of the element name, matched ignoring ASCII case, is outside the white space rule (section 5, White space): <pre> and <textarea>, and <script> and <style>, whose content is raw text.
func LexLayout ¶
LexLayout tokenizes src as Lex does, and also returns its comments in source order, for the formatter, which must print them where they were. With shebang true, src is a file, and a first line that starts with #! is skipped (section 2); it is returned as the first comment.
func LexWith ¶
LexWith tokenizes src as Lex does. With regex false, a / never begins a regular expression literal, which gives the lexer as it was before the literal existed; the fuzz test compares the two on every input in which the literal does not occur.
func NormalizeBreaks ¶
NormalizeBreaks returns s with each \r that is a line break on its own replaced by \n, so that every line break holds a \n and its lines can be found and counted by \n. The offsets do not change.
Types ¶
type Error ¶
type Error struct {
Pos token.Pos
Msg string
// AtEnd marks an error the end of the source caused, such as an element still open there,
// so that more input may complete it.
AtEnd bool
}
Error is a lexical error.
func LexRecover ¶
LexRecover tokenizes src as LexLayout does but goes on past every error, for an editor, and returns the errors found in source order. A string or raw string that no later quote or backtick closes ends at the end of its first line, and a comment left open at the end of the source; a construct that cannot be read at all becomes a Bad token; and markup that is malformed is read as far as it goes. Tokens come out as they would once the errors were fixed, as far as the lexer can tell.