var opPrecedence = OperatorPrecedence.standardOperators // Use the Swift standard library operators let parsed = try Parser.parse(source: "x + y * z") dump(parsed) // contains SequenceExprSyntax(x, +, y, *, z) let folded = try opPrecedence.foldAll(parsed) dump(folded) // contains InfixOperatorExpr(x, +, InfixOperatorExpr(y, *, z))
let parsedOperators = try Parser.parse(source: moreOperators) // Adds **, ExponentiationPrecedence to the set of known operators and precedence groups. try opPrecedence.addSourceFile(parsedOperators) let parsed2 = try Parser.parse(source: "b ** c ** d") dump(parsed2) // contains SequenceExprSyntax(b, **, c, **, d) let folded2 = try opPrecedence.foldAll(parsed2) dump(folded2) // contains InfixOperatorExpr(b, **, InfixOperatorExpr(c, **, d))