HBParser
public struct HBParser
Reader object for parsing String buffers
-
Return current character
Throws
.overflowDeclaration
Swift
mutating func character() throws -> Character
Return Value
Current character
-
Read the current character and return if it is as intended. If character test returns true then move forward 1
Throws
.overflowDeclaration
Swift
mutating func read(_ char: Character) throws -> Bool
Parameters
char
character to compare against
Return Value
If current character was the one we expected
-
Read the current character and return if it is as intended. If character test returns true then move forward 1
Throws
.overflowDeclaration
Swift
mutating func read(string: String) throws -> Bool
Parameters
char
character to compare against
Return Value
If current character was the one we expected
-
Read the current character and check if it is in a set of characters If character test returns true then move forward 1
Throws
.overflowDeclaration
Swift
mutating func read(_ characterSet: Set<Character>) throws -> Bool
Parameters
characterSet
Set of characters to compare against
Return Value
If current character is in character set
-
Read next so many characters from buffer
Throws
.overflowDeclaration
Swift
mutating func read(count: Int) throws -> Substring
Parameters
count
Number of characters to read
Return Value
The string read from the buffer
-
Read from buffer until we hit a character. Position after this is of the character we were checking for
Throws
.overflow if we hit the end of the buffer before reading characterDeclaration
Swift
@discardableResult mutating func read(until: Character, throwOnOverflow: Bool = true) throws -> Substring
Parameters
until
Character to read until
Return Value
String read from buffer
-
Read from buffer until we hit a string. By default the position after this is of the beginning of the string we were checking for
Throws
.overflow, .emptyStringDeclaration
Swift
@discardableResult mutating func read(untilString: String, throwOnOverflow: Bool = true, skipToEnd: Bool = false) throws -> Substring
Parameters
untilString
String to check for
throwOnOverflow
Throw errors if we hit the end of the buffer
skipToEnd
Should we set the position to after the found string
Return Value
String read from buffer
-
Read from buffer until we hit a character in supplied set. Position after this is of the character we were checking for
Throws
.overflowDeclaration
Swift
@discardableResult mutating func read(until characterSet: Set<Character>, throwOnOverflow: Bool = true) throws -> Substring
Parameters
characterSet
Character set to check against
Return Value
String read from buffer
-
Read from buffer until keyPath on character returns true. Position after this is of the character we were checking for
Throws
.overflowDeclaration
Swift
@discardableResult mutating func read(until keyPath: KeyPath<Character, Bool>, throwOnOverflow: Bool = true) throws -> Substring
Parameters
keyPath
keyPath to check
Return Value
String read from buffer
-
Read from buffer until keyPath on character returns true. Position after this is of the character we were checking for
Throws
.overflowDeclaration
Swift
@discardableResult mutating func read(until cb: (Character) -> Bool, throwOnOverflow: Bool = true) throws -> Substring
Parameters
keyPath
keyPath to check
Return Value
String read from buffer
-
Read from buffer from current position until the end of the buffer
Declaration
Swift
@discardableResult mutating func readUntilTheEnd() -> Substring
Return Value
String read from buffer
-
Read while character at current position is the one supplied
Declaration
Swift
@discardableResult mutating func read(while: Character) -> Int
Parameters
while
Character to check against
Return Value
String read from buffer
-
Read while keyPath on character at current position returns true is the one supplied
Declaration
Swift
@discardableResult mutating func read(while keyPath: KeyPath<Character, Bool>) -> Substring
Parameters
while
keyPath to check
Return Value
String read from buffer
-
Read while closure returns true
Declaration
Swift
@discardableResult mutating func read(while cb: (Character) -> Bool) -> Substring
Parameters
while
closure
Return Value
String read from buffer
-
Read while character at current position is in supplied set
Declaration
Swift
@discardableResult mutating func read(while characterSet: Set<Character>) -> Substring
Parameters
while
character set to check
Return Value
String read from buffer
-
Return whether we have reached the end of the buffer
Declaration
Swift
func reachedEnd() -> Bool
Return Value
Have we reached the end
-
Return whether we are at the start of the buffer
Declaration
Swift
func atStart() -> Bool
Return Value
Are we are the start
-
context used in parser error
See moreDeclaration
Swift
public struct Context
-
Return context of current position (line, lineNumber, columnNumber)
Declaration
Swift
func getContext() -> Context
-
Return the character at the current position
Throws
.overflowDeclaration
Swift
func current() -> Character
Return Value
Character
-
Move forward one character
Throws
.overflowDeclaration
Swift
mutating func advance() throws
-
Move back one character
Throws
.overflowDeclaration
Swift
mutating func retreat() throws
-
Move forward so many character
Throws
.overflowDeclaration
Swift
mutating func advance(by amount: Int) throws
Parameters
amount
number of characters to move forward
-
Move back so many characters
Throws
.overflowDeclaration
Swift
mutating func retreat(by amount: Int) throws
Parameters
amount
number of characters to move back
-
Undocumented
Declaration
Swift
mutating func setPosition(_ position: String.Index) throws
-
Undocumented
Declaration
Swift
func unsafeCurrent() -> Character
-
Undocumented
Declaration
Swift
mutating func unsafeAdvance()
-
Undocumented
Declaration
Swift
mutating func unsafeRetreat()
-
Undocumented
Declaration
Swift
mutating func unsafeAdvance(by amount: Int)
-
Undocumented
Declaration
Swift
mutating func unsafeRetreat(by amount: Int)
-
Undocumented
Declaration
Swift
mutating func unsafeSetPosition(_ position: String.Index)