I'm currently exploring Swift-Syntax by using https://swift-ast-explorer.kishikawakatsumi.com as a playground.
One thing that got me confused is that apparently there's no way to get the left and right expressions of a binary operator. For example:
if number + 1 == 2 { }
I also didn't find anything related to that in BinaryOperatorExprSyntax
.
However, the AST does group things differently, in a way which makes it possible to know the operators precedence:
(if_stmt range=[file.swift:2:1 - line:2:34]
(binary_expr type='Bool' location=file.swift:2:19 range=[file.swift:2:4 - line:2:28] nothrow
(dot_syntax_call_expr implicit type='(Float, Float) -> Bool' location=file.swift:2:19 range=[file.swift:2:19 - line:2:19] nothrow
(declref_expr implicit type='(Float.Type) -> (Float, Float) -> Bool' location=file.swift:2:19 range=[file.swift:2:19 - line:2:19] decl=Swift.(file).FloatingPoint extension.== [with (substitution_map generic_signature=<Self where Self : FloatingPoint> (substitution Self -> Float))] function_ref=double)
(type_expr implicit type='Float.Type' location=file.swift:2:19 range=[file.swift:2:19 - line:2:19] typerepr='Float'))
(tuple_expr implicit type='(Float, Float)' location=file.swift:2:4 range=[file.swift:2:4 - line:2:28]
(binary_expr type='Float' location=file.swift:2:15 range=[file.swift:2:4 - line:2:17] nothrow
(dot_syntax_call_expr implicit type='(Float, Float) -> Float' location=file.swift:2:15 range=[file.swift:2:15 - line:2:15] nothrow
(declref_expr type='(Float.Type) -> (Float, Float) -> Float' location=file.swift:2:15 range=[file.swift:2:15 - line:2:15] decl=Swift.(file).Float extension.+ function_ref=unapplied)
(type_expr implicit type='Float.Type' location=file.swift:2:15 range=[file.swift:2:15 - line:2:15] typerepr='Float'))
(tuple_expr implicit type='(Float, Float)' location=file.swift:2:4 range=[file.swift:2:4 - line:2:17]
(declref_expr type='Float' location=file.swift:2:4 range=[file.swift:2:4 - line:2:4] decl=file.(file).myFloating@file.swift:1:5 function_ref=unapplied)
(integer_literal_expr type='Float' location=file.swift:2:17 range=[file.swift:2:17 - line:2:17] value=1 builtin_initializer=Swift.(file).Float extension.init(_builtinIntegerLiteral:) initializer=**NULL**)))
(member_ref_expr type='Float' location=file.swift:2:28 range=[file.swift:2:22 - line:2:28] decl=Swift.(file).Float extension.nan
(type_expr type='Float.Type' location=file.swift:2:22 range=[file.swift:2:22 - line:2:22] typerepr='Float'))))
(brace_stmt range=[file.swift:2:32 - line:2:34])))))
How would I achieve something like this with SwiftSyntax? Thanks!