Classes

The following classes are available globally.

  • Lexer provides a concrete implementation of the LexicalAnalyzer protocol and is used by default for the rest of the OysterKit stack (for example in Grammar.stream<N:Node,L:LexicalAnalyzer>(lexer:L)->AnySequence<N>).

    In addition to the requirements of the LexicalAnalyzer protocol, this implementation provides the ability to skip characters from a CharacterSet when a call to mark() is made. This can be useful when the consumer always wants, for example, to ignore white space in a file.

    See more

    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 using NSScanner). In general consumers of OysterKit do not need to use this class directly as it is abstracted away by a concrete implementation of Lexical 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 the UnicodeScalarView of a String as it enables direct cosumption of other useful classes such as CharacterSet.

    This may change in the future as Swift strings evolve.

    See more

    Declaration

    Swift

    public class StringScanner : CustomStringConvertible
  • AbstractSyntaxTreeConstructor is an IntermediateRepresentation 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 any AbstractSyntaxTree, utilizing the HomogenousTree 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.

    See more

    Declaration

    Swift

    public class AbstractSyntaxTreeConstructor
  • NodeStackEntry‘s are used to capture parsing context (for example child-nodes and errors) ASTs are constructed.

    See more

    Declaration

    Swift

    public final class NodeStackEntry<NodeType> : CustomStringConvertible where NodeType : Node
  • A NodeStack 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.

    See more

    Declaration

    Swift

    public final class NodeStack<NodeType> : CustomStringConvertible where NodeType : Node
  • A generic cache that can be used in your own IntermediateRepresentation

    See more

    Declaration

    Swift

    public final class StateCache<PositionType, KeyType, CachedType> : CustomStringConvertible where PositionType : Comparable, KeyType : Hashable
  • A TokenStream provides lazy iterators that minimize memory consumption and overhead allowing you to iterate through the tokens created by the root rules (those at the lowest level in the language) in the supplied Grammar

    See more

    Declaration

    Swift

    public class TokenStream : Sequence
  • The Iterator created by token streams

    See more

    Declaration

    Swift

    public class TokenStreamIterator : IteratorProtocol
  • A ChoiceRule will match if one of the child rules is matched. It can be thought of as a logical OR.

    See more

    Declaration

    Swift

    public final class ChoiceRule : Rule
  • An implementation of a Rule that allows the specification of a Test closure to provide the required check.

    See more

    Declaration

    Swift

    public final class ClosureRule : Rule
  • 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 more

    Declaration

    Swift

    public final class RecursiveRule : Rule, CustomStringConvertible
  • A rule that matches the specified Terminal

    See more

    Declaration

    Swift

    public final class TerminalRule : Rule