Documentation
¶
Overview ¶
Package parser builds the syntax tree of an Ant module. It implements sections 2, 5, 6, and 10 of the specification with one token of lookahead and no feedback from the checker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTestFile ¶
IsTestFile reports whether path names a test file, whose name ends in _test.ant (section 10, Tests).
func ParseRecover ¶
ParseRecover parses one module in the mode of its path (ModeOf) as ParseLayout does, but goes on past its syntax errors, for an editor. It returns the tree of what parsed, with a BadStmt, BadExpr, or BadType standing where a statement, an expression, or a type could not be read, the layout, and every error in source order: the lexer's, then the parser's as it met them. The error Parse reports is among them, and the rest are those Parse would report once the earlier ones were fixed, as far as the parser can tell. A Bad token, which the lexer has reported, ends a statement for the parser, as a line break would, so that it is reported once. The tree is for analysis only and must not be run.
Types ¶
type Error ¶
type Error struct {
Pos ast.Pos
Msg string
Incomplete bool
// Help says how to fix the error, when the message does not.
Help string
}
Error is a syntax error. Incomplete is set when the input ended too early, which a REPL uses to keep reading.
type Layout ¶
type Layout struct {
Tokens []token.Token
Comments []token.Comment
Roles map[int]Role
// Prefix holds the offsets of the - and ! tokens the parser read as prefix operators.
Prefix map[int]bool
}
Layout is what the formatter needs beyond the tree: the tokens with their spans, the comments, and the role of every opening bracket, keyed by its byte offset.
type Mode ¶
type Mode int
Mode selects what a source may contain at the top level.
const ( // Program is a module: imports followed by declarations and statements (section 10). Program Mode = iota // Spec also allows top-level statements and "..." placeholders, for the specification's // own examples. Spec // Session also allows top-level statements, for a REPL. Session // Declarations is a declaration file (section 10, Declaration files): declarations only, // each qualified by its owner, a func without a body, a type without one, and a var as a // typed constant; the prelude and a host namespace's signatures. Declarations )
type Role ¶
type Role struct {
Block bool // a block or a lambda body, in which newlines separate statements
Typed bool // the { of a record or map literal, directly after its type
Comma bool // a list that allows a comma after its last item
}
Role is what an opening bracket is, as the parser decided while parsing it.