ParserState
struct ParserState : Sendable
extension ParserState: Restorable
A type representing the state of the parser.
-
A tag representing the context of the parser.
See moreDeclaration
Swift
enum Context : Sendable -
The AST being constructed by the parser.
Declaration
Swift
var ast: AST -
The node space into which new node identities must be registered.
Declaration
Swift
private let space: Int -
The lexer generating the tokens to parse.
Declaration
Swift
private(set) var lexer: Lexer { get } -
The current index of the parser in the character stream.
Declaration
Swift
private(set) var currentIndex: String.Index { get } -
The lookahead buffer.
Declaration
Swift
private var lookahead: Deque<Token> -
The diagnostics of the parse errors and warnings.
Declaration
Swift
var diagnostics: DiagnosticSet -
A stack describing the parsing context.
Declaration
Swift
var contexts: [Context] -
Creates a new context for parsing parts of
ast, registering the identities of newly formed ASTs in spacek, usinglexerto generate tokens and reporting errors tolog.Declaration
Swift
init(ast: AST, space: Int, lexer: Lexer, reportingDiagnosticsTo log: DiagnosticSet? = nil) -
Indicates whether the parser is at global scope.
Declaration
Swift
var isAtGlobalScope: Bool { get } -
Indicates whether the parser is at module scope.
Declaration
Swift
var isAtModuleScope: Bool { get } -
Indicates whether the parser is at namespace scope.
Declaration
Swift
var isAtNamespaceScope: Bool { get } -
Indicates whether the parser is expecting to parse member declarations.
Declaration
Swift
var isAtTypeScope: Bool { get } -
Indicates whether the parser is at trait scope.
Declaration
Swift
var isAtTraitScope: Bool { get } -
Indicates whether the parser is expecting to parse a capture declaration.
Declaration
Swift
var isParsingCaptureList: Bool { get } -
The current location of the parser in the character stream.
Declaration
Swift
var currentLocation: SourcePosition { get } -
The next character in the character stream, unless the parser reached its end.
Declaration
Swift
var currentCharacter: Character? { get } -
Returns whether the parser is at the end of the character stream.
Declaration
Swift
var isAtEOF: Bool { get } -
Returns whether there is a whitespace at the current index.
Declaration
Swift
var hasLeadingWhitespace: Bool { get } -
Returns whether there are whitespaces before and after
token.Declaration
Swift
mutating func hasLeadingAndTrailingWhitespaces(_ token: Token) -> Bool -
Returns whether there is a new line in the character stream before
bound.Declaration
Swift
mutating func hasNewline(before bound: Token) -> Bool -
Returns a site from
startIndextoself.currentIndex.Declaration
Swift
func range(from startIndex: String.Index) -> SourceRange -
Returns whether
tokenis a member index.Declaration
Swift
func isMemberIndex(_ token: Token) -> Bool -
Returns the next token without consuming it, if any.
Declaration
Swift
mutating func peek() -> Token? -
Returns up to the next
nnext tokens without consuming them.Declaration
Swift
mutating func peek(_ n: Int) -> Deque<Token>.SubSequence -
Returns whether a token of the given
kindis next in the input.Declaration
Swift
mutating func isNext(_ kind: Token.Kind) -> Bool -
Returns whether a token satisfying
predicateis next in the input.Declaration
Swift
mutating func isNext(satisfying predicate: (Token) -> Bool) -> Bool -
Consumes and returns the next token, if any.
Declaration
Swift
mutating func take() -> Token? -
Consumes and returns the next token if it has the specified kind.
-
Consumes and returns the first
kinds.counttokens if they have the specified kinds. -
Consumes and returns the next token, only if it has the specified kind and if it is not preceded by any whitespace.
-
Consumes and returns the next token iff it is a single question mark nor preceded by any whitespace.
Declaration
Swift
mutating func takePostfixQuestionMark() -> Token? -
Consumes and returns the next token if it satisfies
predicate. -
Consumes and returns a name token with the specified value.
Declaration
Swift
mutating func take(nameTokenWithValue value: String) -> Token? -
Consumes and returns an operator (excluding
=) from the token stream.If the next token in the stream is an angle bracket, it is interpreted as an operator and merged with any attached operator.
Declaration
Swift
mutating func takeOperator() -> SourceRepresentable<Identifier>? -
Consumes and returns the value of a member index.
Declaration
Swift
mutating func takeMemberIndex() -> SourceRepresentable<Int>? -
Consumes and returns an attribute token with the specified name.
Declaration
Swift
mutating func take(attribute name: String) -> Token? -
Applies
parse, propagating thrown errors, and returns non-nilresults or throws an error diagnosing that we expectedexpectedConstruct.Declaration
Swift
mutating func expect<T>( _ expectedConstruct: String, using parse: (inout ParserState) throws -> T? ) throws -> T -
Applies
parser.parse, propagating thrown errors, and returns non-nilresults or throws an error diagnosing that we expectedexpectedConstruct.Declaration
Swift
mutating func expect<C: Combinator>( _ expectedConstruct: String, using parser: C ) throws -> C.Element where C.Context == Self -
Consumes tokens as long as they satisfy
predicate.Declaration
Swift
mutating func skip(while predicate: (Token) -> Bool) -
Consumes tokens until the first one that may be at the start of a declaration.
Declaration
Swift
mutating func skipUntilNextDecl() -
Inserts
nintoself.ast, accumulating any diagnostics inself.diagnostics.Declaration
Swift
mutating func insert<T>(_ n: T) -> T.ID where T : Node -
Inserts
nintoself.ast.Precondition
nis well-formed.Declaration
Swift
mutating func insert<T>(synthesized n: T) -> T.ID where T : Node -
Undocumented
Declaration
Swift
fileprivate func token(_ t: Token) -> SourceRepresentable<Identifier> -
Declaration
Swift
typealias Backup = `Self`
View on GitHub