Created
          June 17, 2019 14:27 
        
      - 
      
 - 
        
Save iby/913fce8729d4f792158de016b66e02f9 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
ianbytchek created this gist
Jun 17, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import Slang let source: String = "import Foundation; class Foo { let bar = 1 }" let file: File = File(source) let disassembly: Disassembly = try! Disassembly(file) var edits: [Edit] = [] // Change "Foundation" identifier to "AppKit". edits.append(Edit(disassembly.query.syntax.first(of: .identifier).select(where: { $0.contents == "Foundation" }).one!, "AppKit")) // Change "class" keyword to "struct". edits.append(Edit(disassembly.query.structure.children(of: .decl(.class)).syntax.first(of: .keyword).one!, "struct")) // Change "bar" property value from "1" to "BAR". edits.append(Edit(disassembly.query.structure.children(of: .decl(.class)).syntax.last(of: .number).one!, "\"BAR\"")) print(file.contents.applying(edits)) // import AppKit; struct Foo { let bar = "BAR" }