-
Notifications
You must be signed in to change notification settings - Fork 1
Grammar
kareman edited this page Aug 13, 2020
·
4 revisions
Allows for recursive patterns, also indirectly.
@dynamicMemberLookup public class Grammar<Input: BidirectionalCollection>: Pattern where Input.Element: Hashable
Define subpatterns using <-
, like this arithmetic pattern:
let g = Grammar { g in
g.all <- g.expr • !any
g.expr <- g.sum
g.sum <- g.product • (("+" / "-") • g.product)*
g.product <- g.power • (("*" / "/") • g.power)*
g.power <- g.value • ("^" • g.power)¿
g.value <- digit+ / "(" • g.expr • ")"
}
This recognises e.g. "1+2-3*(4+3)"
Warning: ``` g.a <- g.a • g.b ```
will lead to infinite recursion.
@inlinable public init()
@inlinable public init() where Input == String
@inlinable public convenience init(_ closure: (Grammar<Input>) -> Void)
@inlinable public convenience init(_ closure: (Grammar<String>) -> Void) where Input == String
var description: String
All the subpatterns and their names.
var patterns: [(name: String, pattern: AnyPattern<Input>)]
The main subpattern, which will be called when this Grammar is being used.
var firstPattern: String?
@inlinable public func createInstructions(_ instructions: inout ContiguousArray<Instruction<Input>>) throws
public static func ==<Input>(lhs: Grammar<Input>, rhs: Grammar<Input>) -> Bool
Generated at 2020-08-23T12:56:49+0000 using swift-doc 1.0.0-beta.3.