Lexer
public struct Lexer : IteratorProtocol, Sequence, Sendable
A type that tokenize a source file.
-
The Hylo source being tokenized.
Declaration
Swift
public let sourceCode: SourceFile -
The current position in the source file.
Declaration
Swift
private(set) var index: String.Index { get } -
Creates a lexer generating tokens from the contents of
source.Declaration
Swift
public init(tokenizing source: SourceFile) -
The current location of the lexer in
sourceCode.Declaration
Swift
public var location: SourcePosition { get } -
trueiff the last scanned token was.int.Declaration
Swift
private var previousTokenWasInt: Bool -
Advances to the next token and returns it, or returns
nilif no next token exists.Declaration
Swift
public mutating func next() -> Token? -
Discards
countcharacters from the stream.Declaration
Swift
private mutating func discard(_ count: Int = 1) -
Returns the next character in the stream without consuming it, if any.
Declaration
Swift
private func peek() -> Character? -
Returns the current index and consumes
characterfrom the stream, or returnsnilif the stream starts with a different character.Declaration
Swift
public mutating func take(_ character: Character) -> String.Index? -
Returns the current index and consumes
prefixfrom the stream, or returnsnilif the stream starts with a different prefix.Declaration
Swift
private mutating func take<T: Sequence>(prefix: T) -> String.Index? where T.Element == Character -
Consumes the longest substring that satisfies the given predicate.
Declaration
Swift
private mutating func take(while predicate: (Character) -> Bool) -> Substring -
Consumes an integral literal and returns its kind, or returns
nilif it fails to scan a valid integer.Declaration
Swift
private mutating func scanIntegralLiteral(allowingPlus allowPlus: Bool = false) -> Token.Kind?Parameters
allowingPlusIf set to
true, allows the integral literal to begin with a “+” sign. If set tofalse(the default), only allows “-” or no sign at the beginning.
View on GitHub