Avatar
omochimetaru 8/23/2022 1:02 AM
@_spi(RawSyntax) public struct RawSyntax { var rawData: RawSyntaxData { unsafeAddress { pointer } }
1:02 AM
謎の文法がある
1:02 AM
/// This is an address-family accessor: a function that is called when /// a value is loaded from the storage, like a getter, but which works /// by returning a pointer to an immutable value of the storage type. /// This kind of accessor also has an addressor kind. /// /// Addressors are a way of proving more efficient access to storage /// when it is already stored in memory (but not as a stored member /// of the type). IMMUTABLE_ADDRESSOR(Address, unsafeAddress) https://github.com/apple/swift/blob/7123d2614b5f222d03b3762cb110d27a9dd98e24/include/swift/AST/AccessorKinds.def
1:03 AM
get とか _read みたいなプロパティ実装方法の一つらしい
1:08 AM
@_spi(RawSyntax) public struct RawTryExprSyntax: RawExprSyntaxNodeProtocol { public var unexpectedBeforeTryKeyword: RawUnexpectedNodesSyntax? { layoutView.children[0].map(RawUnexpectedNodesSyntax.init(raw:)) } public var tryKeyword: RawTokenSyntax { layoutView.children[1].map(RawTokenSyntax.init(raw:))! } public var unexpectedBetweenTryKeywordAndQuestionOrExclamationMark: RawUnexpectedNodesSyntax? { layoutView.children[2].map(RawUnexpectedNodesSyntax.init(raw:)) } public var questionOrExclamationMark: RawTokenSyntax? { layoutView.children[3].map(RawTokenSyntax.init(raw:)) } public var unexpectedBetweenQuestionOrExclamationMarkAndExpression: RawUnexpectedNodesSyntax? { layoutView.children[4].map(RawUnexpectedNodesSyntax.init(raw:)) } public var expression: RawExprSyntax { layoutView.children[5].map(RawExprSyntax.init(raw:))! } } unexpectedなんちゃらを含む構造で正規の文法よりゆるいソースコードをパースしたそうな雰囲気
1:11 AM
struct ParsedToken { var tokenKind: RawTokenKind /// Whole text of this token including leading/trailing trivia. var wholeText: SyntaxText /// Range of the actual token’s text. /// /// Text in `wholeText` before `textRange.lowerBound` is leading trivia and /// after `textRange.upperBound` is trailing trivia. var textRange: Range<SyntaxText.Index> } leading trivia, token, trailing triviaの持ち方も軽そうな感じになってる