Classes
The following classes are available globally.
-
Lexer
provides a concrete implementation of theLexicalAnalyzer
protocol and is used by default for the rest of the OysterKit stack (for example inGrammar.stream<N:Node,L:LexicalAnalyzer>(lexer:L)->AnySequence<N>
).In addition to the requirements of the
See moreLexicalAnalyzer
protocol, this implementation provides the ability to skip characters from aCharacterSet
when a call tomark()
is made. This can be useful when the consumer always wants, for example, to ignore white space in a file.Declaration
Swift
open class Lexer : LexicalAnalyzer, CustomStringConvertible
-
A pure Swift implementation of a
String
scanner, that can leverage some of the strengths of swift (over usingNSScanner
). In general consumers of OysterKit do not need to use this class directly as it is abstracted away by a concrete implementation ofLexical Analyzer
.At this point (Swift 4.0) the Swift
String
subsystem is still enjoying a reasonable amount of churn so details of the implementation will change to fully leverage any improved performance affordances. However at this point the implementation is based around theUnicodeScalarView
of aString
as it enables direct cosumption of other useful classes such asCharacterSet
.This may change in the future as Swift strings evolve.
See moreDeclaration
Swift
public class StringScanner : CustomStringConvertible
-
AbstractSyntaxTreeConstructor is an
See moreIntermediateRepresentation
responsible for briding between the parsing results and an AbstractSyntaxTree. It encapsulates a parsing strategy that creates it’s own lightweight homogenous representation of the parsed data. It can build into anyAbstractSyntaxTree
, utilizing theHomogenousTree
by default. In addition it can parse into a heterogenous abstract syntax tree represented by any Swift Type by utlizing the Swift Decoder framework to decode the intermediate representation into a decodable container structure.Declaration
Swift
public class AbstractSyntaxTreeConstructor
-
A
See moreNodeStack
can be used to manage AST construction state, as new rule evaluations begin new contexts can be pushed onto the node stack and then popped and discarded on failure, or popped and acted on for success.Declaration
Swift
public final class NodeStack<NodeType> : CustomStringConvertible where NodeType : Node
-
A generic cache that can be used in your own
See moreIntermediateRepresentation
Declaration
Swift
public final class StateCache<PositionType, KeyType, CachedType> : CustomStringConvertible where PositionType : Comparable, KeyType : Hashable
-
The Iterator created by token streams
See moreDeclaration
Swift
public class TokenStreamIterator : IteratorProtocol
-
When a rule definition calls itself whilst evaluating itself (left hand recursion) you cannot create the rule directly as it will become caught in an infinite look (creating instances of itself, which create instances of itself etc until the stack is empty). To avoid this a rule can use this wrapper to manage lazy initialization of itself. The recursive rule enables a reference to be added on the RHS, but the actual rule will not be initiialized until later, and this wrapper will then call that lazily initalized rule.
See moreDeclaration
Swift
public final class RecursiveRule : Rule, CustomStringConvertible