# Add code strings(aka quisiquotes) to function builders

**URL:** <https://forums.swift.org/t/add-code-strings-aka-quisiquotes-to-function-builders/38713>\
**Category:** Discussion\
**Created:** [July 24, 2020, 5:07am UTC](https://forums.swift.org/t/add-code-strings-aka-quisiquotes-to-function-builders/38713 "2020-07-24T05:07:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![total\_swiftification](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/total_swiftification/32/11900_2.png) [@total\_swiftification](https://forums.swift.org/u/total_swiftification)\
**Post date:** [July 24, 2020, 5:07am UTC](https://forums.swift.org/t/add-code-strings-aka-quisiquotes-to-function-builders/38713/1 "2020-07-24T05:07:26Z")

</div>

Hi folks, I got some idea and ready for being criticized 😉  
Currently, only some swift syntax allowed in function building closures, but that limits the expressivity of DSL in that it cannot accept raw strings of text which can be some external code. For example, something like this is not possible:

```swift
Python {
	import os

	catPicture = os.open("../royal-kitten.jpg")
}
//or
EBNF {
    variable_declaration := 'var' identifier (':' type_spec)? assignment_expression;
}

```

Well it is possible to do it, but it is ugly as hell 😞 :

```swift
Python {"""
	import os
        //HOLY! 
	catPicture = os.open("../royal-kitten.jpg")
"""}

```

My point is - if the function building stuff is mostly concerned with an aesthetic vibe in every place, then accepting the code as a raw string should be possible.

In short, I suggest making an addition to function building aggregate a set of new attributes:

```swift
//must contain the function that takes a string and produces a syntax tree
@syntaxParser struct PythonParser {}
//must contain a function that for every token adds additional metadata about colouring to it
@syntaxColoring struct PythonSyntaxDyer {}
//and the cherry in this mix
//attribute for marking closures inside a fb declaration
@quasiString(syntaxParser:syntaxDyer:)

@functionBuilder struct HLSL {
    static func buildBlock(_ partialResults: @quasiString(...) String) -> HLSL.Shader {
         ...
    }
}

```

Capturing values from swift should be done with unquoting:

```swift
let a = 3
Python { someValue = #{ a } } 
//syntax of the representative language must not collide with unquoting
//probably should be possible to change quotation starting symbol

```

What ya all thinking bout that?

_Poll ([view on site](https://forums.swift.org/t/add-code-strings-aka-quisiquotes-to-function-builders/38713/1))_

---

<div class="post-metadata">

**Author:** ![Lantua](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lantua/32/8868_2.png) [@Lantua](https://forums.swift.org/u/Lantua)\
**Post date:** [July 24, 2020, 1:27pm UTC](https://forums.swift.org/t/add-code-strings-aka-quisiquotes-to-function-builders/38713/2 "2020-07-24T13:27:30Z")

</div>

I think the function builder is more about _embedding_ DSL logic into Swift code than a pure arbitrary text. You still use Swift syntax for `if-else`, `let/var` on assignment, etc.
