Documentation
¶
Overview ¶
Package lex turns widget source into positioned tokens, one slice per significant line.
The dialect is line-oriented and its whole punctuation inventory is `%%`, `"`, `{` and `}`, so the scanner is a whitespace splitter that knows about quoted text. It classifies each token far enough for the parser and the validator to report a canonical-form finding rather than a shape error: a mermaid edge operator, a node shape bracket, a colour literal and a unit-suffixed time value are each their own kind, because each has a catalogued rewrite.
Comments are dropped here. A `%%` that opens a line is a comment; a `%%` after content on the same line is W508 and the rest of that line is dropped, which is what makes a `%%` inside quoted text unambiguously text.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Kind ¶
type Kind int
Kind classifies one token.
const ( // KindWord is an identifier or a keyword: the dialect reserves nothing, so // `node` is a legal role name and the parser decides by position. KindWord Kind = iota // KindInteger is a decimal integer, optionally signed. KindInteger // KindString is a double-quoted literal. Text holds its contents. KindString // KindTimeLiteral is a number carrying a unit sigil, such as `820ms`. KindTimeLiteral // KindMermaidEdge is one of mermaid's ten edge operators. KindMermaidEdge // KindShapeBracket is an identifier carrying a mermaid node shape bracket. KindShapeBracket // KindColour is a colour value: a hex literal, or an `rgb(`/`var(` form. KindColour // KindOther is a token that matches no other kind. KindOther )
type Line ¶
Line is one significant line: a statement's tokens, in order. Blank lines and whole-line comments produce no Line.
type Token ¶
type Token struct {
Kind Kind
// Text is the token's value: the run exactly as written for every kind
// except KindString, where it is the literal's contents without its
// delimiters. A span recovers what the delimiters were.
Text string
At diag.SourcePosition
// EndColumn is one past the token's last code point, so a span can be
// closed without re-measuring the text.
EndColumn int
}
Token is one lexical unit with its anchor.
func (Token) Span ¶
func (token Token) Span() diag.SourceSpan
Span is the token's extent, for an IR record that is exactly one token wide.